gpt4 book ai didi

web-services - 如何使用 cxf 组件使用 Apache camel 调用第三方 Web 服务

转载 作者:行者123 更新时间:2023-12-04 04:39:03 29 4
gpt4 key购买 nike

我浏览了 Apache camel 网站上的示例和camel in action,两者都非常关注暴露网络服务。我在网上找到的唯一示例不起作用。

我正在尝试访问第三方网络服务 wsdl - http://www.webservicex.net/CurrencyConvertor.asmx?WSDL

此服务具有计算货币汇率的操作/方法。操作名称是“ConversionRate”。

我定义了这样的路线 -

      <?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">


<camelContext xmlns="http://camel.apache.org/schema/spring">

<route>
<description>here is a sample which processes the input files
(leaving them in place - see the 'noop' flag)
then performs content based routing on the message using XPath</description>
<from uri="file:src/data/order?noop=true"/>
<log message="${body}"/>

<to uri="cxf://http://www.webservicex.net/CurrencyConvertor.asmx?wsdlURL=http://www.webservicex.net/CurrencyConvertor.asmx?wsdl&amp;serviceName=CurrencyConvertor&amp;portName=http://www.webserviceX.NET/tns:CurrencyConvertorSoap&amp;dataFormat=MESSAGE"/>
<log message="${body}"/>
</route>
</camelContext>

</beans>

我已将示例有效负载 xml 定义为 -
<order>
<Id>1</Id>
<Price>10.00</Price>
<Quantity>2</Quantity>
</order>

运行此示例时出现此错误。
   Error occurred while running main from: org.apache.camel.spring.Main
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.camel.maven.RunMojo$1.run(RunMojo.java:440)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[cxf://http://www.webservicex.net/CurrencyConvertor.asmx?dataFormat=MESSAGE&portName=http%3A%2F%2Fwww.webserviceX.NET%2Ftns%3ACurrencyConvertorSoap&serviceName=CurrencyConvertor&wsdlURL=http%3A%2F%2Fwww.webservicex.net%2FCurrencyConvertor.asmx%3Fwsdl]. Reason: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service CurrencyConvertor.
at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:395)
at org.apache.camel.impl.ProducerCache.acquireProducer(ProducerCache.java:114)
at org.apache.camel.impl.ProducerCache.startProducer(ProducerCache.java:145)
at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:175)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
at org.apache.camel.processor.interceptor.TraceInterceptor.doStart(TraceInterceptor.java:358)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.processor.WrapProcessor.doStart(WrapProcessor.java:52)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
at org.apache.camel.processor.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1064)
at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:41)
at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:28)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
at org.apache.camel.processor.interceptor.DefaultChannel.doStart(DefaultChannel.java:153)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:85)
at org.apache.camel.processor.MulticastProcessor.doStart(MulticastProcessor.java:938)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
at org.apache.camel.processor.UnitOfWorkProcessor.doStart(UnitOfWorkProcessor.java:88)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:78)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.impl.RouteService.startChildService(RouteService.java:322)
at org.apache.camel.impl.RouteService.warmUp(RouteService.java:151)
at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:2000)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:1928)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1716)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1597)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1453)
at org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:179)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1421)
at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:228)
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:118)
at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:283)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:327)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:941)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:475)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:186)
at org.apache.camel.spring.Main.doStart(Main.java:140)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.main.MainSupport.run(MainSupport.java:141)
at org.apache.camel.main.MainSupport.run(MainSupport.java:332)
at org.apache.camel.spring.Main.main(Main.java:73)
... 6 more
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service CurrencyConvertor.
at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:139)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:412)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:534)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:248)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:90)
at org.apache.camel.component.cxf.CxfEndpoint.createClient(CxfEndpoint.java:527)
at org.apache.camel.component.cxf.CxfProducer.doStart(CxfProducer.java:76)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:393)
... 88 more
*************************************.

最佳答案

根据 CXF,目标 URI 似乎不正确文档。
serviceName 的格式和 portName应该是 {namespace}name
尝试:

  • 服务名称={ http://www.webserviceX.NET/ }货币转换器
  • 端口名称={ http://www.webserviceX.NET/ }CurrencyConvertorSoap
  • 关于web-services - 如何使用 cxf 组件使用 Apache camel 调用第三方 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20585877/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com