|
This post was updated on .
Hi,
This time I tried using http instead of http4. Both http and http4 gives different errors. The intercept is not working, even with isUseAdviceWith() to return true. What is going on ? using camel 2.10.2, and http 4.2.2. Thank you in advance, 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; public class IsUseAdviceWithJUnit4Test extends CamelTestSupport { private String providerEndPointURI = "http4:stackoverflow.com?throwExceptionOnFailure=false"; private String timerEndPointURI = "timer:myTimer?fixedRate=true&delay=1000&period=1000"; 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) .to(providerEndPointURI) .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(mockEndPointURI)); } @Override public boolean isUseAdviceWith() { return true; } @Override public boolean isUseRouteBuilder() { return true; } } |
|
Hi,
I tried to run the test with the trunk code, the tests are passed without any issue. What's the issue that you meet? If you want to interceptSendToEndpoint, you need to make sure the uri string that you passed should be same with the endpoint. -- Willem Jiang Red Hat, Inc. FuseSource is now part of Red Hat Web: http://www.fusesource.com | http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: willemjiang On Saturday, December 1, 2012 at 4:11 AM, lleclerc wrote: > Hi, > > This time I tried using http instead of http4. > No exception, but the intercept is not working, even with isUseAdviceWith() > to return true. > > What is going on ? > > using camel 2.10.2, and http 4.2.2. > > Thank you in advance, > > 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"; > > @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 { > > context.getRouteDefinitions().get(0).adviceWith(context, new > AdviceWithRouteBuilder() { > @Override > public void configure() throws Exception { > > replaceFromWith(directEndPointURI); > > mockEndpoints(); > > interceptSendToEndpoint(providerEndPointURI) > .process(new Processor() { > @Override > public void process(Exchange exchange) throws > Exception { > System.out.println("INTERCEPTED"); > } > }) > .skipSendToOriginalEndpoint(); > } > }); > > // 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(); > > 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; > } > } > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473.html > Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com). |
|
This post was updated on .
The message "INTERCEPTED" is never printed and the request is not intercepted, nor skipped, it is still sent over internet and we see the content of "http://stackoverflow.com" through [httpclient.wire.content] messages.
Edit: And I am using global string to make sure there is no error in the URI name Edit2: I updated the code in the first post so the test fails when the message is not intercepted, can you try it again ? |
|
In reply to this post by lleclerc
Adding a symbolic reward of 2$ through paypal !!!!
|
|
In reply to this post by lleclerc
You need to comment out the mockEndpoints() and specify the full URI of the http endpoint like this. mockEndpoints will mock all endpoints in the route.
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { public void configure() throws Exception { replaceFromWith(directEndPointURI); //mockEndpoints(); interceptSendToEndpoint(providerEndPointURI + "?throwExceptionOnFailure=false").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { System.out.println("INTERCEPTED"); } }).skipSendToOriginalEndpoint(); } }); -- Willem Jiang Red Hat, Inc. FuseSource is now part of Red Hat Web: http://www.fusesource.com | http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: willemjiang On Monday, December 3, 2012 at 9:58 PM, lleclerc wrote: > The message "INTERCEPTED" is never printed and the request is not > intercepted, nor skipped, it is still sent over internet and we see the > content of "http://stackoverflow.com" through [httpclient.wire.content] > messages. > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473p5723544.html > Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com). |
|
I still get the same error.
I modified the code in the first post. I use the exact same String everywhere now. |
|
Did you remove the call of mockEndpoints();?
-- Willem Jiang Red Hat, Inc. FuseSource is now part of Red Hat Web: http://www.fusesource.com | http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: willemjiang On Tuesday, December 4, 2012 at 9:59 PM, lleclerc wrote: > I still get the same error. > > I modified the code in the first post. I use the exact same String > everywhere now. > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473p5723611.html > Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com). |
|
Yes, it's commented out, exactly as the code in the first post.
Can you get the test to success ? Maybe it is some other problem. |
|
This post was updated on .
Hi,
I think this is another bug. http://pastebin.com/LHeZ3zpj This test is returning true in isUseAdviceWith() and starts the context manually, but is not using the advice and not functionnal. http://pastebin.com/hU9rmqAB The exact same test that does not (@Override isUseAdviceWith() and manually start context) is in reality using the advice and is functionnal. Can you please confirm this is a bug ? or not ? Thanks, |
|
*edited last post! Think I found a bug!
|
|
Hi,
After digging the code which you shows to me, I found the cause of your issue. The http4 endpoint is created before the Http4Component is started, it is cause the NPE to make the test failed. It's not a bug of CamelTestSupport. I will commit a quick fix for it today. -- Willem Jiang Red Hat, Inc. FuseSource is now part of Red Hat Web: http://www.fusesource.com | http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Friday, December 7, 2012 at 6:01 AM, lleclerc wrote: > *edited last post! Think I found a bug! > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473p5723736.html > Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com). |
|
This post was updated on .
Hi Willem,
How is it going ? Fix release ? *Edit : Thanks for the great job ! |
|
I already committed a fix for it , you can find more information here[1]
Please verify with the latest camel snapshot. [1]https://issues.apache.org/jira/browse/CAMEL-5854 -- Willem Jiang Red Hat, Inc. FuseSource is now part of Red Hat Web: http://www.fusesource.com | http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Thursday, December 13, 2012 at 10:58 PM, lleclerc wrote: > Hi Willem, > > How is it going ? Fix release ? > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473p5724043.html > Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com). |
|
Thanks!
Updated my pom file with <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> <version>2.10.4-SNAPSHOT</version> </dependency> <repositories> <repository> <id>apache.snapshots</id> <name>Apache Development Snapshot Repository</name> <url>https://repository.apache.org/content/repositories/snapshots/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> |
|
This post was updated on .
The SNAPSHOT doesn't have source code. Am I missing a line somewhere in the pom.xml ?
Why is the source not added in this snapshot ? |
|
We don't deploy the source jar into the snapshot repository.
If you want to have one you can try to build the artifact yourself from the svn repository[1]. [1]http://camel.apache.org/source.html -- Willem Jiang Red Hat, Inc. FuseSource is now part of Red Hat Web: http://www.fusesource.com | http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Friday, December 14, 2012 at 3:58 AM, lleclerc wrote: > The SNAPSHOT doesn't have source code. Am I missing a line somewhere in the > pom.xml ? > Why is the source not added in those snapshots ? > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473p5724053.html > Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com). |
| Powered by Nabble | Edit this page |
