2012-11-05 75 views
1

我想將靜態CXF 2.5.4客戶端轉換爲動態生成的客戶端。我用下面的代碼:CXF動態客戶端獲取編組錯誤

 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

請提供您的架構 – willome

回答

1

你應該嘗試加載你的類像在此之前重置上下文類加載器:

Thread.currentThread().setContextClassloader(threadCL); 

描述: here