Java 使用ApacheCamel调用第三方web服务

Java 使用ApacheCamel调用第三方web服务,java,web-services,apache-camel,Java,Web Services,Apache Camel,我不熟悉骆驼 我正在尝试使用camel-javadsl调用webservice from("cxf://http://darshan:8080/sampleWebService/SampleTestServicePort?wsdlURL=http://darshan:8080/sampleWebService/SampleTestServicePort?wsdl&serviceName={http://ws.test.com/}SampleTestServiceService&p

我不熟悉骆驼

我正在尝试使用camel-javadsl调用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>

这不会产生错误,但输出也不算什么

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


当您将Apache CXF组件用作
from()
时,请提前感谢

,您所做的是托管Web服务,而不是访问第三方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>

...

这就是您想要的吗?

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


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



我想知道第二个
&
(这里:
SampleTestServicePort?wsdl
)是否需要转义?我们应该如何判断,没有代码的代码有什么问题?感谢您的回复我没有问题&我使用了以下文章作为参考[链接]()。感谢herry格式化我的posthveiga。感谢您的回复,但远程方法中没有参数可用。请让我知道文件myRequest.xml的内容&什么是myFileRequest??这取决于第三方服务的工作方式。您需要以预期的格式发送请求,或者使用SOAPAction。如果您使用的是请求,则文件应该是这样的。