SOAP WS-Addressing property with Wss4jSecurityInterceptor with Java

2.2k Views Asked by At

Hi I create code for consume SOAP service,

For Authentication Header I used Wss4jSecurityInterceptor for set Header information.

I am getting fail response like below

 Exception in thread "main" org.springframework.ws.soap.client.SoapFaultClientException: Required element {http://www.w3.org/2005/08/addressing}Action is missing

My Configuration code as below

@Configuration
public class SoapClientConfig {

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("com.xyz.client");
        marshaller.setCheckForXmlRootElement(false);
        return marshaller;
    }

    @Bean
    public MyClient myClient(Jaxb2Marshaller marshaller) throws Exception {
        MyClient client = new MyClient();
        client.setDefaultUri("https://localhost:8080/ws/service");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);

        ClientInterceptor[] interceptors = new ClientInterceptor[] {securityInterceptor()};

        client.setInterceptors(interceptors);
        return client;
    }

    @Bean
    public Wss4jSecurityInterceptor securityInterceptor() {
        Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
        wss4jSecurityInterceptor.setSecurementActions("UsernameToken");
        wss4jSecurityInterceptor.setSecurementMustUnderstand(true);
        wss4jSecurityInterceptor.setSecurementPasswordType("PasswordText");
        wss4jSecurityInterceptor.setSecurementUsername("XXXXXXXXXXX");
        wss4jSecurityInterceptor.setSecurementPassword("XXXXXXXX");
        return wss4jSecurityInterceptor;
    }
}

Can anyone suggest me what I am missing?

If I try from SOAPUI its working fine. If I set WS-Addressing=false from SOAPUI also giving me same error, So Issue with set WS-Addressing property with above code. How can I?

2

There are 2 best solutions below

4
S. Stas On

Do you use WebServiceTemplate to send the request? If yes, you can do something like :

ActionCallback callback = new ActionCallback(
                    new URI("action uri"));

Here you should provide actual uri location of action instead "action uri". Then, do

getWebServiceTemplate().marshalSendAndReceive(request, callback)
0
Ramasamy Kasiviswanathan On

Long time before worked on populating SOAP Header with dynamic value, for that you need to work on constructing the xml nodes using callback object...WebServiceMessageCallback

http://docs.spring.io/spring-ws/site/reference/html/client.html#d5e1848

In my scenario I need to construct the node using QName (Java) Node by Node.