You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Willem jiang <wi...@gmail.com> on 2012/12/03 09:54:51 UTC

Re: Test Intercept with adviceWith and http

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).




Re: Test Intercept with adviceWith and http

Posted by Willem jiang <wi...@gmail.com>.
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).




Re: Test Intercept with adviceWith and http

Posted by lleclerc <ll...@aim-rg.com>.
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.

Re: Test Intercept with adviceWith and http

Posted by lleclerc <ll...@aim-rg.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>



--
View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473p5724050.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Test Intercept with adviceWith and http

Posted by Willem jiang <wi...@gmail.com>.
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).




Re: Test Intercept with adviceWith and http

Posted by lleclerc <ll...@aim-rg.com>.
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.

Re: Test Intercept with adviceWith and http

Posted by Willem jiang <wi...@gmail.com>.
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).




Re: Test Intercept with adviceWith and http

Posted by lleclerc <ll...@aim-rg.com>.
*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.

Re: Test Intercept with adviceWith and http

Posted by lleclerc <ll...@aim-rg.com>.
Found the problem, might be a bug, will be posting the solution in the next
hour.



--
View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473p5723732.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Test Intercept with adviceWith and http

Posted by lleclerc <ll...@aim-rg.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.



--
View this message in context: http://camel.465427.n5.nabble.com/Test-Intercept-with-adviceWith-and-http-tp5723473p5723616.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Test Intercept with adviceWith and http

Posted by Willem jiang <wi...@gmail.com>.
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).




Re: Test Intercept with adviceWith and http

Posted by lleclerc <ll...@aim-rg.com>.
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.

Re: Test Intercept with adviceWith and http

Posted by Willem jiang <wi...@gmail.com>.
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).




Re: Test Intercept with adviceWith and http

Posted by lleclerc <ll...@aim-rg.com>.
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.