使用驼峰路由的Apache Camel SOAP请求

时间:2018-03-11 06:46:47

标签: java maven apache-camel camel-cxf

我想使用apache camel routing发出SOAP请求。我试过cxf,http4,netty4-http。什么都行不通。我想要像

这样的东西
    from("direct:start")
   .to(myEndpoint)//should make soap call
   .process(new Processor(){
    public void process(Exchange e){
    Log.debug(exchange.getIn().getBody().toString());//Should print returned value
}
}) 

我尝试过的内容包括

<camelContext xmlns="http://camel.apache.org/schema/spring">
                    <route id="wsClient">
                                <from uri="direct:start" />
                                <to
                                    uri="cxf:bean:productServiceEndpoint" />
                            </route>
                        </camelContext>
                        <cxf:cxfEndpoint id="productServiceEndpoint"
                                address="http://www.webservicex.com/country.asmx" wsdlURL="http://www.webservicex.com/country.asmx?wsdl"  />

这表示需要serviceClass。我不明白我正在消耗它。为什么我需要服务类?

下一步:

from("direct:start")
.process(new Processor() {

                        @Override
                        public void process(Exchange exchange) throws Exception {
                            // TODO Auto-generated method stub

                            exchange.getOut().setBody(
                                    "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:web=\"http://www.webserviceX.NET\">   <soap:Header/>   <soap:Body>      <web:GetCountries/>   </soap:Body></soap:Envelope>");

                        }

                    })
.to("http4://www.webservicex.com/country.asmx")
.process(new Processor(){

            @Override
            public void process(Exchange exchange) throws Exception {
                // TODO Auto-generated method stub
                System.out.println(""+exchange.getExchangeId());
                System.out.println(""+exchange.getIn().getBody());
                System.out.println(""+exchange.getIn().getBody());

            }


            })

这和netty4-http不会生成任何内容。

1 个答案:

答案 0 :(得分:0)

检查您的代码,以便您写入IN交换而不是OUT交换。 从(“直接:启动”) .process(new Processor(){

                @Override
                public void process(Exchange exchange) throws Exception {
                    // TODO Auto-generated method stub

                    **exchange.getIn()**.setBody(
                            "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:web=\"http://www.webserviceX.NET\">   <soap:Header/>   <soap:Body>      <web:GetCountries/>   </soap:Body></soap:Envelope>");