java - 使用有问题的 wsdl 的服务 - 意外的元素异常

标签 java eclipse web-services wsdl cxf

我必须使用有问题的 wsdl 服务(无法更改它)。起初我不得不自定义映射,因为生成的类在 java.x 包中。现在我生成了 vanilla 客户端并尝试使用它:

    Services handle = new Services(new URL("http://172.16.1.2:8080/axis2/services/x?wsdl"));
    ServicesPortType service = handle
            .getServicesHttpSoap11Endpoint();


    x.y.ws.datamodels.xsd.ObjectFactory obj = new x.y.ws.datamodels.xsd.ObjectFactory();

    IPInterfaceInfo sourceIPInterface = obj.createIPInterfaceInfo();
            service.getInformation(sourceIPInterface);

无论如何,这段实际上什么都不做并且只包含空值的代码抛出了一个异常:

WARNING: Interceptor for {http://workflowprocessor.ws.y.x}Services# {http://workflowprocessor.ws.y.x}getBandwidthInformation has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"http://datamodels.ws.y.x/xsd", local:"infoString"). Expected elements are <{http://logging.util.java/xsd}resourceBundleName>,<{http://logging.util.java/xsd}resourceBundle>,<{http://logging.util.java/xsd}parent>,<{http://logging.util.java/xsd}useParentHandlers>,<{http://logging.util.java/xsd}filter>,<{http://logging.util.java/xsd}handlers>,<{http://logging.util.java/xsd}level>,<{http://logging.util.java/xsd}name> 
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:822)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:643)
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:157)
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:799)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1635)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1502)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1410)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:650)
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:533)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
at $Proxy34.getBandwidthInformation(Unknown Source)
at adva.SimpleTest.main(SimpleTest.java:33)

引起:javax.xml.bind.UnmarshalException

最佳答案

可以通过设置选项 set-jaxb-validation-event-handler 来禁用验证,例如:

    Services servicehandle = new Services(new URL("http://172.16.2.3:8080/axis2/services/x?wsdl"));
    ServicesPortType port = servicehandle
            .getServicesHttpSoap11Endpoint();



      java.util.Map<String, Object> requestContext =
                               ((javax.xml.ws.BindingProvider)
                port).getRequestContext();
    requestContext.put("set-jaxb-validation-event-handler",  "false");

关于java - 使用有问题的 wsdl 的服务 - 意外的元素异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16539021/

相关文章:

java - 使用 Java 8 从 "Map<String, Collection<String>>"到 "Map<String, List<String>>"

java - 在文本文件中输出变量

java - 如何在eclipse中执行页面对象程序?

java - Jar 文件无法正常工作,出现错误 : Invalid jar file

java - 组合 getSelectedItem 但然后

java - JUnit 在 play 框架 2.0.4 中测试 Akka 参与者 - scala.concurrent.duration.Duration 上的 JAVA ClassNotFoundException

java - JAX-RS : How to return a response and continue processing the request in the back end

java - FitNesse:启用 FitNesse Fixture 以在服务器端调用方法

java - 服务器端事件未使用 SSE 在 Jersey 2.8 中触发

java - 从 SQLite 数据库中删除的数据再次出现