我尝试在spring.xml文件中使用Apache Camel Interceptor来捕获传入请求和传出响应,如下所示:
<bean id="InterceptProcessor" class="CaptureProcessor"/>
<camel:camelContext id="camel">
<camel:jmxAgent id="agent" disabled="true" />
<camel:intercept>
<camel:process ref="InterceptProcessor"></camel:process>
</camel:intercept>
<camel:route id="Resource.rConnect.rconnect" autoStartup="false">
<camel:from
uri="cxfjetty:${Resource.rConnect.rconnect.baseUrl}?urlTemplateRef=#URLTemplateRef.Resource.rConnect.rconnect&
convertAttachments=true" />
<camel:to
uri="sonicesb://Process/rConnect?bindingStrategy=#ExposeBindingStrategy.Resource.rConnect.rconnect&headerFilterStrategy=#ExposeHeaderFilterStrategy.Resource.rConnect.rconnect&esbConfig=#ExposeEsbConfig.Resource.rConnect.rconnect" />
</camel:route>
<camel:route autoStartup="false">
<camel:from
uri="directsonicesb:Resource.rConnect.rconnect?bindingStrategy=#InvokeBindingStrategy.Resource.rConnect.rconnect&headerFilterStrategy=#InvokeHeaderFilterStrategy.Resource.rConnect.rconnect&uriTemplate=#URITemplate.Resource.rConnect.rconnect" />
<camel:to uri="sonicesb://Process/rConnect" />
</camel:route>
</camel:camelContext>下面是this的文章。
但是"CaptureProcessor“在输入周期中只被调用一次。
我怎样才能让它也捕获输出呢?
发布于 2014-05-09 22:12:11
根据Camel doc的说法,这在intercept中是不可能的
发生的情况是,交换在每个处理步骤之前被截获,这意味着它将在
因此,不可能在每个步骤之后截取处理。然而,对于这个需求,有一个开放的Jira票证:CAMEL-6901
或者,您可以使用类似于完成后回调的onCompletion,该回调可以为每个路由定义,也可以为整个驼峰上下文全局定义:
<onCompletion>
<log message="${body}" />
</onCompletion>有关这种可能性的更多信息,请参阅Camel docs。
发布于 2014-05-15 08:12:44
我找到了一种更适合我的方法。
在我的原始问题中使用截取,然后在process类中使用:使用同步并添加onCompletion处理器。
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class CaptureProcessor implements Processor, Synchronization
{
@Override
public void process(Exchange exch) throws Exception
{
if (exch.hasOut())
{
// you won't get here
} else
{
// ==== Add the onCompletion interceptor ====
exch.addOnCompletion(this);
// do in processing
....
}
}
@Override
public void onComplete(Exchange exch)
{
if (exch.hasOut())
{
// do the out procesing
....
} else
{
// you won't get here
}
}
@Override
public void onFailure(Exchange exch)
{
// you get the idea by now
}
}并且入站截取和出站截取各只调用一次。
发布于 2014-05-13 12:35:12
谢谢彼得。
这就起到了作用。
不过,也有一些有趣的结果
我尝试将intercept和onCompletion条目移动到不同的位置,但总是得到相同的结果。我的解决方案是在第一个入站调用中添加一个特定的标头,如果标头已经存在,则绕过对其他调用的处理。
向Steve致敬
https://stackoverflow.com/questions/23555899
复制相似问题