【问题标题】:CXF Dynamic Client getting Marshalling errorCXF 动态客户端收到编组错误
【发布时间】:2012-11-05 22:46:48
【问题描述】:

我正在尝试将静态 CXF 2.5.4 客户端转换为动态生成的客户端。我使用了以下代码:

        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        logger.info("Dynamically loading wsdl from " + theWsdlLocation);
        dynClient = dcf.createClient(theWsdlLocation, bindingFileList);
        if (dynClient == null) {
            logger.severe("dynClient creation not successful");
        } else {
            logger.info("Successful creation of service client from wsdl at " + theWsdlLocation);
        }
        ......
        http = (HTTPConduit) dynClient.getConduit();
        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
        ClassLoader clAfterClientPolicy = httpClientPolicy.getClass().getClassLoader();
        httpClientPolicy.setConnectionTimeout(36000);
        httpClientPolicy.setAllowChunking(false);
        http.setClient(httpClientPolicy);
        .......
        ClassLoader threadCL = Thread.currentThread().getContextClassLoader();
        Object asrReq = threadCL.loadClass("com.microsoft.schemas.dynamics._2008._01.services.AddressServiceReadRequest").newInstance();
        .......
        Object [] asrRespObjs = dynClient.invoke("read", asrReq);

当客户端启动 dynClient.invoke 方法时,它会抛出以下异常:

    org.apache.cxf.interceptor.Fault: Marshalling Error: com.microsoft.schemas.dynamics._2008._01.services.AddressServiceReadRequest is not known to this context
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:261)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)

谁能解释为什么 JAXB 不能编组 asrReq 对象?

【问题讨论】:

    标签: java web-services jaxb cxf


    【解决方案1】:

    您应该在加载类之前尝试重置上下文类加载器,如下所示:

    Thread.currentThread().setContextClassloader(threadCL); 
    

    如上所述: here

    【讨论】:

      猜你喜欢
      • 2014-12-12
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      • 2021-10-01
      相关资源
      最近更新 更多