2

I have to connect to a SOAP 1.2 Web Service with Spring-WS, but I'm having difficulties in setting SOAPAction header that is required by the service. I've already looked here and there, but none seems to give solution that would apply in my case.

I receive an error message basically stating that SOAPAction cannot be empty. (I'll post the actual error message if required)

The default behaviour with WebServiceTemplate seems to be that it'll sent the header as empty String.

I've used two approaches with WebServiceTemplate in order to set the action

  1. Using SoapActionCallback with webServiceTemplate#sendAndReceive()
  2. Manually setting the header in callback with setSoapAction( String s )

Option 1 doesn't do anything. Option 2 sets the header, but only temporarily. I can see it set if I log getSoapAction() call in the callback, but it's not sent anywhere. At least not as a separate header as I suspect is required by the service.

I digged a bit the sources of SaajSoapMessage implementation and it is in fact setting the action as part of the Content-Type header, which is, according to some references I read, correct behaviour. The problem is that I don't see the action in Content-Type header either.

The other SO questions had an answer stating that there's a bug in Saaj implementation, which causes the change of action header to be ignored. Based on the issue timestamp, I'd expect it to be fixed for the version in use.

For the debugging purposes I'm using SoapUI mock I have created. I don't have access to the source or logs of the actual WS implementation. I believe it uses .NET / WCF if that makes any difference.

So, it all boils down to simple question: How do I set the SOAPAction header for SOAP 1.2 with Spring-WS

I'm using version 2.1.4-RELEASE of Spring-WS, but instead of the default dependencies to Spring-core version 3.2.4 etc., I've manually set dependencies for the same libs, but for version 3.2.7. The reason for this is that I wish to have exactly same version of Spring that comes with Grails 2.3.6 where this component will be integrated.

Community
  • 1
  • 1
kaskelotti
  • 4,709
  • 9
  • 45
  • 72

2 Answers2

4

I got this trouble too,and found the solution: you can click this url: https://spring.io/guides/gs/consuming-web-service/ you will see

public GetQuoteResponse getQuote(String ticker) {

    GetQuote request = new GetQuote();
    request.setSymbol(ticker);

    log.info("Requesting quote for " + ticker);

    GetQuoteResponse response = (GetQuoteResponse) getWebServiceTemplate()
            .marshalSendAndReceive("http://www.webservicex.com/stockquote.asmx",
                    request,
                    new SoapActionCallback("http://www.webserviceX.NET/GetQuote"));

    return response;
}

from this demo enter image description here

so this is answer !

1

A separate SOAPAction header is used only in SOAP 1.1. In SOAP 1.2, the action is expected to be set as a parameter in the Content-Type header, and as you have seen, Spring-WS contains the necessary code to set that parameter.

If that parameter is lost, then it is most likely an issue with SAAJ. I've seen that issue with the SAAJ implementation in Java 1.6. A workaround is to package a more recent SAAJ version with your application.

If that still doesn't help, then your only option is to do some debugging to figure out where the Content-Type header is reset.

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
  • Using the latest version of SAAJ fixes this problem. Getting the latest version to be used in a web container is another thing... – kaskelotti Jan 17 '15 at 14:15
  • Out of curiosity, what is the servlet container you are using and what issue did you encounter? – Andreas Veithen Jan 17 '15 at 18:27
  • I'll have to deploy the app on Websphere 7.X. Bundling the latest SAAJ with my application had no effect. Based on investigations so far, it seems that SAAJ is loaded by Websphere at a very early stage. Changing the class-loading settings(parent-last) for the app didn't help. I also believe that in Websphere SAAJ is included within some other jar. – kaskelotti Jan 18 '15 at 00:40
  • In fact, WAS 7.X has a version SAAJ where this issue is not present. So, anyone reading this: Even that your unit/integration tests fail, test it on the actual server as well :) – kaskelotti Jan 22 '15 at 13:29