如何将SOAP请求传递给Camel CXF

时间:2014-07-18 05:04:09

标签: apache-camel

我有一个要求“在使用camel进行路由时,我必须调用Web服务”。但我对将SOAP xml设置到交换机感到震惊。有人可以帮我弄这个吗。请看一下我的代码

public static void main(String[] args) throws Exception {
        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("file:input?noop=true")
                        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange) throws Exception {
                                //Setting a String to the exchange body
                                exchange.getIn().setBody("Just a String");
                                //Now i want to set a SOAP xml to the exchange body
                                //exchange.getIn().setBody();
                                System.out.println("Ravi "+ exchange.getIn().getBody(String.class));
                            }
                        })
                        .to("cxf://http://www.webservicex.net/stockquote.asmx?wsdlURL=src/main/resources/META-INF/stockquote.wsdl&serviceName={http://www.webserviceX.NET/}StockQuote&portName={http://www.webserviceX.NET/}StockQuoteSoap&dataFormat=MESSAGE")
                        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange) throws Exception {
                                System.out.println("Raju" + exchange);
                            }
                        }).to("file:data/destination?fileName=test2.xml");
            }
        });
        context.start();
        Thread.sleep(20000);
        context.stop();
    }

1 个答案:

答案 0 :(得分:0)

不确定我是否正确理解,但请举例说明(在春季dsl中)以防万一。

  1. 使用PAYLOAD模式设置端点:

    <cxf:cxfEndpoint id="myEndpoint" ... >
        <cxf:properties>
            <entry key="dataFormat" value="PAYLOAD"/>
        </cxf:properties>
    </cxf:cxfEndpoint>
    
  2. 然后在你的路线中:

    <from uri="direct:webservicecall"/>
    <to uri="language:constant:classpath:FileContainingBody.xml"/>
    <to uri="cxf:bean:myEndpoint?defaultOperationName=MyMethod"/>
    
  3. 这里的要点是使用&#34;语言&#34;正如Petter建议的那样,先前已将您的端点配置为PAYLOAD模式,以加载请求正文的组件。