使用契约优先的Spring-WS完成的SOAP的非编组异常



我正在尝试编写我的第一个SOAP web服务。

我收到SOAP响应解组失败这是我映射到org.springframework.oxm.UnmarshallingFailureException的响应。我已经将Spring配置为使用Castor (un)编组器。问题是我不知道如何找到一个更具体的原因。

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;
}

映射:

<?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>

模式(使用基于两个输入XML文件的ang.jar生成):

<?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>

和WSDL Spring生成:

<?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>

我发出的SOAP请求:

<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>

解决!首先,我从

中替换了异常解析器
org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver

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

将抛出的实际异常放回SOAP响应中。然后我看到问题是在Castor xml映射文件:

改变

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

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

相关内容

  • 没有找到相关文章