繁体   English   中英

使用apache骆驼调用第三方Web服务

[英]call third party web service using apache camel

我是骆驼的新手

我正在尝试使用骆驼Java DSL调用Web服务

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>

那没有错误,但是输出什么也没有。

请建议我代码中的错误。

提前致谢

当您将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>

这是你想要的?

在骆驼上下文中,如下定义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"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM