apachecamel调用SOAP服务
我是Apache Camel的新手,我使用的是Red Hat CodeReady Studio 12.16.0.GA。 我想调用soapweb服务。 我用过这个例子 这是我的camel上下文文件apachecamel调用SOAP服务,soap,apache-camel,redhat,Soap,Apache Camel,Redhat,我是Apache Camel的新手,我使用的是Red Hat CodeReady Studio 12.16.0.GA。 我想调用soapweb服务。 我用过这个例子 这是我的camel上下文文件 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel-cxf="http://camel.apache.org/schema/cxf" xmlns:xsi
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel-cxf="http://camel.apache.org/schema/cxf"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring https://camel.apache.org/schema/spring/camel-spring.xsd http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<bean class="org.apache.cxf.transport.common.gzip.GZIPInInterceptor" id="gZipInInterceptor"/>
<bean
class="org.apache.cxf.transport.common.gzip.GZIPOutInterceptor" id="gZipOutInterceptor"/>
<camel-cxf:cxfEndpoint
address="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso"
id="fullCountryInfoResponseClient" serviceClass="org.oorsprong.websamples_countryinfo.CountryInfoServiceSoapType">
<camel-cxf:inInterceptors>
<ref bean="gZipInInterceptor"/>
</camel-cxf:inInterceptors>
<camel-cxf:outInterceptors>
<ref bean="gZipOutInterceptor"/>
</camel-cxf:outInterceptors>
</camel-cxf:cxfEndpoint>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="bean-66d2672d-c6c0-4984-bc31-90bc30bfaaef"/>
<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring" xmlns:order="http://fabric8.com/examples/order/v7">
<route id="simple-route">
<from id="_to2" uri="timer:timerName?delay=0&repeatCount=1"/>
<setBody id="_setBody2">
<constant id="id">"US"</constant>
</setBody>
<bean beanType="GetFullCountryInfoBuilder.class" id="_bean1" method="getFullCountryInfo"/>
<setHeader headerName="operationNamespace" id="_setHeader1">
<constant>http://www.oorsprong.org/websamples.countryinfo</constant>
</setHeader>
<setHeader headerName="operationName" id="_setHeader2">
<constant>FullCountryInfo</constant>
</setHeader>
<to id="_to1" uri="cxf:bean:fullCountryInfoResponseClient"/>
<setBody id="_setBody1">
<simple>${body}</simple>
</setBody>
<log id="_log1" message=">>>${body}"/>
</route>
</camelContext>
</beans>
它周围有很多问题。首先,我不能将输入参数传递到body中。
我试着把身体摆成这样
<web:FullCountryInfo xmlns:web="http://www.oorsprong.org/websamples.countryinfo">
<web:sCountryISOCode>US</web:sCountryISOCode>
</web:FullCountryInfo>
org.oorsprong.websamples.GetFullCountryInfoBuilder // i guessed the package name
当我用常量替换占位符时
InvocationTargetException: Error creating bean with name 'getFullCountryInfo' defined in class path resource [com/example/GetFullCountryInfoBuilder.class]: Unsatisfied dependency expressed through method 'getFullCountryInfo' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
或者,当我从方法getFullCountryInfo中删除输入参数时,Camel找不到GetFullCountryInfoBuilder类
InvocationTargetException: org.apache.camel.FailedToCreateRouteException: Failed to create route simple-route at: >>> Bean[GetFullCountryInfoBuilder.class] <<< in route: Route(simple-route)[[From[timer:timerName?delay=0&repeatCoun... because of java.lang.ClassNotFoundException: GetFullCountryInfoBuilder.class
InvocationTargetException:org.apache.camel.FailedToCreateRouteException:Bean[GetFullCountryInfoBuilder.class]创建路由简单路由失败,前两个错误出现在将参数传递给Bean方法的字段中
Could not resolve placeholder 'id' in value "${id}"
表达式@Value(“${id}”)
引用了名为id
的Spring属性,但它不存在。由于您使用此ID定义了一个路由步骤,我怀疑您希望将设置为消息体的值“US”传递给该方法
不知道您的骆驼路线,所以这不起作用
但是,您可以使用通知Camel将设置为“US”的消息体作为参数id
插入方法中
getFullCountryInfo(@Body String id) {
您还可以使用setHeader
将值设置到消息头中,并使用注释@header
将其注入到方法中。因为当你有一个输入消息(不是计时器)时,你通常不想覆盖正文
另一个问题是,即使删除参数并将主体设置为静态,bean也无法解决
ClassNotFoundException: GetFullCountryInfoBuilder.class
我想这是因为beanType
应该这样定义
<web:FullCountryInfo xmlns:web="http://www.oorsprong.org/websamples.countryinfo">
<web:sCountryISOCode>US</web:sCountryISOCode>
</web:FullCountryInfo>
org.oorsprong.websamples.GetFullCountryInfoBuilder // i guessed the package name
所以它必须是完整的包/类名,但没有“.class”后缀。谢谢。这很有帮助。现在豆子的所有问题都消失了。但将响应转换为字符串时出现问题,因为传递失败(ExchangeId:ID-1599152842117-0-1上的MessageId:ID-1599152842117-0-2)。交付尝试后耗尽:1捕获:org.apache.cxf.interceptor.Fault:org.oorsprong.websamples.FullCountryInfo无法转换为java.lang.String您是否尝试将响应转换为字符串?可能是因为您执行了类似于String response=myFullCountryInfo//object的操作,myFullCountryInfo无法转换为String
Yes,我已经尝试过了。在cxf:bean:fullCountryInfoResponseClient之后,我将使用方法@bean公共字符串getFullCountryInfoOutput(@Body FullCountryInfoResponse response)的
放入{String ret=response.getFullCountryInfoResult().getSName()+“+”+response.getFullCountryInfoResult().getSCapitalCity()+“-”+response.getFullCountryInfoResult().getSCurrencyISOCode();return ret;}
但请求对象FullCountryInfo似乎被强制转换为字符串。我不知道为什么或者在哪里。看起来CXF不处理FullCountryInfo对象,但String和Camel尝试将其转换。当我将getFullCountryInfo的返回值更改为字符串时,此异常将消失。