SOAP WS-Addressing property with Wss4jSecurityInterceptor with Java
Asked Answered
K

2

11

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?

Kosciusko answered 22/3, 2017 at 6:12 Comment(1)
I got the solution of above issue here... #43975284Kosciusko
A
6

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)
Aid answered 28/3, 2017 at 11:45 Comment(4)
My SOAP Header already contain this Action info. Also addressing property also there, then also I am getting addressing issueMagnum
So could you post the whole code dealing with request construction andsending?Aid
The issue is weird that its depend upon Sequence of Action define.If I define Action before Security element it shows error. If I define Action after Security Its works.Kosciusko
I don't find a way to set the "wsa:To" header on the client, when this URL is different to the endpoint.Mairemaise
S
0

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.

Stillness answered 29/3, 2017 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.