JAX-WS 客户机收到的 SOAP 错误未引发异常



我重构了一个JAX-WS客户端,使其在Java11上运行(来自Java8(。 重构的代码现在使用 jaxws-rt-2.3.2 中的 jax-ws\jaxb.jar而不是 java8 rt.jar。 当没有错误时,客户端能够成功处理响应,但是当收到错误时,它不会引发异常。

我在 2 个日食工作区中同时拥有新旧应用程序。 CXF-codegen-plugin 3.3.1 用于在两者中生成客户端工件。 在调试模式下,我能够看到相同的请求在两者中的处理方式不同。 在解组响应时,Java11 工作区会创建 SOAP11Fault 对象,而不设置任何对象属性(错误代码、错误字符串、详细信息(。 这导致 SOAPFaultBuilder.createException(( 方法尝试返回 ProtcolException(它找不到(。 Java8 工作区使用必要的属性创建 SOAP11Fault,并使 SOAPFaultBuilder.createException(( 方法正确处理异常。 看起来jaxb没有在jaxws-rt发行版中正确解组XML消息。

W:

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:Service.ACME.v10.SomeProduct" xmlns:dt="urn:Data.ACME.v10.SomeProduct" xmlns:ft="urn:Fault.ACME.v10.SomeProduct" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" name="SomeProduct" targetNamespace="urn:Service.ACME.v10.SomeProduct">
<wsdl:types>
<xs:schema targetNamespace="urn:Data.ACME.v10.SomeProduct" xmlns:dt="urn:Data.ACME.v10.SomeProduct" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
...
</xs:schema>
</wsdl:types>
<wsdl:portType name="SomeProduct">
<wsdl:operation name="CallExpressInquiry">
<wsdl:input message="tns:ExpInq_InMsg"/>
<wsdl:output message="tns:ExpInq_OutMsg"/>
<wsdl:fault message="tns:InvalidInputErr_FaultMsg" name="InvalidInputErrFault"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SomeProductSOAP" type="tns:SomeProduct">
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#SomeProductPolicy"/>
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="CallExpressInquiry">
<soap:operation soapAction="http://www.acme.org/SomeProduct/CallExpressInquiry"/>
<wsdl:input>
<soap:body use="literal"/>
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#SomeProductPartsPolicy"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#SomeProductPartsPolicy"/>
</wsdl:output>
<wsdl:fault name="InvalidInputErrFault">
<soap:fault use="literal" name="InvalidInputErrFault"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SomeProductService">
<wsdl:port binding="tns:SomeProductSOAP" name="SomeProductSOAP">
<soap:address location="https://uat.services.SomeProduct.com:8444/SomeProduct"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

响应有效负载:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>The Following Sender Id Not Registered: 12345</faultstring>
<detail>
<ns2:InvalidInputError  xmlns:ns2="urn:Fault.ACME.v10.SomeProduct" xmlns="urn:Data.ACME.v10.SomeProduct">
<ns2:responseCode>307</ns2:responseCode>
</ns2:InvalidInputError>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

来自 jaxws-rt 包(StubHandler 类(的代码:

public JavaCallInfo readResponse(Packet p, JavaCallInfo call) throws Throwable {
Message msg = p.getMessage();
if(msg.isFault()) {
->>>        SOAPFaultBuilder faultBuilder = SOAPFaultBuilder.create(msg);
->>>        Throwable t = faultBuilder.createException(checkedExceptions);
call.setException(t);
throw t;
} else {
initArgs(call.getParameters());
Object ret = responseBuilder.readResponse(msg, call.getParameters());
call.setReturnValue(ret);
return call;
}
}

带有 Java8 日志的旧工作区(工作(:

Sep 17, 2019 3:34:26 PM com.sun.xml.internal.ws.api.pipe.Fiber dumpFiberContext
FINE: engine-JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e: Stub for https://uat.services.ensurebill.com:8444/EnsureBillfiber-1 After tube execution with NO ACTION or MSG ID and 'current' tube com.sun.xml.internal.ws.handler.ClientLogicalHandlerTube@571f07be.processResponse() from thread SwingWorker-pool-1-thread-1 with Packet: com.sun.xml.internal.ws.api.message.Packet@6ac6209f
Sep 17, 2019 3:34:26 PM com.sun.xml.internal.ws.api.pipe.Fiber dumpFiberContext
FINE: engine-JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e: Stub for https://uat.services.ensurebill.com:8444/EnsureBillfiber-1 After tube execution with NO ACTION or MSG ID and 'current' tube null.processResponse() from thread SwingWorker-pool-1-thread-1 with Packet: com.sun.xml.internal.ws.api.message.Packet@6ac6209f
Sep 17, 2019 3:34:26 PM com.sun.xml.internal.ws.api.pipe.Fiber _doRun
FINE: Thread leaving _doRun(): Thread[SwingWorker-pool-1-thread-1,5,main]
Sep 17, 2019 3:34:26 PM com.sun.xml.internal.ws.api.pipe.Fiber completionCheck
FINE: engine-JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e: Stub for https://uat.services.ensurebill.com:8444/EnsureBillfiber-1 completed
Sep 17, 2019 3:34:28 PM java.awt.DefaultKeyboardFocusManager dispatchEvent
FINE: sun.awt.TimedWindowEvent[WINDOW_LOST_FOCUS,opposite=null,oldState=0,newState=0] on frame0
Sep 17, 2019 3:34:28 PM java.awt.DefaultKeyboardFocusManager dispatchEvent
FINE: Active javax.swing.JFrame[frame0,0,0,1216x732,invalid,layout=java.awt.BorderLayout,title=Ensurebill SDK Sandbox v14.1.00.3 | Java Version: 1.8,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,8,31,1200x693,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true], Current focused javax.swing.JFrame[frame0,0,0,1216x732,invalid,layout=java.awt.BorderLayout,title=Ensurebill SDK Sandbox v14.1.00.3 | Java Version: 1.8,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,8,31,1200x693,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true], losing focus javax.swing.JFrame[frame0,0,0,1216x732,invalid,layout=java.awt.BorderLayout,title=Ensurebill SDK Sandbox v14.1.00.3 | Java Version: 1.8,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,8,31,1200x693,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true] opposite null
Sep 17, 2019 3:34:28 PM java.awt.DefaultKeyboardFocusManager dispatchEvent
FINE: java.awt.FocusEvent[FOCUS_LOST,temporary,opposite=null,cause=ACTIVATION] on javax.swing.JTextArea[,0,0,440x640,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@2a127b2a,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],colums=40,columWidth=11,rows=40,rowHeight=16,word=true,wrap=true]
Sep 17, 2019 3:34:28 PM java.awt.DefaultKeyboardFocusManager dispatchEvent
FINE: java.awt.event.WindowEvent[WINDOW_DEACTIVATED,opposite=null,oldState=0,newState=0] on frame0
Keep-Alive-Timer, called close()
Keep-Alive-Timer, called closeInternal(true)
Keep-Alive-Timer, SEND TLSv1.2 ALERT:  warning, description = close_notify
Keep-Alive-Timer, WRITE: TLSv1.2 Alert, length = 80
Keep-Alive-Timer, called closeSocket(true)
Sep 17, 2019 3:34:39 PM javax.xml.bind.ContextFinder find
FINE: Trying to locate com/sun/xml/internal/ws/fault/jaxb.properties
Sep 17, 2019 3:34:39 PM javax.xml.bind.ContextFinder find
FINE:   not found
Sep 17, 2019 3:34:39 PM javax.xml.bind.ContextFinder find
FINE: Trying to locate com/sun/xml/internal/ws/fault/jaxb.properties
Sep 17, 2019 3:34:39 PM javax.xml.bind.ContextFinder find
FINE:   not found
Sep 17, 2019 3:34:39 PM javax.xml.bind.ContextFinder find
FINE: Checking system property javax.xml.bind.context.factory
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder find
FINE:   not found
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder find
FINE: Checking system property javax.xml.bind.JAXBContext
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder find
FINE:   not found
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder lookupJaxbContextUsingOsgiServiceLoader
FINE: Unable to find from OSGi: javax.xml.bind.JAXBContext
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder find
FINE: Checking META-INF/services
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder find
FINE: Unable to find: META-INF/services/javax.xml.bind.JAXBContext
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder find
FINE: Trying to create the platform default provider
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder safeLoadClass
FINE: Trying to load com.sun.xml.internal.bind.v2.ContextFactory
Sep 17, 2019 3:34:40 PM javax.xml.bind.ContextFinder newInstance
FINE: loaded com.sun.xml.internal.bind.v2.ContextFactory from jar:file:/C:/Program%20Files/Java/jdk1.8.0_171/jre/lib/rt.jar!/com/sun/xml/internal/bind/v2/ContextFactory.class
Sep 17, 2019 3:34:40 PM com.sun.xml.internal.bind.v2.ContextFactory createContext
FINE: Property com.sun.xml.internal.bind.XmlAccessorFactoryis not active.  Using JAXB's implementation
Sep 17, 2019 3:35:19 PM com.sun.xml.internal.bind.v2.util.XmlFactory createTransformerFactory
FINE: TransformerFactory instance: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl@5fd6be83
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE: Trying to locate com/sun/xml/internal/ws/fault/jaxb.properties
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE:   not found
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE: Checking system property javax.xml.bind.context.factory
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE:   not found
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE: Checking system property javax.xml.bind.JAXBContext
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE:   not found
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder lookupJaxbContextUsingOsgiServiceLoader
FINE: Unable to find from OSGi: javax.xml.bind.JAXBContext
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE: Checking META-INF/services
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE: Unable to find: META-INF/services/javax.xml.bind.JAXBContext
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder find
FINE: Trying to create the platform default provider
Sep 17, 2019 3:35:50 PM javax.xml.bind.ContextFinder safeLoadClass
FINE: Trying to load com.sun.xml.internal.bind.v2.ContextFactory
Sep 17, 2019 3:35:51 PM javax.xml.bind.ContextFinder newInstance
FINE: loaded com.sun.xml.internal.bind.v2.ContextFactory from jar:file:/C:/Program%20Files/Java/jdk1.8.0_171/jre/lib/rt.jar!/com/sun/xml/internal/bind/v2/ContextFactory.class
Sep 17, 2019 3:35:51 PM com.sun.xml.internal.bind.v2.ContextFactory createContext
FINE: Property com.sun.xml.internal.bind.XmlAccessorFactoryis not active.  Using JAXB's implementation
ensurebill.v10.tsysa.service.InvalidInputErrFaultMsg: The Following Sender Id Not Registered:F1273E49D2CA45C6AFD1413C1F0EF800
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:135)
at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:238)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:189)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:276)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:104)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)

带有 Java11 日志的新工作区(不引发异常(:

Sep 17, 2019 3:51:30 PM com.sun.xml.ws.api.pipe.Fiber dumpFiberContext
FINE: engine-JAX-WS RI 2.3.2 git-revision#3d0bba4: Stub for https://uat.services.ensurebill.com:8444/EnsureBillfiber-1 After tube execution with NO ACTION or MSG ID and 'current' tube com.sun.xml.ws.handler.ClientLogicalHandlerTube@3d400f20.processResponse() from thread SwingWorker-pool-1-thread-1 with Packet: com.sun.xml.ws.api.message.Packet@211f3a60
Sep 17, 2019 3:51:30 PM com.sun.xml.ws.api.pipe.Fiber dumpFiberContext
FINE: engine-JAX-WS RI 2.3.2 git-revision#3d0bba4: Stub for https://uat.services.ensurebill.com:8444/EnsureBillfiber-1 After tube execution with NO ACTION or MSG ID and 'current' tube null.processResponse() from thread SwingWorker-pool-1-thread-1 with Packet: com.sun.xml.ws.api.message.Packet@211f3a60
Sep 17, 2019 3:51:30 PM com.sun.xml.ws.api.pipe.Fiber _doRun
FINE: Thread leaving _doRun(): Thread[SwingWorker-pool-1-thread-1,5,main]
Sep 17, 2019 3:51:30 PM com.sun.xml.ws.api.pipe.Fiber completionCheck
FINE: engine-JAX-WS RI 2.3.2 git-revision#3d0bba4: Stub for https://uat.services.ensurebill.com:8444/EnsureBillfiber-1 completed
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder find
FINE: Searching jaxb.properties
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder getSystemProperty
FINE: Checking system property javax.xml.bind.JAXBContextFactory
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder getSystemProperty
FINE:   not found
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder getSystemProperty
FINE: Checking system property javax.xml.bind.context.factory
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder getSystemProperty
FINE:   not found
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder getSystemProperty
FINE: Checking system property javax.xml.bind.JAXBContext
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder getSystemProperty
FINE:   not found
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder firstByServiceLoaderDeprecated
FINE: Searching META-INF/services
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder firstByServiceLoaderDeprecated
FINE: Configured factorty class:com.sun.xml.bind.v2.ContextFactory
Sep 17, 2019 3:51:30 PM javax.xml.bind.ContextFinder newInstance
FINE: loaded com.sun.xml.bind.v2.ContextFactory from jar:file:/C:/Users/layanij/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jaxb-runtime-2.3.2.jar!/com/sun/xml/bind/v2/ContextFactory.class
Sep 17, 2019 3:51:30 PM com.sun.xml.bind.v2.ContextFactory createContext
FINE: Property com.sun.xml.bind.XmlAccessorFactoryis not active.  Using JAXB's implementation
Sep 17, 2019 3:51:30 PM javax.xml.soap.FactoryFinder getSystemProperty
FINE: Checking system property javax.xml.soap.SAAJMetaFactory
Sep 17, 2019 3:51:30 PM javax.xml.soap.FactoryFinder logFound
FINE:   found com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl

期望在 Java11 版本工作区中引发异常。

好消息,坏消息。 好消息是我能够让它工作。 坏消息是我不知道它做了什么。 经过数小时的尝试解决,我决定从头开始创建一个新的工作区,然后手动重新应用我的更改。我运行了它,错误响应最终在我的客户端中抛出了一个异常"createFault 的 faultCode 参数被传递为 NULL",这证实了我之前的观察。我能够在网上找到表明响应可能与架构不一致的信息。 我根据架构验证了 XML 有效负载,它是有效的。 我从命令提示符(在 eclipse 之外(使用 maven 重建了项目,并重新启动了重新测试的应用程序。 错误的属性现在正确填充,我的客户端能够按预期处理错误。 对于那些在 eclipse 中开发的人,我唯一的建议是,如果所有其他方法都失败了,请构建一个新的工作区,看看是否有帮助。

相关内容

  • 没有找到相关文章

最新更新