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
。