Question

I am trying to code my first SOAP web service.

I am getting the SOAP response Unmarshall failure which is the response i mapped to org.springframework.oxm.UnmarshallingFailureException. I have configured Spring to use Castor (un)marshaller. Problem is i don't know how to find a more specific cause.

public class SentenceRequest {

public SentenceRequest() {}

private List<String> words = new ArrayList<String>();

public List<String> getWords() {
    return words;
}

public void setWords(List<String> words) {
    this.words = words;
}


public class SentenceResponse {

private String sentence;

public SentenceResponse() {}

public SentenceResponse(String sen) {
    sentence = sen;
}

public String getSentence() {
    return sentence;
}

public void setSentence(String sentence) {
    this.sentence = sentence;
}

the castor mapping:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapping PUBLIC
    "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN"
    "http://castor.exolab.org/mapping.dtd">
<mapping xmlns="http://castor.exolab.org/">
    <class name="ro.soapservice2.SentenceRequest">
        <map-to xml="SentenceRequest" ns-uri="sentence" ns-prefix="s" />
        <field name="words" collection="arraylist" type="java.util.List" required="true">
            <bind-xml name="word" node="element"></bind-xml>
        </field>
    </class>

    <class name="ro.soapservice2.SentenceResponse">
        <map-to xml="SentenceResponse" ns-uri="sentence" ns-prefix="s" />
        <field name="sentence" type="java.lang.String" required="true">
            <bind-xml name="sentence" node="element" />
        </field>
    </class>
</mapping>

the schema (generated with Trang.jar based on two input XML files):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"      targetNamespace="sentence" xmlns:s="sentence">
  <xs:element name="SentenceRequest">
    <xs:complexType>
          <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="s:word"/>
  </xs:sequence>
</xs:complexType>
</xs:element>
  <xs:element name="word" type="xs:string"/>
    <xs:element name="SentenceResponse">
      <xs:complexType>
        <xs:sequence>
          <xs:element ref="s:sentence"/>
        </xs:sequence>
      </xs:complexType>
     </xs:element>
   <xs:element name="sentence" type="xs:string"/>
</xs:schema>

and the WSDL Spring generates:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="sentence" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="sentence" targetNamespace="sentence">
  <wsdl:types>
    <xs:schema xmlns:s="sentence" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="sentence">

  <xs:element name="SentenceRequest">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="s:word"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="word" type="xs:string"/>

  <xs:element name="SentenceResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="s:sentence"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="sentence" type="xs:string"/>

 </xs:schema>
</wsdl:types>

  <wsdl:message name="SentenceResponse">
    <wsdl:part element="tns:SentenceResponse" name="SentenceResponse">
    </wsdl:part>
  </wsdl:message>

  <wsdl:message name="SentenceRequest">
    <wsdl:part element="tns:SentenceRequest" name="SentenceRequest">
    </wsdl:part>
  </wsdl:message>

  <wsdl:portType name="Sentence">
    <wsdl:operation name="Sentence">
      <wsdl:input message="tns:SentenceRequest" name="SentenceRequest">
      </wsdl:input>
      <wsdl:output message="tns:SentenceResponse" name="SentenceResponse">
      </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="SentenceSoap11" type="tns:Sentence">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="Sentence">
      <soap:operation soapAction=""/>
      <wsdl:input name="SentenceRequest">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="SentenceResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

  <wsdl:service name="SentenceService">
    <wsdl:port binding="tns:SentenceSoap11" name="SentenceSoap11">
      <soap:address location="http://localhost:8080/soapservice2/services"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

the SOAP request i make:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sen="sentence">
<soapenv:Header/>
 <soapenv:Body>
    <sen:SentenceRequest>
       <!--1 or more repetitions:-->
       <sen:word>asd</sen:word>
    </sen:SentenceRequest>
 </soapenv:Body>
</soapenv:Envelope>
Was it helpful?

Solution

Solved! First i replaced my exception resolver from

org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver

to

org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver

which puts back in the SOAP response the real exception that was thrown. Then i saw the problem was at the Castor xml mapping file:

changed from

<field name="words" collection="arraylist" type="java.util.List" required="true">
                <bind-xml name="word" node="element"></bind-xml>
        </field>

to

<field name="words" collection="arraylist" type="java.lang.String" required="true">
                <bind-xml name="word" node="element"></bind-xml>
        </field>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top