从RESTful服务调用SOAP服务

时间:2013-12-31 06:48:08

标签: java web-services rest soap cxf

我在Spring中使用Apache CXF框架为我的项目创建RESTful API。现在,我需要使用我的REST服务调用SOAP服务。

我通过Eclipse生成了java代码和客户端,生成了所有客户端代码和调用服务的主方法。但是,只要我将此代码放入我的RESTful服务并实例化使用@WebServiceClient注释的类,我就会得到类强制转换异常,并显示消息无法确定BusFactory实现类名称

这是stacktrace

java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
at java.lang.Class.asSubclass(Unknown Source) [rt.jar:1.6.0_45]
at org.apache.cxf.BusFactory.getBusFactoryClass(BusFactory.java:362) [cxf-api-2.2.12.jar:2.2.12]
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:289) [cxf-api-2.2.12.jar:2.2.12]
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:276) [cxf-api-2.2.12.jar:2.2.12]
at org.jboss.wsf.stack.cxf.client.ProviderImpl.setValidThreadDefaultBus(ProviderImpl.java:242) [jbossws-cxf-client-4.1.4.Final-redhat-7.jar:4.1.4.Final-redhat-7]
at org.jboss.wsf.stack.cxf.client.ProviderImpl.createServiceDelegate(ProviderImpl.java:164) [jbossws-cxf-client-4.1.4.Final-redhat-7.jar:4.1.4.Final-redhat-7]
at javax.xml.ws.Service.<init>(Service.java:57) [jboss-jaxws-api_2.2_spec-2.0.1.Final-redhat-2.jar:2.0.1.Final-redhat-2]
at org.tempuri.ifl_sms_ms.IFLSMSMSSOAPHTTPService.<init>(IFLSMSMSSOAPHTTPService.java:49) [classes:]
at com.ifli.rapid.proxy.impl.SMSProxyImpl.sendSms(SMSProxyImpl.java:176) [classes:]
at com.ifli.rapid.proxy.impl.SMSProxyImpl.sendSMSWithoutTemplate(SMSProxyImpl.java:129) [classes:]
at com.ifli.rapid.notification.services.impl.SMSServiceImpl.sendSMS(SMSServiceImpl.java:73) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.6.0_45]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) [spring-tx-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) [spring-aop-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at com.sun.proxy.$Proxy71.sendSMS(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.6.0_45]
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173) [cxf-rt-core-2.2.12.jar:2.2.12]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89) [cxf-rt-core-2.2.12.jar:2.2.12]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:133) [cxf-rt-frontend-jaxrs-2.2.12.jar:2.2.12]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:82) [cxf-rt-frontend-jaxrs-2.2.12.jar:2.2.12]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) [cxf-rt-core-2.2.12.jar:2.2.12]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [rt.jar:1.6.0_45]
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) [rt.jar:1.6.0_45]
at java.util.concurrent.FutureTask.run(Unknown Source) [rt.jar:1.6.0_45]
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) [cxf-rt-core-2.2.12.jar:2.2.12]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106) [cxf-rt-core-2.2.12.jar:2.2.12]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243) [cxf-api-2.2.12.jar:2.2.12]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:111) [cxf-rt-core-2.2.12.jar:2.2.12]
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:99) [cxf-rt-transports-http-2.2.12.jar:2.2.12]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:431) [cxf-rt-transports-http-2.2.12.jar:2.2.12]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:147) [cxf-rt-transports-http-2.2.12.jar:2.2.12]
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:148) [cxf-rt-transports-http-2.2.12.jar:2.2.12]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179) [cxf-rt-transports-http-2.2.12.jar:2.2.12]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:103) [cxf-rt-transports-http-2.2.12.jar:2.2.12]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159) [cxf-rt-transports-http-2.2.12.jar:2.2.12]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.2.1.Final-redhat-10.jar:7.2.1.Final-redhat-10]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_45]

有没有人知道发生了什么事?代码在REST服务之外运行良好。

以下是用于调用SOAP服务的代码

final QName SERVICE_NAME = new QName("http://tempuri.org/IFL_SMS_MS",        "IFL_SMS_MSSOAP_HTTP_Service");
IFLSMSMSSOAPHTTPService ss = new IFLSMSMSSOAPHTTPService(wsdlURL, SERVICE_NAME);
IFLSMSMSPortType port = ss.getIFLSMSMSSOAPHTTPPort();
org.tempuri.ifl_sms_ms.REQUEST _smsRequest_requestMSG = new    org.tempuri.ifl_sms_ms.REQUEST();
_smsRequest_requestMSG.setPHNO(sendTo);
_smsRequest_requestMSG.setTEXT(text);
RESPONSE _smsRequest__return = port.smsRequest(_smsRequest_requestMSG);

0 个答案:

没有答案