Marshalling Error: XXXX is not known to this context

9733 ワード

最近の需要では、1つのcfx+springで構築されたwebServiceプロジェクトの1つの機能で別のWebServiceプロジェクトの2つのインタフェースを呼び出す必要があります.2つのインタフェースを単独で呼び出すのは異常ではありませんが、同時に2つのインタフェースを呼び出すと異常orgが報告されます.apache.cxf.interceptor.Fault:Marshalling Error:XXXX is not known to this conte,同僚の助けで解決され、例を作って記念します.
サービス側インタフェースA:
@WebService
public interface SayHello {

	public String sayHello(@WebParam(name = "name") String name);
}

インタフェースA実装クラス:
public class SayHelloImpl implements SayHello {

	@Resource
	private UserService userService;
	
	@Override
	public String sayHello(String name) {
		//User user = userService.findOne(Long.valueOf(id));
		return "Hello:" + name;
	}
}

サービス側インタフェースB
@WebService
public interface SayGoodBye {

	public String sayGoodBye(@WebParam(name = "name") String name);
}
インタフェースB実装クラス:
public class SayGoodByeImpl implements SayGoodBye {
	@Override
	public String sayGoodBye(String name) {
		
		return "bye:" + name;
	}
}

Springプロファイル:
	
	
	
	
	

クライアントコール:
	public static void main(String[] args){
		try {
			JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); 
			Client clientA = dcf.createClient("http://192.168.1.66:8080/groupClass/ws/getSayHelloService?wsdl");
			Object[] resultA = clientA.invoke("sayHello", "Joker");
			System.out.println("resultA===>" + resultA[0]);
			
			dcf = JaxWsDynamicClientFactory.newInstance(); 
			Client clientB = dcf.createClient("http://192.168.1.66:8080/groupClass/ws/getSayGoodByeService?wsdl");
			Object[] resultB = clientB.invoke("sayGoodBye", "Joker");
			System.out.println("resultB===>" + resultB[0]);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

取得された例外:
[INFO ] [08:43:33] org.apache.cxf.endpoint.dynamic.DynamicClientFactory - Created classes: gc.web.ws.ObjectFactory, gc.web.ws.SayHello, gc.web.ws.SayHelloResponse
  resultA===>Hello:Joker
[INFO ] [08:43:35] org.apache.cxf.endpoint.dynamic.DynamicClientFactory - Created classes: gc.web.ws.ObjectFactory, gc.web.ws.SayGoodBye, gc.web.ws.SayGoodByeResponse
  [WARN ] [08:43:35] org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://ws.web.gc/}SayGoodByeImplService#{http://ws.web.gc/}sayGoodBye has thrown exception, unwinding now
  org.apache.cxf.interceptor.Fault: Marshalling Error: gc.web.ws.SayGoodBye is not known to this context
	at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:266)
	at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:237)
	at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:117)
	at org.apache.cxf.wsdl.interceptors.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:297)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:283)
	at cms.web.util.ConnectWebService.main(ConnectWebService.java:129)
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: gc.web.ws.SayGoodBye is not known to this context
javax.xml.bind.JAXBException: gc.web.ws.SayGoodBye is not known to this context]
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)
	at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
	at org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:617)
	at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:241)
	... 11 more
Caused by: com.sun.istack.SAXException2: gc.web.ws.SayGoodBye is not known to this context
javax.xml.bind.JAXBException: gc.web.ws.SayGoodBye is not known to this context
	at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:247)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:262)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:147)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:130)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:332)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:339)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:75)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)
	... 15 more
Caused by: javax.xml.bind.JAXBException: gc.web.ws.SayGoodBye is not known to this context
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:613)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:144)
	... 21 more
org.apache.cxf.interceptor.Fault: Marshalling Error: gc.web.ws.SayGoodBye is not known to this context
	at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:266)
	at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:237)
	at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:117)
	at org.apache.cxf.wsdl.interceptors.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:297)
	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:283)
	at cms.web.util.ConnectWebService.main(ConnectWebService.java:129)
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: gc.web.ws.SayGoodBye is not known to this context
javax.xml.bind.JAXBException: gc.web.ws.SayGoodBye is not known to this context]
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)
	at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
	at org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:617)
	at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:241)
	... 11 more
Caused by: com.sun.istack.SAXException2: gc.web.ws.SayGoodBye is not known to this context
javax.xml.bind.JAXBException: gc.web.ws.SayGoodBye is not known to this context
	at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:247)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:262)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:147)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:130)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:332)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:339)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:75)
	at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
	at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)
	... 15 more
Caused by: javax.xml.bind.JAXBException: gc.web.ws.SayGoodBye is not known to this context
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:613)
	at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:144)
	... 21 more

エンド例外後のクライアントコード:
public static void main(String[] args){
		try {
			//            WebService  ,            
			ClassLoader cl = Thread.currentThread().getContextClassLoader();
			
			JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); 
			Client clientA = dcf.createClient("http://192.168.1.66:8080/groupClass/ws/getSayHelloService?wsdl");
			Object[] resultA = clientA.invoke("sayHello", "Joker");
			System.out.println("resultA===>" + resultA[0]);

                       Thread.currentThread().setContextClassLoader(cl);
			
			dcf = JaxWsDynamicClientFactory.newInstance(); 
			Client clientB = dcf.createClient("http://192.168.1.66:8080/groupClass/ws/getSayGoodByeService?wsdl");
			Object[] resultB = clientB.invoke("sayGoodBye", "Joker");
			System.out.println("resultB===>" + resultB[0]);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}