Apache Camel 调用 SOAP 服务
Apache Camel invoke SOAP service
我是 Apache Camel 的新手,我使用的是 Red Hat CodeReady Studio 12.16。0.GA。
我想调用 soap web 服务。
我用过这个例子https://tomd.xyz/camel-consume-soap-service/
这是我的骆驼上下文文件
<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>
这是我的输入 bean
import org.oorsprong.websamples.FullCountryInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Component
public class GetFullCountryInfoBuilder {
public GetFullCountryInfoBuilder() {}
@Value("${id}")
private java.lang.String id;
@Bean
public FullCountryInfo getFullCountryInfo(java.lang.String id) {
FullCountryInfo request = new FullCountryInfo();
request.setSCountryISOCode(id);
return request;
}
}
周围有很多问题。首先,我无法将输入参数传递给正文。
我试过这样设置 body
<web:FullCountryInfo xmlns:web="http://www.oorsprong.org/websamples.countryinfo">
<web:sCountryISOCode>US</web:sCountryISOCode>
</web:FullCountryInfo>
但没有收到任何回复或什么也没记录。
我尝试使用 bean 来创建请求,但我得到
InvocationTargetException: Error creating bean with name 'getFullCountryInfoBuilder': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'id' in value "${id}"
当我用常量替换占位符时
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 class
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
前两个错误出现在将参数传递给 bean 方法的字段中。
Could not resolve placeholder 'id' in value "${id}"
表达式 @Value("${id}")
引用了一个名为 id
的 Spring 属性,但它不存在。由于您使用此 ID 定义了一个路由步骤,我怀疑您想将设置为消息 body 的值“US”传递给该方法。
Spring annotation @Value
不知道你的骆驼路线所以这行不通。
然而,您可以使用 Camel annotations 告诉 Camel 注入消息 body 您设置为“US”作为方法中的参数 id
。
getFullCountryInfo(@Body String id) {
您还可以使用 setHeader
将值设置到消息 header 中,并使用注释 @Header
将其注入到方法中。因为当您有输入消息(不是计时器)时,您通常不想覆盖 body.
另一个问题是无法解析 bean,即使您删除参数并将 body 设置为静态也是如此。
ClassNotFoundException: GetFullCountryInfoBuilder.class
我想这是因为 beanType
应该这样定义
org.oorsprong.websamples.GetFullCountryInfoBuilder // i guessed the package name
所以它必须是完整的 package/classname 但没有“.class”后缀。
我是 Apache Camel 的新手,我使用的是 Red Hat CodeReady Studio 12.16。0.GA。 我想调用 soap web 服务。 我用过这个例子https://tomd.xyz/camel-consume-soap-service/
这是我的骆驼上下文文件
<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>
这是我的输入 bean
import org.oorsprong.websamples.FullCountryInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Component
public class GetFullCountryInfoBuilder {
public GetFullCountryInfoBuilder() {}
@Value("${id}")
private java.lang.String id;
@Bean
public FullCountryInfo getFullCountryInfo(java.lang.String id) {
FullCountryInfo request = new FullCountryInfo();
request.setSCountryISOCode(id);
return request;
}
}
周围有很多问题。首先,我无法将输入参数传递给正文。 我试过这样设置 body
<web:FullCountryInfo xmlns:web="http://www.oorsprong.org/websamples.countryinfo">
<web:sCountryISOCode>US</web:sCountryISOCode>
</web:FullCountryInfo>
但没有收到任何回复或什么也没记录。 我尝试使用 bean 来创建请求,但我得到
InvocationTargetException: Error creating bean with name 'getFullCountryInfoBuilder': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'id' in value "${id}"
当我用常量替换占位符时
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 class
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
前两个错误出现在将参数传递给 bean 方法的字段中。
Could not resolve placeholder 'id' in value "${id}"
表达式 @Value("${id}")
引用了一个名为 id
的 Spring 属性,但它不存在。由于您使用此 ID 定义了一个路由步骤,我怀疑您想将设置为消息 body 的值“US”传递给该方法。
Spring annotation @Value
不知道你的骆驼路线所以这行不通。
然而,您可以使用 Camel annotations 告诉 Camel 注入消息 body 您设置为“US”作为方法中的参数 id
。
getFullCountryInfo(@Body String id) {
您还可以使用 setHeader
将值设置到消息 header 中,并使用注释 @Header
将其注入到方法中。因为当您有输入消息(不是计时器)时,您通常不想覆盖 body.
另一个问题是无法解析 bean,即使您删除参数并将 body 设置为静态也是如此。
ClassNotFoundException: GetFullCountryInfoBuilder.class
我想这是因为 beanType
应该这样定义
org.oorsprong.websamples.GetFullCountryInfoBuilder // i guessed the package name
所以它必须是完整的 package/classname 但没有“.class”后缀。