<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Ordinary hut

    人間一福地,勝似天仙宮
    posts - 61, comments - 50, trackbacks - 0, articles - 1

    Camel與cxf

    Posted on 2011-09-29 13:50 landor 閱讀(2336) 評(píng)論(2)  編輯  收藏 所屬分類(lèi): camel
    camel是一個(gè)路由選擇引擎,具體內(nèi)容可見(jiàn)
    http://camel.apache.org
    還有一本camel in action,對(duì)camel核心進(jìn)行了詳細(xì)講解;

    這是一個(gè)簡(jiǎn)單的例子,接收一個(gè)webservice消息,并且通過(guò)camel把消息路由給一個(gè)bean;
    需要一些jar包:
    apache-cxf-2.3.3\lib\cxf-2.3.3.jar
    apache
    -cxf-2.3.3\lib\XmlSchema-1.4.7.jar
    apache
    -cxf-2.3.3\lib\neethi-2.0.4.jar
    apache
    -cxf-2.3.3\lib\wss4j-1.5.11.jar
    apache
    -cxf-2.3.3\lib\wsdl4j-1.6.2.jar
    apache
    -cxf-2.3.3\lib\geronimo-servlet_3.0_spec-1.0.jar
    apache
    -cxf-2.3.3\lib\jsr311-api-1.1.1.jar
    apache
    -cxf-2.3.3\lib\jetty-continuation-7.2.2.v20101205.jar
    apache
    -cxf-2.3.3\lib\jetty-http-7.2.2.v20101205.jar
    apache
    -cxf-2.3.3\lib\jetty-server-7.2.2.v20101205.jar
    apache
    -cxf-2.3.3\lib\jetty-util-7.2.2.v20101205.jar
    apache
    -cxf-2.3.3\lib\jetty-io-7.2.2.v20101205.jar
    apache
    -camel-2.7.1\lib\spring\spring-beans-3.0.5.RELEASE.jar
    apache
    -camel-2.7.1\lib\spring\spring-context-3.0.5.RELEASE.jar
    apache
    -camel-2.7.1\lib\spring\spring-context-support-3.0.5.RELEASE.jar
    apache
    -camel-2.7.1\lib\spring\spring-core-3.0.5.RELEASE.jar
    apache
    -camel-2.7.1\lib\spring\spring-expression-3.0.5.RELEASE.jar
    apache
    -camel-2.7.1\lib\spring\spring-tx-3.0.5.RELEASE.jar
    apache
    -camel-2.7.1\lib\spring\aopalliance-1.0.jar
    apache
    -camel-2.7.1\lib\spring\commons-logging-1.1.1.jar
    apache
    -camel-2.7.1\lib\spring\spring-aop-3.0.5.RELEASE.jar
    apache
    -camel-2.7.1\lib\spring\spring-asm-3.0.5.RELEASE.jar
    apache
    -camel-2.7.1\lib\slf4j-api-1.6.1.jar
    apache
    -camel-2.7.1\lib\camel-core-2.7.1.jar
    apache
    -camel-2.7.1\lib\commons-management-1.0.jar
    apache
    -camel-2.7.1\lib\camel-cxf-2.7.1.jar
    apache
    -camel-2.7.1\lib\camel-spring-2.7.1.jar

    1 新建bean:
    package bean;
    public class Usr {
        
    public String test(String str){
            System.out.println(
    "Hello Bean    "+str);
            
    return "Hello Bean    "+str;
        }
    }

    2 再新建一個(gè)webservice接口文件:
    package server;
    import javax.jws.WebService;
    @WebService
    public interface IHello {
        String sayHi(String name);
    }

    3 需要建立spring配置文件,放在classpath下
    配置文件有兩個(gè)用途:
        用cxf發(fā)布一個(gè)webservice;
        配置camel的route
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:cxf
    ="http://camel.apache.org/schema/cxf"
        xmlns:camel
    ="http://camel.apache.org/schema/spring"
        xsi:schemaLocation
    ="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://camel.apache.org/schema/spring 
            http://camel.apache.org/schema/spring/camel-spring.xsd
            http://camel.apache.org/schema/cxf
            http://camel.apache.org/schema/cxf/camel-cxf.xsd"
    >

        
    <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-extension-http-jetty.xml" />
        
        
    <!--發(fā)布一個(gè)webservice-->
        
    <cxf:cxfEndpoint id="orderEndpoint"
                     address
    ="http://localhost:9000/helloWorld"
                     serviceClass
    ="server.IHello"
                     
    />
        
        
    <bean id="usr" class="bean.Usr"></bean>
            
        
    <camelContext xmlns="http://camel.apache.org/schema/spring">
            
    <route>
                
    <from uri="cxf:bean:orderEndpoint"/>
                
    <bean ref="usr" method="test"/>
            
    </route>
        
    </camelContext>
    </beans>

    4 啟動(dòng)camel:

    package camel;
    import org.apache.camel.spring.Main;
    public class Helloworld {
        
    public static void main(String[] args) throws Throwable {
            Main main 
    = new Main();
            main.start();
            Thread.sleep(
    600000);
            main.stop();
        }
    }

    5 寫(xiě)個(gè)webservice客戶(hù)端測(cè)試一下:
    package client;
    import java.net.URL;
    import javax.xml.namespace.QName;
    import javax.xml.ws.Service;
    import server.IHello;
    public class Test {
        
    public static void main(String[] args) throws Throwable{
            URL wsdlURL 
    = new URL("http://localhost:9000/helloWorld?wsdl");//WSDL文件地址
            QName SERVICE_NAME 
    = new QName("http://server/""IHelloService");//參數(shù)一是WSDL中的 targetNamespace,參數(shù)2是WSDL中的 name 節(jié)點(diǎn)
            Service service = Service.create(wsdlURL, SERVICE_NAME);
            IHello client 
    = service.getPort(IHello.class);
            String result 
    = client.sayHi("bbb");
            System.out.println(result);
        }
    }

    得到的結(jié)果應(yīng)該是:
    Hello Bean    bbb

    Feedback

    # re: Camel與cxf  回復(fù)  更多評(píng)論   

    2012-06-10 20:17 by jdkleo
    我的client代碼:
    public class CamelCxfClient {
    public static void main(String[] args) throws Throwable{
    URL wsdlURL = new URL("http://localhost:8080/camel_ws/webservice/helloWorld?wsdl");
    // QName SERVICE_NAME = new QName("http://www.springframework.org/schema/beans", "helloWorld");

    QName SERVICE_NAME = new QName("http://www.springframework.org/schema/beans", "helloWorld");
    Service service = Service.create(wsdlURL, SERVICE_NAME);
    IHelloWorld client = service.getPort(IHelloWorld.class);
    String result = client.sayHi("bbb");
    System.out.println(result);
    }
    }
    我跑后變成這樣:
    Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: org.apache.cxf.message.Exchange.getBindingOperationInfo()Lorg/apache/cxf/service/model/BindingOperationInfo;
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:143)
    at $Proxy35.sayHi(Unknown Source)
    at camel.ws.CamelCxfClient.main(CamelCxfClient.java:13)
    Caused by: org.apache.cxf.binding.soap.SoapFault: org.apache.cxf.message.Exchange.getBindingOperationInfo()Lorg/apache/cxf/service/model/BindingOperationInfo;
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:96)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:658)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2139)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2022)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1947)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:632)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:472)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:302)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:254)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:123)
    ... 2 more

    # re: Camel與cxf  回復(fù)  更多評(píng)論   

    2012-06-10 20:30 by jdkleo
    i am so sorry that i find
    in my pom.xml
    the <cxf.version>2.2.3</cxf.version>
    that must be changed to
    <cxf.version>2.3.3</cxf.version>
    oh fuck

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲熟妇无码AV在线播放| 免费91最新地址永久入口 | 四虎影院免费视频| 免费国产在线精品一区 | 一级日本高清视频免费观看 | EEUSS影院WWW在线观看免费| 午夜亚洲AV日韩AV无码大全| 成人无码区免费视频观看| 色多多A级毛片免费看| 亚洲成在人线av| 四虎在线免费播放| 100000免费啪啪18免进| 一级特黄a免费大片| 亚洲国产AV一区二区三区四区| 亚洲综合色婷婷七月丁香| 久久久久久免费视频| 亚欧洲精品在线视频免费观看 | 免费av欧美国产在钱| 18女人腿打开无遮掩免费| 男人和女人高潮免费网站| 亚洲欧美日韩久久精品| 亚洲成色999久久网站| 国产亚洲综合网曝门系列| 免费看美女被靠到爽| 日本一道本不卡免费 | 日韩版码免费福利视频| 精品熟女少妇a∨免费久久| 麻豆一区二区三区蜜桃免费| 亚洲无限乱码一二三四区| 国产亚洲色婷婷久久99精品91| 在线观看AV片永久免费| 国产精品网站在线观看免费传媒| 一区视频免费观看| 一级毛片高清免费播放| 国产精品hd免费观看| 黄 色一级 成 人网站免费| 亚洲AV无码AV吞精久久| 亚洲综合一区二区| 久久亚洲精品中文字幕三区| 亚洲AV一宅男色影视| 亚洲日韩国产一区二区三区|