2012-05-31 54 views
3

我正在使用Apache CXF Web服務和Spring集成,現在我還沒有如何從您的CXF端點調用Spring集成應用程序。如何從您的CXF端點調用Spring集成應用程序

我有工作經驗的Apache的駱駝,是很容易解決這個問題...但在Spring Integration的我沒有任何想法....

我行代碼是:

  1. 在Web服務定義-beans.xml文件:

    <!-- Load CXF modules from cxf.jar --> 
    <import resource="classpath:META-INF/cxf/cxf.xml"/> 
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> 
    
    <!--Exposing the HelloWorld service as a SOAP service --> 
    <bean id="jaxbBean" 
         class="org.apache.cxf.jaxb.JAXBDataBinding" 
         scope="prototype"/> 
    
    <bean id="jaxws-and-aegis-service-factory" 
         class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean" 
         scope="prototype"> 
        <property name="dataBinding" ref="jaxbBean"/> 
        <property name="serviceConfigurations"> 
        <list> 
         <bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration"/> 
         <bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration"/> 
         <bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/> 
        </list> 
    </property> 
    </bean> 
    
    <jaxws:endpoint id="helloWorld" 
          serviceName="HelloWorldService" 
          implementorClass="com.datys.cxf.HelloWorldService" 
          address="/HelloWorld"> 
        <jaxws:serviceFactory> 
         <ref bean="jaxws-and-aegis-service-factory"/> 
        </jaxws:serviceFactory> 
    </jaxws:endpoint> 
    
  2. 在服務定義-beans.xml文件:

    <gateway id="HelloWorldService" 
         default-request-channel="requestStrings" 
         default-reply-channel="replyStrings"    
         service-interface="com.datys.cxf.HelloWorldService"> 
        <method name="sayHello"/> 
    </gateway> 
    
    <channel id="requestStrings"/> 
    <channel id="replyStrings"/> 
    
    <!--<channel id="filesOut"/>--> 
    <service-activator input-channel="requestStrings" 
            output-channel="filesOut" 
            ref="handler" method="handleString"/> 
    
    <file:outbound-channel-adapter id="filesOut" 
               directory="file:D:/OUTPUT"/> 
    
    <beans:bean id="handler" class="org.springframework.integration.samples.filecopy.Handler"/> 
    

但是當我部署和客戶端Web服務調用Web服務來回報這個錯誤:

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could not instantiate service  class com.datys.cxf.HelloWorldService because it is an interface. 
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:171) 
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:94) 
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:240) 
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210) 
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103) 
at $Proxy29.sayHello(Unknown Source) 

回答

3

也許最簡單的辦法是配置一個<網關>。這使您可以提供任何可以注入到端點並調用它來啓動消息流的接口。在封面下,接口的實現方式與Spring中其他「ProxyFactoryBean」實現相同(例如,通過RMI,HttpInvoker等進行遠程處理)。

下面是從參考手冊中相關章節: http://static.springsource.org/spring-integration/docs/2.1.x/reference/htmlsingle/#gateway-proxy

+0

我解決了這個問題,通過你的答案啓發。我創建了普通的cxf web服務,並且在實現中,我調用網關bean來在我的spring集成流程中路由請求消息...這不是一個漂亮的解決方案,但它工作正常...! – kikicarbonell

相關問題