1
我想使用Spring Boot和Integration DSL將消息作爲HTTP Post發送到休息服務。有沒有人有一個如何使用(基本)身份驗證做到這一點的例子?具有基本身份驗證的Http出站通道適配器
其他一切似乎都工作正常。該日誌顯示「org.springframework.web.client.HttpClientErrorException:401 Unauthorized」。
我想使用Spring Boot和Integration DSL將消息作爲HTTP Post發送到休息服務。有沒有人有一個如何使用(基本)身份驗證做到這一點的例子?具有基本身份驗證的Http出站通道適配器
其他一切似乎都工作正常。該日誌顯示「org.springframework.web.client.HttpClientErrorException:401 Unauthorized」。
實際上與Spring Integration方面的Basic Auth
無關。
這是ClientHttpRequestFactory
的責任。
比如我以前做這樣的事情:
@Bean
public ClientHttpRequestFactory clientHttpRequestFactory(@Value("username") String username,
@Value("password") String password) {
HttpClient httpClient = HttpClientBuilder.create().
setDefaultCredentialsProvider(getCredentialsProvider(username, password))
.build();
HttpComponentsClientHttpRequestFactory clientHttpRequestFactory =
new HttpComponentsClientHttpRequestFactory(httpClient);
return clientHttpRequestFactory;
}
private CredentialsProvider getCredentialsProvider(final String username, final String password) {
CredentialsProvider cp = new BasicCredentialsProvider();
cp.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, password));
return cp;
}
,並注入該clientHttpRequestFactory
到Http.outboundGateway().requestFactory()
。
所有其他ClientHttpRequestFactory
可能有其他方法來爲其請求對象配置Basic Auth
。