Программисты JAVA общаются здесь
Anonymous
Spring Boot Callable — 401 Несанкционированный: [нет тела]
Сообщение
Anonymous » 22 фев 2026, 12:03
Я использую интерфейс Callable внутри приложения Spring Boot, которое отправляет запрос аутентификации:
Код: Выделить всё
public class TestCallable implements Callable {
TestEntity testEntity;
public TestCallable(TestEntity testEntity) {
this.testEntity = testEntity;
}
@Override
public TestDto call() throws Exception {
String authRequestBody = "{" +
"\"username\": \"" + testEntity.getLogin() + "\"," +
"\"password\": \"" + testEntity.getPassword() + "\"," +
"\"client_id\": \"" + testEntity.getClientId() + "\"," +
"\"client_secret\": \"" + testEntity.getClientSecret() + "\"" +
"}";
HttpHeaders authHeaders = new HttpHeaders();
authHeaders.setContentType(MediaType.APPLICATION_JSON);
authHeaders.set("Accept", "application/json");
authHeaders.set("Grant_type", "password");
HttpEntity authEntity = new HttpEntity(authRequestBody, authHeaders);
RestTemplate restTemplate = new RestTemplate();
TestDto testDto = testDto = restTemplate.postForObject(testEntity.getEndpoint(), authEntity, TestDto.class);
return testDto;
}
}
И эти запросы я отправляю в 4 потока:
Код: Выделить всё
List futuresList = new ArrayList();
ExecutorService pool = Executors.newFixedThreadPool(4);
for (Integer i=0; i
Подробнее здесь: [url]https://stackoverflow.com/questions/66224688/spring-boot-callable-401-unauthorized-no-body[/url]
1771750980
Anonymous
Я использую интерфейс Callable внутри приложения Spring Boot, которое отправляет запрос аутентификации: [code]public class TestCallable implements Callable { TestEntity testEntity; public TestCallable(TestEntity testEntity) { this.testEntity = testEntity; } @Override public TestDto call() throws Exception { String authRequestBody = "{" + "\"username\": \"" + testEntity.getLogin() + "\"," + "\"password\": \"" + testEntity.getPassword() + "\"," + "\"client_id\": \"" + testEntity.getClientId() + "\"," + "\"client_secret\": \"" + testEntity.getClientSecret() + "\"" + "}"; HttpHeaders authHeaders = new HttpHeaders(); authHeaders.setContentType(MediaType.APPLICATION_JSON); authHeaders.set("Accept", "application/json"); authHeaders.set("Grant_type", "password"); HttpEntity authEntity = new HttpEntity(authRequestBody, authHeaders); RestTemplate restTemplate = new RestTemplate(); TestDto testDto = testDto = restTemplate.postForObject(testEntity.getEndpoint(), authEntity, TestDto.class); return testDto; } } [/code] И эти запросы я отправляю в 4 потока: [code]List futuresList = new ArrayList(); ExecutorService pool = Executors.newFixedThreadPool(4); for (Integer i=0; i Подробнее здесь: [url]https://stackoverflow.com/questions/66224688/spring-boot-callable-401-unauthorized-no-body[/url]