我想我需要这样的东西:http://camel.apache.org/cxf-tomcat-example.html
我有一个带有 jax-ws 注释的 Web 服务类,我想使用此类来处理请求并生成响应,而不是使用自定义处理器。
像这样:from(cxf ws endpoit).to(my webservice implementation)
这可能吗?我可以将消息路由到正确的 Java 方法吗?
这与我使用 cxf
和 jax-ws
所做的完全相同,但我也想使用 camel。
我想使用代码优先方法(生成的 WSDL)。
最佳答案
Can I route my messages to the correct java method?
如果你指的是你手动创建的bean的具体方法,那么是的。
例如:
创建自定义 bean:
public class CustomProcessor {
public void processSomething(Exchange exchange) {
Something smth = exchange.getIn().getBody(Something.class); //Your message's body
}
}
使用 Spring
创建一个像这样的 Camel 配置:
<bean id="processor" class="your.custom.CustomProcessor"/>
<camel:camelContext trace="true" id="camelContext" >
<camel:route id="camelRoute">
<camel:from uri="cxf:bean:yourWebServiceListenerEndpoint?dataFormat=POJO&synchronous=true" />
<camel:choice>
<camel:when>
<camel:simple>${headers.operationName} == 'DoSomething'</camel:simple>
<camel:bean ref="processor" method="processSomething"/>
</camel:when>
</camel:choice>
<camel:to uri="cxf:bean:yourWebServiceTargetEndpoint"/>
</camel:route>
</camel:camelContext>
根据操作名称,camel 会将消息路由到相应的处理器。您可以按照自己喜欢的方式在 Camel 中发送消息。你只需要想想如何。从你的问题来看,这是我所能提供的。如果您将其更新为更具体,也许我可以提供更多帮助。
另请参阅:
关于tomcat - 将 Camel 与 tomcat、cxf 和 jax-ws/rs 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13612403/