使用apache camel调用第三方Web服务

时间:2013-12-29 10:38:27

标签: java web-services apache-camel

我是骆驼新手

我正在尝试使用camel java dsl

调用webservice
from("cxf://http://darshan:8080/sampleWebService/SampleTestServicePort?wsdlURL=http://darshan:8080/sampleWebService/SampleTestServicePort?wsdl&serviceName={http://ws.test.com/}SampleTestServiceService&portName={http://ws.test.com/}SampleTestServicePort&dataFormat=MESSAGE")

以下是我的wsdl文件:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.test.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.test.com/" name="SampleTestServiceService">
    <types>
        <xsd:schema>
            <xsd:import namespace="http://ws.test.com/" schemaLocation="http://darshan:808O/sampleWebService/SampleTestServicePort?xsd=1"></xsd:import>
    </xsd:schema>
    </types>
    <message name="sayHello">
        <part name="parameters" element="tns:sayHello"></part>
    </message>
    <message name="sayHelloResponse">
        <part name="parameters" element="tns:sayHelloResponse"></part>
    </message>
    <portType name="SampleTestServiceDelegate">
        <operation name="sayHello">
            <input message="tns:sayHello"></input>
            <output message="tns:sayHelloResponse"></output>
        </operation>
    </portType>
    <binding name="SampleTestServicePortBinding" type="tns:SampleTestServiceDelegate">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
        <operation name="sayHello">
            <soap:operation soapAction=""></soap:operation>
            <input>
                <soap:body use="literal"></soap:body>
            </input>
            <output>
                <soap:body use="literal"></soap:body>
            </output>
        </operation>
    </binding>
    <service name="SampleTestServiceService">
        <port name="SampleTestServicePort" binding="tns:SampleTestServicePortBinding">
            <soap:address location="http://darshan:808O/sampleWebService/SampleTestServicePort"></soap:address>
        </port>
    </service>
</definitions>

这没有错误,但输出也没有。

请告诉我我的代码有什么问题。

提前致谢

2 个答案:

答案 0 :(得分:0)

当您使用Apache CXF组件作为from()时,您正在托管Web服务而不是访问第三方服务。

要访问第三方服务,您需要使用组件的to()形式。你需要做这样的事情:

<route>
  <from uri="file:./myFileRequest?delay=1000&amp;include=myRequest.xml">
  <to uri="cxf://http://darshan:8080/sampleWebService/SampleTestServicePort?wsdlURL=http://darshan:8080/sampleWebService/SampleTestServicePort?wsdl&serviceName={http://ws.test.com/}SampleTestServiceService&portName={http://ws.test.com/}SampleTestServicePort&dataFormat=MESSAGE" />
  ...
</route>

这是你在找什么?

答案 1 :(得分:0)

在驼峰上下文中定义cxf bean,如下所示

<cxf:cxfEndpoint
    address="Service ENDPOINT"
    endpointName="give wsdl:port@name here from wsdl"
    id="any id" loggingFeatureEnabled="true"
    serviceClass="your service class - it will be inside the stubs generated from WSDL"
    serviceName="Service Name"
    wsdlURL="WSDL path" xmlns:ws="namespace">
    <cxf:properties>
        <entry key="dataFormat" value="PAYLOAD"/>
    </cxf:properties>
</cxf:cxfEndpoint>

然后在你的路线中写下以下内容:

<to id="_to1" uri="cxf:bean:id Of the cxfEndpoint bean"/>