我尝试使用Spring(-WS)将HTTP基本身份验证凭据添加到我的SOAP请求中.该请求本身有效,但是没有凭据提交. HTTP标头应如下所示:
[...]
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic mybase64encodedtopsecretcredentials=
但是最后一行没有丢失.在MyConfig.java中,我配置Bean(无XML):
@Bean
public WebServiceTemplate webServiceTemplate() {
WebServiceTemplate template = new WebServiceTemplate();
try {
template.setMarshaller(marshaller()); //Jaxb2Marshaller
template.setUnmarshaller(marshaller());
// proxy for tcpmon inspection
template.setDefaultUri("http://127.0.0.1:29080/target/webservice.php");
String username = environment.getProperty("config.username");
String password = environment.getProperty("config.password");
Credentials credentials = new UsernamePasswordCredentials(username, password);
HttpComponentsMessageSender sender = new HttpComponentsMessageSender();
sender.setCredentials(credentials);
sender.afterPropertiesSet();
template.setMessageSender(sender);
} catch (Exception e) {
// @todo: handle me
}
return template;
}
如果您知道缺少授权行的原因,请告诉我. :)提前非常感谢