【问题标题】:ArcGIS GeoEvent Processor - javax.xml.ws.soap.SOAPFaultException: Unmarshalling ErrorArcGIS GeoEvent 处理器 - javax.xml.ws.soap.SOAPFaultException:解组错误
【发布时间】:2014-11-19 11:40:27
【问题描述】:

背景

我正在使用 wsimport 创建本质上是一个 Java Web 服务客户端,连接到一个返回数据集的 .Net Web 服务(不幸的是)。更具体地说,我正在为 ESRI ArcGIS Server 10.2 的 GeoEvent 处理器套件开发一个项目(入站传输),但我认为这可能会以与 JAXB 和 WSDL 绑定相关的更一般的术语来回答。请耐心等待,因为我从大学(10 年以上)就没有接触过 Java。

就 WSDL 而言,.Net DataSet 是一种多态类型,其实际布局直到运行时才确定,在 DataSet 被数据填充之后。当您想将该 Web 服务与 .Net 以外的任何东西一起使用时,这会导致问题。

经过一些研究,我设法使用 wsimport 从 webservice wsdl 生成。然后,我能够编写一个基本的概念证明程序,该程序从作为 DOM 的 Web 服务获取结果,然后将该 DOM 作为节点列表。

参考:

我的wsimport是这样的(为了保护无辜,域名已经改了):

C:\Development\ArcGIS\WSDL>wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b xsd.xjb -keep -p com.somecompany.services -XadditionalHeaders http://services.somecompany.com/DataRetrieval.asmx?wsdl

问题

不幸的是,在我的概念验证中工作的相同代码库,从 web 服务中获取结果,一旦我在 ArcGIS GeoEvent 处理器中实施就失败了。我的项目是 ArcGIS GeoEvent 处理器将控制的 OSGI 包的一部分。下面的错误显示在 GeoEvent 处理器的 Apache Karaf 日志中。

基于错误,我的理解是我在 wsimport 中进行绑定的方式存在问题,根据我上面列出的那些链接引用通用模式。看起来通用模式缺少一些作为 wsimport 生成的类存在的元素的定义。当我检查 wsimport 的输出时,这些类似乎已正确生成。

由于发布限制,我没有包含 WSDL,但如果需要,我会在以后的回复中包含。

我想弄清楚什么

  • 应该如何解释这个错误?
  • 为什么在 ArcGIS GeoEvent 处理器中运行时,我的基本概念证明中用于访问 Web 服务的相同 wsimport 生成代码会失败?
  • 错误提到了 JAXB 和 SAX,我没有有意在概念验证或 ArcGIS GeoEvent 处理器项目中引用这些库。会不会是 web 服务的绑定/解组处理方式不同,ArcGIS GeoEvent 处理器包装在 JAXB/SAX 中,而概念证明不是?
  • 我可以做些什么来解决这个问题?
    1. 使用不同的自定义 xsd 和 xjb 来说明 Web 服务的预期架构?我不确定该怎么做。
    2. 使用 wsimport 以外的东西来生成 Web 服务引用类?
    3. 在 Java 环境中为 ArcGIS GeoEvent 处理器调整一些东西?
    4. 其他选项?
    5. 提交seppuku,那不是我的问题?

错误

2014-09-23 16:10:14,365 | ERROR | ansport Listener | SomeInboundTransport             | 367 - com.somecompany.arcgis.geoevent.transport.inbound.somecompanyInboundTransport - 1.0.0 | Unable to call Webservice
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (uri:"http://www.w3.org/2001/XMLSchema", local:"element"). Expected elements are <{http://services.somecompany.com/}complexType>,<{http://services.somecompany.com/}annotation>,<{http://services.somecompany.com/}redefine>,<{http://services.somecompany.com/}element>,<{http://services.somecompany.com/}include>,<{http://services.somecompany.com/}attributeGroup>,<{http://services.somecompany.com/}group>,<{http://services.somecompany.com/}notation>,<{http://services.somecompany.com/}import>,<{http://services.somecompany.com/}simpleType>,<{http://services.somecompany.com/}attribute> 
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)[120:org.apache.cxf.cxf-rt-frontend-jaxws:2.6.1]
    at com.sun.proxy.$Proxy198.getCompanyArcgisData(Unknown Source)[367:com.somecompany.arcgis.geoevent.transport.inbound.somecompanyInboundTransport:1.0.0]
    at com.somecompany.arcgis.geoevent.transport.inbound.SomeInboundTransport.callWebService(SomeInboundTransport.java:184)[367:com.somecompany.arcgis.geoevent.transport.inbound.somecompanyInboundTransport:1.0.0]
    at com.somecompany.arcgis.geoevent.transport.inbound.SomeInboundTransport.run(SomeInboundTransport.java:257)[367:com.somecompany.arcgis.geoevent.transport.inbound.somecompanyInboundTransport:1.0.0]
    at java.lang.Thread.run(Thread.java:722)[:1.7.0_17]
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 651; unexpected element (uri:"http://www.w3.org/2001/XMLSchema", local:"element"). Expected elements are <{http://services.somecompany.com/}complexType>,<{http://services.somecompany.com/}annotation>,<{http://services.somecompany.com/}redefine>,<{http://services.somecompany.com/}element>,<{http://services.somecompany.com/}include>,<{http://services.somecompany.com/}attributeGroup>,<{http://services.somecompany.com/}group>,<{http://services.somecompany.com/}notation>,<{http://services.somecompany.com/}import>,<{http://services.somecompany.com/}simpleType>,<{http://services.somecompany.com/}attribute>]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:425)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:362)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:784)[91:org.apache.cxf.cxf-rt-databinding-jaxb:2.6.1]
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:97)[91:org.apache.cxf.cxf-rt-databinding-jaxb:2.6.1]
    at org.apache.cxf.jaxb.JAXBEncoderDecoder$1.run(JAXBEncoderDecoder.java:812)
    at java.security.AccessController.doPrivileged(Native Method)[:1.7.0_17]
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:810)[91:org.apache.cxf.cxf-rt-databinding-jaxb:2.6.1]
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:644)[91:org.apache.cxf.cxf-rt-databinding-jaxb:2.6.1]
    at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:157)[91:org.apache.cxf.cxf-rt-databinding-jaxb:2.6.1]
    at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:108)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:798)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1667)[118:org.apache.cxf.cxf-rt-transports-http:2.6.1]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1520)[118:org.apache.cxf.cxf-rt-transports-http:2.6.1]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1428)[118:org.apache.cxf.cxf-rt-transports-http:2.6.1]
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:658)[118:org.apache.cxf.cxf-rt-transports-http:2.6.1]
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:532)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:464)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:367)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)[87:org.apache.cxf.cxf-api:2.6.1]
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:89)[119:org.apache.cxf.cxf-rt-frontend-simple:2.6.1]
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)[120:org.apache.cxf.cxf-rt-frontend-jaxws:2.6.1]
    ... 4 more
Caused by: com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 651; unexpected element (uri:"http://www.w3.org/2001/XMLSchema", local:"element"). Expected elements are <{http://services.somecompany.com/}complexType>,<{http://services.somecompany.com/}annotation>,<{http://services.somecompany.com/}redefine>,<{http://services.somecompany.com/}element>,<{http://services.somecompany.com/}include>,<{http://services.somecompany.com/}attributeGroup>,<{http://services.somecompany.com/}group>,<{http://services.somecompany.com/}notation>,<{http://services.somecompany.com/}import>,<{http://services.somecompany.com/}simpleType>,<{http://services.somecompany.com/}attribute>
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:101)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:243)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:242)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
    ... 28 more
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.w3.org/2001/XMLSchema", local:"element"). Expected elements are <{http://services.somecompany.com/}complexType>,<{http://services.somecompany.com/}annotation>,<{http://services.somecompany.com/}redefine>,<{http://services.somecompany.com/}element>,<{http://services.somecompany.com/}include>,<{http://services.somecompany.com/}attributeGroup>,<{http://services.somecompany.com/}group>,<{http://services.somecompany.com/}notation>,<{http://services.somecompany.com/}import>,<{http://services.somecompany.com/}simpleType>,<{http://services.somecompany.com/}attribute>
    ... 39 more

代码 (sn-p)

import com.somecompany.services.*; //generated by wsimport
import javax.xml.ws.*;
//...

private com.somecompany.services.DataRetrieval myWS;
private com.somecompany.services.DataRetrievalSoap port;

private byte[] callWebService(String userName, String pwd, long dataTimeFrame)
{
    try
    {
        myWS = new com.somecompany.services.DataRetrieval();

        port = myWS.getDataRetrievalSoap();
        com.somecompany.services.AuthSoapHeader mySoapHeader = new com.somecompany.services.AuthSoapHeader();
        mySoapHeader.setUserName(userName);

        //Hash the password then set it for the SOAP header
        String pwdHash = hashMD5(pwd);
        mySoapHeader.setPassword(pwdHash);
        Holder holder = new Holder<AuthSoapHeader>(mySoapHeader);

        Date endTime = new Date();
        Date startTime = new Date(endTime.getTime() - dataTimeFrame);
        XMLGregorianCalendar gcEndTime = dateToGregorianTime(endTime);
        XMLGregorianCalendar gcStartTime = dateToGregorianTime(startTime);

        GetCompanyArcgisDataResponse.GetCompanyArcgisDataResult companyData = port.getCompanyArcgisData(gcStartTime, gcEndTime, holder);

        if( ((AuthSoapHeader)holder.value).getError() != null)
        {
            log.error("Authentication to web services failed!");
            //OSGI stop service
            this.stop();
            return null;
        }else
            log.info("Authentication to web services successful.");

        //Convert the results to a java object and then to a byte array to send to the adapter
        Object companyDataAny = companyData.getAny();
        byte[] companyDataBytes = objectToBytes(companyDataAny);
        return companyDataBytes;

    }
    catch(Exception ex)
    {
        log.error("Unable to call Webservice", ex);
        //OSGI stop service
        this.stop();
        return null;
    }
}

环境细节

  • JDK 7u17 (1.7.0_17) 64 位。 ArcGIS GeoEvent 处理器正在使用此版本的 JRE,因此我被锁定在该版本中执行。虽然在意识到这一点之前我已经在 1.7.0_51 中进行了一些开发。
  • wsimport - JAX-WS RI 2.2.4-b01
  • ArcGIS 服务器 10.2
  • ArcGIS GeoEvent 处理器扩展
  • Karaf(ArcGIS Geovent 处理器用于运行 OSGI 包)

【问题讨论】:

    标签: java jaxb arcgis


    【解决方案1】:

    这可能不是最好的答案,但这是我想出的。

    包装我的 OSGI 项目的 ArcGIS GeoEvent 处理器似乎正在对我在我的应用程序中引用的 Web 服务进行一些额外的绑定/解除绑定。我用来让 .Net(DataSet 返回值)Web 服务在 Java 中运行的变通方法对于来自 GeoEvent 处理器的包装器来说是不可接受的。

    我的解决方案

    最终,我创建了一个辅助 .Net Web 服务,它获取 DataSet 值并将它们转换为 JSON,并返回 JSON 字符串。这消除了尝试从 Web 服务引用 DataSet 返回值时遇到的问题,现在我正在处理一个简单的 JSON 字符串。该 JSON Web 服务的 wsimport 运行顺利,无需变通方法。我将新导入的 Web 服务文件放入我的 java 项目中,现在没有问题了。

    关于 C# 数据集到 JSON 的参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 2021-06-12
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      相关资源
      最近更新 更多