Apache camel 使用截距的骆驼试验
我正试图截获一条消息,以跳过Http请求并继续我的路由。 下面是您可以复制/粘贴以试用的类 使用camel测试、camel core、camel-http4 2.10.2和httpclient osgi、httpcore osgi 4.2.2 代码如下:Apache camel 使用截距的骆驼试验,apache-camel,Apache Camel,我正试图截获一条消息,以跳过Http请求并继续我的路由。 下面是您可以复制/粘贴以试用的类 使用camel测试、camel core、camel-http4 2.10.2和httpclient osgi、httpcore osgi 4.2.2 代码如下: import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.AdviceWithRouteBuilde
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
/**
* Created with IntelliJ IDEA.
* User: lleclerc
* Date: 12-11-28
* Time: 16:34
* To change this template use File | Settings | File Templates.
*/
public class IsUseAdviceWithJUnit4Test extends CamelTestSupport {
private String providerEndPointURI = "http://stackoverflow.com";
private String timerEndPointURI = "timer://myTimer";
private String mockEndPointURI = "mock:myMock";
private String directEndPointURI = "direct:myDirect";
private boolean messageIntercepted;
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from(timerEndPointURI + "?fixedRate=true&delay=1000&period=1000")
.to(providerEndPointURI + "?throwExceptionOnFailure=false")
.to(mockEndPointURI);
}
};
}
@Test
public void testIsUseAdviceWith() throws Exception {
messageIntercepted = false;
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith(directEndPointURI);
mockEndpoints();
interceptSendToEndpoint(providerEndPointURI)
.skipSendToOriginalEndpoint()
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
messageIntercepted = true;
System.out.println("INTERCEPTED");
}
});
}
});
// we must manually start when we are done with all the advice with
context.start();
getMockEndpoint(mockEndPointURI).expectedMessageCount(1);
template.sendBody(directEndPointURI, "a trigger");
assertMockEndpointsSatisfied();
assertEquals(true, messageIntercepted);
assertNotNull(context.hasEndpoint(directEndPointURI));
assertNotNull(context.hasEndpoint("mock:" + directEndPointURI));
assertNotNull(context.hasEndpoint(mockEndPointURI));
}
@Override
public boolean isUseAdviceWith() {
return true;
}
@Override
public boolean isUseRouteBuilder() {
return true;
}
}
谢谢你的帮助 camel-http4内部存在缺陷
这与使用“http4”有关…将其更改为“http”,效果很好…还不确定为什么会出现这种情况,尽管我更新了测试,在消息未被截获时失败,您能再试一次吗,http或http4都不起作用…:(