Apache CXF - 代码第一Web服务 - JAXB绑定

时间:2011-12-12 18:35:42

标签: web-services apache cxf

我开发了一个Webservice,我的客户端得到了这个例外:

Dez 12, 2011 7:26:51 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL

Information: Creating Service {http://interfaces.loginserver.mmo.com/}ILoginService from WSDL: http://localhost:8080/loginService?wsdl

Dez 12, 2011 7:26:53 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL

Information: Creating Service {http://interfaces.loginserver.mmo.com/}ILoginService from WSDL: http://localhost:8080/loginService?wsdl

Dez 12, 2011 7:26:58 PM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging

Warnung: Interceptor for {http://interfaces.loginserver.mmo.com/}ILoginService#{http://interfaces.loginserver.mmo.com/}login has thrown exception, unwinding now

org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:824)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:644)

      at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:156)

      at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:109)

      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

      at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:801)

      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1627)

      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1494)

      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1402)

      at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)

      at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:649)

      at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)

      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

      at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:535)

      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:465)

      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:368)

      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:321)

      at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)

      at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)

      at $Proxy25.login(Unknown Source)

      at com.mmo.client.main.Main.<init>(Main.java:36)

      at com.mmo.client.main.Main.main(Main.java:41)

Caused by: javax.xml.bind.UnmarshalException

- with linked exception:

[com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 211; unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)]

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:434)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:371)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:348)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:784)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:96)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder$1.run(JAXBEncoderDecoder.java:812)

      at java.security.AccessController.doPrivileged(Native Method)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:810)

      ... 21 more

Caused by: com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 211; unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:662)

      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.Loader.childElement(Loader.java:105)

      at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:251)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:498)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480)

      at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:247)

      at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:181)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:369)

      ... 27 more

Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)

      ... 38 more



Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)

      at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)

      at $Proxy25.login(Unknown Source)

      at com.mmo.client.main.Main.<init>(Main.java:36)

      at com.mmo.client.main.Main.main(Main.java:41)

Caused by: javax.xml.bind.UnmarshalException

- with linked exception:

[com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 211; unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)]

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:434)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:371)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:348)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:784)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:96)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder$1.run(JAXBEncoderDecoder.java:812)

      at java.security.AccessController.doPrivileged(Native Method)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:810)

      at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:644)

      at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:156)

      at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:109)

      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

      at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:801)

      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1627)

      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1494)

      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1402)

      at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)

      at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:649)

      at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)

      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

      at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:535)

      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:465)

      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:368)

      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:321)

      at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)

      at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)

      ... 3 more

Caused by: com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 211; unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:662)

      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.Loader.childElement(Loader.java:105)

      at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:251)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:498)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480)

      at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:247)

      at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:181)

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:369)

      ... 27 more

Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)

      ... 38 more

我的Web服务包含XSD架构?!我不明白为什么Apache CXF抛出此异常?!

你能帮我吗?!

1 个答案:

答案 0 :(得分:2)

原因很清楚:

org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"", local:"sessionKey"). Expected elements are (none)

您的客户端正在提供sessionKey元素的请求,该元素不在您的XSD方案中,JAXB不知道它,因此抛出异常,它无法解析由{1}}方案提供的请求客户端。