简体   繁体   English

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

[英]call third party web service using apache camel

I am new to camel 我是骆驼的新手

I am trying to call webservice using camel java dsl 我正在尝试使用骆驼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")

following is my wsdl file: 以下是我的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>

That gives no error but also output is nothing. 那没有错误,但是输出什么也没有。

Please suggest me what is wrong in my code. 请建议我代码中的错误。

Thanks in advance 提前致谢

When you use the Apache CXF Component as a from() what you are doing is you are hosting the webservice instead of accessing a third-party one. 当您将Apache CXF组件用作from() ,您正在做的是托管Web服务,而不是访问第三方服务。

To access a third-party service you need to use the to() form of the component. 要访问第三方服务,您需要使用组件的to()形式。 You need to do something like this: 您需要执行以下操作:

<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>

Is this what you are looking for? 这是你想要的?

Define the cxf bean as below in the camel context 在骆驼上下文中,如下定义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>

then write the following in your route: 然后在您的路线中输入以下内容:

<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