I try to add HTTP Basic Auth credentials to my SOAP-Request using Spring(-WS). The Request itself works, but no credentials are submitted. The HTTP header should look like:
[...]
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic mybase64encodedtopsecretcredentials=
But the last row is not missing. In MyConfig.java, I configure the Bean (no 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;
}
If you know the reason why the Authorization line is missing, please let me know. :) Thank you a lot in advance
I had similar problem and this article helped me: https://looksok.wordpress.com/2014/09/06/spring-4-soap-request-with-http-basic-authentication/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With