【问题标题】:Fail when delete optional tag from soap request从肥皂请求中删除可选标签时失败
【发布时间】:2015-09-15 13:51:19
【问题描述】:

正如标题中所建议的,当我从请求中删除可选参数时出现错误

完整请求:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v001="http://xmlns.tel.be/nin/v001">
   <soapenv:Header/>
   <soapenv:Body>
      <v001:Request>
         <v001:locationId>lyuda_0309001_loc</v001:locationId>
         <v001:workOrderId>88155530</v001:workOrderId>
         <v001:systemName>NINAS</v001:systemName>
         <v001:scenarioId>2</v001:scenarioId>
         <!--Optional:-->
         <v001:scenarioData>
            <v001:scenarioData></v001:scenarioData>
         </v001:scenarioData>
      </v001:Request>
   </soapenv:Body>
</soapenv:Envelope>

当我用

调用它时
             <v001:scenarioData>
                <v001:scenarioData></v001:scenarioData>
             </v001:scenarioData>

一切正常 但是当我尝试删除可选标签时

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v001="http://xmlns.tel.be/nin/v001">
   <soapenv:Header/>
   <soapenv:Body>
      <v001:NinasNCOssRequest>
         <v001:locationId>lyuda_0309001_loc</v001:locationId>
         <v001:workOrderId>88155531</v001:workOrderId>
         <v001:systemName>NINAS</v001:systemName>
         <v001:scenarioId>2</v001:scenarioId>
      </v001:NinasNCOssRequest>
   </soapenv:Body>
</soapenv:Envelope>

打个电话我有问题:

<Error> <org.springframework.ws.soap.server.SoapMessageDispatcher> <devapp104.netcracker.com> <clust1> <[ACTIVE] ExecuteThread: '14' for queue: 'weblogic.kernel.Default (self-tuning)'> <guest> <> <> <1442316335622> <BEA-000000> <ERROR org.springframework.ws.soap.server.SoapMessageDispatcher - EndpointInterceptor.afterCompletion threw exception
org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are <{http://xmlns.tel.be/nin/v001}Request>,<{http://xmlns.tel.be/nin/v001}Response>,<{http://xmlns.tel.be/nin/v001}ScenarioEnum>,<{http://xmlns.tel.be/nin/v001}ValidationException>
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:863)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:742)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:720)
    at com.net.tel.interceptors.AttachmentInterceptor.afterCompletion(AttachmentInterceptor.java:46)
    at org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor.afterCompletion(DelegatingSmartEndpointInterceptor.java:90)
    at org.springframework.ws.server.MessageDispatcher.triggerAfterCompletion(MessageDispatcher.java:399)
    at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:249)
    at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:173)
    at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88)
    at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:59)
    at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:239)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3732)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are <{http://xmlns.tel.be/nin/v001}Request>,<{http://xmlns.tel.be/nin/v001}Response>,<{http://xmlns.tel.be/nin/v001}ScenarioEnum>,<{http://xmlns.tel.be/nin/v001}ValidationException>
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:663)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:258)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:253)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:120)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1064)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:499)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480)
    at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:75)
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:150)
    at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:244)
    at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:127)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:322)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:305)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:127)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:738)
    ... 27 more
> 

请求的xsd架构:

<xsd:element name="NinasNCOssRequest" type="RequestType"/>

<xsd:complexType name="RequestType">
        <xsd:sequence>
            <xsd:element name="locationId" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="false"/>
            <xsd:element name="workOrderId" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="false"/>
            <xsd:element name="systemName" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="false"/>
            <xsd:element name="scenarioId" type="schema:ScenarioType" minOccurs="1" maxOccurs="1" nillable="false"/>
            <xsd:element name="scenarioData" type="schema:ScenarioDataType" minOccurs="0" maxOccurs="1" nillable="false" />
        </xsd:sequence>
    </xsd:complexType>

<xsd:simpleType name="ScenarioType">
        <xsd:restriction base="xsd:int">
            <xsd:enumeration value="1"/>
            <xsd:enumeration value="2"/>
        </xsd:restriction>
    </xsd:simpleType>

<xsd:complexType name="ScenarioDataType">
        <xsd:sequence>
            <xsd:element name="scenarioData" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

任何提示如何解决它?

【问题讨论】:

  • 添加你正在发送的请求......那个不起作用的那个
  • 这些是完全不同的请求,具有不同的命名空间......等等。失败的请求有xmlns:v001="http://xmlns.telenet.be/oss/ninas/v001",正常的请求有xmlns:v001="http://xmlns.tel.be/nin/v001" 你的开始标签也不同。好像你把事情搞混了
  • 很抱歉,当我在您的评论后添加问题时,我忘记更改路径了 :) 现在一切正常
  • 您能否显示 XSD 的随附相关部分,该部分将那个元素(它不仅仅是一个标签)定义为可选的?
  • @Abel 更新了问题

标签: java spring soap xsd spring-ws


【解决方案1】:

最初,我认为您有验证异常,因此我询问了您的 XSD 架构文件。然而,这变得不正确。

你展示了:

<Error> <org.springframework.ws.soap.server.SoapMessageDispatcher> <devapp104.netcracker.com> <clust1> <[ACTIVE] ExecuteThread: '14' for queue: 'weblogic.kernel.Default (self-tuning)'> <guest> <> <> <1442316335622> <BEA-000000> <ERROR org.springframework.ws.soap.server.SoapMessageDispatcher - EndpointInterceptor.afterCompletion threw exception
org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are <{http://xmlns.tel.be/nin/v001}Request>,<{http://xmlns.tel.be/nin/v001}Response>,<{http://xmlns.tel.be/nin/v001}ScenarioEnum>,<{http://xmlns.tel.be/nin/v001}ValidationException>
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:863)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:742)

重要的是:

nested exception is javax.xml.bind.UnmarshalException: 
unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). 
Expected elements are 
    <{http://xmlns.tel.be/nin/v001}Request>,
    <{http://xmlns.tel.be/nin/v001}Response>,
    <{http://xmlns.tel.be/nin/v001}ScenarioEnum>,
    <{http://xmlns.tel.be/nin/v001}ValidationException>

你收到的&lt;Fault&gt;并不代表你发送的XML不正确,而是接收端没想到数据。 SOAP 的服务实现在发生意外情况时发送它,例如接收端未捕获的异常。

要找出导致异常的原因,您应该要求接收端实现SoapFaultDetail。一旦你有了它,并且他们用更多的细节(如堆栈跟踪或实际错误)填充它,你就可以更好地调查它。 Here's a guide on how to do that with Spring.

当然,即使您坚持 XSD 设计,您也可以问他们为什么不给您发送正确的响应。

【讨论】:

  • 感谢您的建议,我将尝试使用 SoapFaultDetail 调查此问题
【解决方案2】:

异常主要说明com.net.tel.interceptors.AttachmentInterceptor的实现有问题。堆栈跟踪表明这是一个端点拦截器,它尝试对来自服务的响应进行一些后处理,但无法识别 SOAP 错误响应:它没有以不同的方式处理它们,而是尝试以与成功响应,从而导致隐藏原始 SOAP 错误的异常。

一旦您在 com.net.tel.interceptors.AttachmentInterceptor 中解决了该问题,您将获得有意义的 SOAP 错误响应,这可能会告诉您服务拒绝您的请求的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-20
    • 2011-02-10
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多