Spring WS: How to configure HTTP Basic auth for a SOAP client
Here is a way to enable HTTP Basic auth for a SOAP client developed using Spring-WS.
In every request sent by our SOAP client, the HTTP header Authorization
has to be set.
Dependencies
POM Parent : org.springframework.boot:spring-boot-starter-parent:1.3.8.RELEASE
org.springframework.boot:spring-boot-starter-ws
(implied version 2.2.3.RELEASE)
org.apache.httpcomponents:httpcore
(implied version 4.4.5)
org.apache.httpcomponents:httpclient
(implied version 4.5.2)
Java client
Spring WS uses Apache HttpComponents, you just have to configure it in the right way when creating the WebServiceTemplate instance.
You have to create a custom WebServiceMessageSender instance:
(the code in the method createContext comes from Apache HttpComponents samples)
Then you have to set this factory to your webservice template configuration:
Let me know if it does not work for you.