1

我正在尝试将静态 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 对象?

4

1 回答 1

1

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

Thread.currentThread().setContextClassloader(threadCL); 

如上所述: 这里

于 2012-12-23T14:02:20.257 回答