我正在尝试将静态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对象吗?
答案 0 :(得分:1)
在加载类之前,您应该尝试重置Context Class Loader:
Thread.currentThread().setContextClassloader(threadCL);
如上所述: here