Я не знаю, почему я не могу получить список продуктов. Помогите мне, пожалуйста
@ RestController
@RequestMapping ( "/ плоский")
открытый класс AttrController {
ResponseEntity responseEntity;
String client_id="web-app-agent";
String
client_secret = "Z | AOSFVM5oIa3354645f ~ Нет ~ Aq0xgmV6 @ L # y6z {";
@RequestMapping (значение = "/ att", метод = RequestMethod.GET, производит = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity >> getAllByApi () выбрасывает IOException {
RestTemplate restTemplate = new RestTemplate ();
HttpHeaders headers = new HttpHeaders ();
String auth = client_id + ":" + client_secret;
headers.set("Accept", "application/json");
headers.set("grant_type", "password");
headers.set("username", "test@test");
headers.set("password", "1234");
headers.set("Authorization", "Basic " + Base64.encodeBase64String(auth.getBytes(Charset.forName("UTF-8"))));
HttpEntity< String> request = new HttpEntity<>(headers);
ResponseEntity<String> res = restTemplate.exchange("http://agent/oauth/token",HttpMethod.POST,request,String.class);
System.out.println("#### get response = " + res.getBody());
String responseText = res.getBody();
HashMap tokenMap = new ObjectMapper().readValue(responseText, HashMap.class);
String tokenN = (String) tokenMap.get("access_token");
System.out.println("Tokennn"+tokenN);
HttpHeaders headers1 = new HttpHeaders();
headers1.set("Authorization", "Bearer " + tokenN);
headers1.set("Accept", "application/json");
headers1.set("grant_type", "password");
headers1.set("username", "test@test");
headers1.set("password", "1234");
HttpEntity<String> request1 = new HttpEntity<>(headers1);
ResponseEntity<Attribute> attributes = restTemplate.exchange("http://agent:8082/flat/attributes",HttpMethod.GET,request1,Attribute.class);
return new ResponseEntity(attributes, HttpStatus.OK);
}
}