【发布时间】:2019-09-17 23:26:02
【问题描述】:
我重构了一个 JAX-WS 客户端以在 Java11(来自 Java8)上运行。重构的代码现在使用来自 jaxws-rt-2.3.2.jar 的 jax-ws\jaxb 而不是 java8 rt.jar。客户端在没有错误的情况下能够成功处理响应,但是当收到错误时,它不会抛出异常。
我在 2 个 Eclipse 工作区中同时拥有新旧应用程序。 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版本工作区会抛出异常。
【问题讨论】: