5

I am having difficulty in calling a SOAP 1.2 WebService via Spring-ws WebServiceTemplate. The request being made is missing SOAPAction in Http Header and the server throws an error with "Unable to handle request without a valid action parameter. Please supply a valid soap action." I was able to figure out SOAP Action was missing by monitoring through wireshark. I am also not behind any proxy.

I have made sure that the SOAP XML I am trying to send is valid by running the request through TCP Mon ( tool like SOAP UI) and was able to get response.

Here is my spring config:

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans  
                        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                        http://www.springframework.org/schema/util
                        http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
    <property name="soapVersion">
    <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
    </property>
</bean>

<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
 <constructor-arg ref="messageFactory" />
<property name="defaultUri" value="https://ecomapi.networksolutions.com/soapservice.asmx" />
<property name="messageSender">
    <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender" />     </property>
</bean>

And this is my java code:

            public void simpleSendAndReceive() {
            try{
            StreamSource source = new StreamSource(new StringReader(MESSAGE));
            StreamResult result = new StreamResult(System.out);
            SoapActionCallback actionCallBack = new SoapActionCallback("https://ecomapi.networksolutions.com/soapservice.asmx") {
                public void doWithMessage(WebServiceMessage msg) {
                    SoapMessage smsg = (SoapMessage)msg;
                    smsg.setSoapAction("http://networksolutions.com/ReadOrder");
                }
            };
            webServiceTemplate.sendSourceAndReceiveToResult(
                    "https://ecomapi.networksolutions.com/soapservice.asmx",
                     source,
                     new SoapActionCallback("http://networksolutions.com/ReadOrder"),
     //                      actionCallBack,
                     result);


            System.out.println(source.getInputStream().toString());
            System.out.println(result.getWriter().toString());

            }catch (SoapFaultClientException e) {
                System.out.println(e.getFaultCode());
                System.out.println(e.getFaultStringOrReason());
                System.out.println(e.fillInStackTrace().getLocalizedMessage());
            } catch (WebServiceIOException we) {
                System.out.println(we.getRootCause());
            }
        }
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
user1546703
  • 51
  • 1
  • 1
  • 2
  • You seem to be setting SOAP Action headers multiple ways here right - using `actionCallBack`, explicitly using `new SoapActionCallback..`, are both approaches not working? – Biju Kunjummen Jul 24 '12 at 13:52
  • Thats correct. Both the approaches give the same error back. – user1546703 Jul 24 '12 at 14:01
  • You require a `http://networksolutions.com/ReadOrder` header right - what header do you see over the wire using wireshark. Just want to ensure that you are not sending `https://ecomapi.networksolutions.com/soapservice.asmx`. This is a simple tool to capture what is going back and forth - http://sourceforge.net/projects/nettool/ – Biju Kunjummen Jul 24 '12 at 14:04
  • I have attached two screen shots that show the differences in the HTTP headers. First is the screenshot for the request I am sending from TCP Mon ![TCPMon Request Header](http://tinypic.com/r/2e4w0hl/6) and the second is the request made from java.![Java Request Header](http://tinypic.com/r/5wyog2/6) If you notice, SOAPAction is missing in the header for the java request. – user1546703 Jul 24 '12 at 14:38
  • I am not able to replicate your behavior, sorry. I tried the same webserviceTemplate API that you have used - with explicit SOAPActionCallback the way you have provided and it works cleanly for me, the SOAPAction header appears in the header. Can you confirm the version of Spring-WS - I am using 2.1.0 – Biju Kunjummen Jul 24 '12 at 14:53
  • I am using spring-ws 2.0.0. Here is the relevant entry in pom.xml: org.springframework.ws spring-ws-core 2.0.0-M1 – user1546703 Jul 24 '12 at 15:13
  • Okay, may not harm upgrading to Spring-WS 2.1.0 and trying once more – Biju Kunjummen Jul 25 '12 at 19:04

3 Answers3

1

I faced the same problem and I traced it back to a bug in the 1.3.2 version of the com.sun.xml.messaging.saaj.soap.MessageImpl implementation (http://java.net/jira/browse/SAAJ-37). I upgraded to the 1.3.19 version and all was fine.

The Issue:-

Before writing the request to the output stream, the saveChanges() method is called. The 1.3.2 version of this class was overwriting the 'Content-Type' request header in it's implementation of the 'saveChanges' method.

Nikhil
  • 16,194
  • 20
  • 64
  • 81
John Shepherd
  • 211
  • 2
  • 3
0

I had a similar issue which was due to the namespace of the XmlSchema annotation in the package-info.java file being different from what the soap service I was trying to call expected. This resulted from me using xjc to generate the jaxb request and response objects from a xsd that I had sewn together from the wsdl parts plus the xsd header from a previous service I was interfacing so it was a pure cut and paste error on my part but the previous answer on here about the namespace was what clued me in to my error quickly.

Frequentcrasher
  • 271
  • 1
  • 4
  • 8
0

SOAPAction is mandatory only in SOAP 1.1, see section Content Type.

The SOAP 1.1 mandatory SOAPAction HTTP header has been removed in SOAP 1.2. In its place is an optional action parameter on the application/soap+xml media type.

Amio.io
  • 20,677
  • 15
  • 82
  • 117