简体   繁体   中英

Spring-WS set SOAPAction header for SOAP version 1.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.

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 !

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM