You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by John <Jo...@ateb.com> on 2010/12/12 07:07:52 UTC

interceptSendToEndpoint with dynamic endpoint

Hi,

I am using camel 2.2, though I did give this a shot with 2.5

I have a route that has an http endpoint that is configured at startup. In
my route builder I have something like:

String wsUrl = "http://host/ws";

from("activemq:somequeue")
    .bean("someBean")
    .to(wsUrl);

While trying to create a unit test for this route, I am adding an
interceptSendToEndpoint to direct any requests to the wsUrl endpoint to a
mock endpoint.

I am unable to get the interceptor to work as long as I have a variable in
the original route endpoint. If I replace .to(wsUrl) with
.to("http://host/ws") everything works fine in my test. The documentation
mentions that interceptSendToEndpoint should be fine with a dynamic URI.

Is there a way to use the interceptor in my test without a hard coded string
in the route endpoint?

Thanks,

-john

-- 
View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3301978.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: interceptSendToEndpoint with dynamic endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
Then just use * in the intercept

interceptSendToEndpoint("aws-sqs://myQueue*") ...

On Thu, Sep 26, 2013 at 5:41 PM, Jeff Eltgroth <je...@gmail.com> wrote:
> Hi,
>
> I am using camel-core 2.10.0.fuse-71-047 and I am getting similar problems
> using interceptSendToEndpoint.  My uri has a pound sign (#) which is getting
> encoded to %23.  This is the kind of uri I am using:
> "aws-sqs://myQueue?amazonSQSClient=#myClient" where myClient is in the
> registry.
>
> Jeff
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p5740263.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: interceptSendToEndpoint with dynamic endpoint

Posted by Jeff Eltgroth <je...@gmail.com>.
Hi,

I am using camel-core 2.10.0.fuse-71-047 and I am getting similar problems
using interceptSendToEndpoint.  My uri has a pound sign (#) which is getting
encoded to %23.  This is the kind of uri I am using: 
"aws-sqs://myQueue?amazonSQSClient=#myClient" where myClient is in the
registry.

Jeff



--
View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p5740263.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: interceptSendToEndpoint with dynamic endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I was able to reproduce the issue and I will fix this in the next release.
https://issues.apache.org/jira/browse/CAMEL-3430


On Tue, Dec 14, 2010 at 11:00 PM, John <Jo...@ateb.com> wrote:
>
> I've started testing with the camel 2.6 snapshot and believe I have found the
> root of the issue.
>
> The endpoint I am trying to test is an http endpoint. I included the user
> name and password as query params in the URI.
>
> Having a "&" in the URI prevents the InterceptSendToEndpoint from working
> correctly. I recreated the issue with a static http endpoint like
>
> .to("http:host/my_ws?arg1=ok&arg2=bad")
>
> Out of curiosity I printed out the endpoints in my route after adding the
> interceptor. On the URI without the "&", I only see one endpoint:
>
> endPoint.uri = http://host/some_place/junk?arg1=ok
> endPoint.class = class org.apache.camel.impl.InterceptSendToEndpoint
>
> On the URI with the "&", I see two endpoints:
>
> endPoint.uri = http://host/some_place/junk?arg2=bad&arg1=ok
> endPoint.class = class org.apache.camel.impl.InterceptSendToEndpoint
> endPoint.uri = http://host/some_place/junk?arg2=bad&arg1=ok
> endPoint.class = class org.apache.camel.component.http.HttpEndpoint
>
> -john
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3305364.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: interceptSendToEndpoint with dynamic endpoint

Posted by John <Jo...@ateb.com>.
I've started testing with the camel 2.6 snapshot and believe I have found the
root of the issue.

The endpoint I am trying to test is an http endpoint. I included the user
name and password as query params in the URI.

Having a "&" in the URI prevents the InterceptSendToEndpoint from working
correctly. I recreated the issue with a static http endpoint like

.to("http:host/my_ws?arg1=ok&arg2=bad")

Out of curiosity I printed out the endpoints in my route after adding the
interceptor. On the URI without the "&", I only see one endpoint:

endPoint.uri = http://host/some_place/junk?arg1=ok
endPoint.class = class org.apache.camel.impl.InterceptSendToEndpoint

On the URI with the "&", I see two endpoints:

endPoint.uri = http://host/some_place/junk?arg2=bad&arg1=ok
endPoint.class = class org.apache.camel.impl.InterceptSendToEndpoint
endPoint.uri = http://host/some_place/junk?arg2=bad&arg1=ok
endPoint.class = class org.apache.camel.component.http.HttpEndpoint

-john

-- 
View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3305364.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: interceptSendToEndpoint with dynamic endpoint

Posted by John <Jo...@ateb.com>.
I added a System.out.println in the route class to show that when the route
is starting wsUrl is set properly. 

I also added a println to the test class right before I add the adviceWith.
The adviceWith call in the test class appears to occur after the route has
successfully loaded.

I was trying to see if I could determine from the RouteDefinition in the
test class what the endpoint in question looks like.
-- 
View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3303142.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: interceptSendToEndpoint with dynamic endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
Add a system.out.println(wsUrl) so you can see that the url has been
resolved and spring have invoked the afterPropertiesSet. BEFORE the
adviceWith is being invoked in your test.



On Mon, Dec 13, 2010 at 2:55 PM, John <Jo...@ateb.com> wrote:
>
> My application has a route defined like:
>
> public MyRoute extends RouteBuilder implements InitializingBean,
> DisposableBean
> {
>    private String host;
>    private String user;
>    private String pw;
>
>    private String wsUrl;
>
>    afterPropertiesSet()
>    {
>        wsUrl = "http://" + host + "/some_ws" + "?username=" + user +
> "&password=" + pw;
>    }
>
>    public void configure()
>    {

Add System.out here!!!


>        from("activemq:somequeue")
>            .bean("someBean")
>            .to(wsUrl);
>    }
> }
>
> In my spring xml I define:
>
> <camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
>    <camel:routeBuilder ref="myRoute"/>
> </camelContext>
>
> <bean name="myRoute" class="com.MyRoute">
>    <property name="host" value="${myroute.host}" />
>    <property name="user" value="${myroute.user}" />
>    <property name="pw" value="${myroute.pw}" />
> </bean>
>
> So I'm trying to create a unit test with a mock endpoint for the web service
> call in the route. To do that I'm attempting to add the interceptor via
> adviceWith that I showed above. I can't get the interceptor to actually work
> though when my original route uses the wsUrl variable. If I replace wsUrl
> with the String "http://some_stuff" the interceptor works fine.
>
> Thanks,
>
> -john
> --
> View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3303122.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: interceptSendToEndpoint with dynamic endpoint

Posted by John <Jo...@ateb.com>.
My application has a route defined like:

public MyRoute extends RouteBuilder implements InitializingBean,
DisposableBean
{
    private String host;
    private String user;
    private String pw;

    private String wsUrl;

    afterPropertiesSet()
    {
        wsUrl = "http://" + host + "/some_ws" + "?username=" + user +
"&password=" + pw;
    }

    public void configure()
    {
        from("activemq:somequeue")
            .bean("someBean")
            .to(wsUrl);
    }
}

In my spring xml I define:

<camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
    <camel:routeBuilder ref="myRoute"/>        
</camelContext>

<bean name="myRoute" class="com.MyRoute">
    <property name="host" value="${myroute.host}" />
    <property name="user" value="${myroute.user}" />
    <property name="pw" value="${myroute.pw}" />
</bean>

So I'm trying to create a unit test with a mock endpoint for the web service
call in the route. To do that I'm attempting to add the interceptor via
adviceWith that I showed above. I can't get the interceptor to actually work
though when my original route uses the wsUrl variable. If I replace wsUrl
with the String "http://some_stuff" the interceptor works fine.

Thanks,

-john
-- 
View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3303122.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: interceptSendToEndpoint with dynamic endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Dec 13, 2010 at 11:44 AM, John <Jo...@ateb.com> wrote:
>
> Hi Claus,
>
> I'm already using a wild card to try and perform the match. The issue
> appears to be with using the adviceWith method to setup the
> interceptSendToEndpoint call in my unit test.
>
> This works perfectly when the endpoint in the route I'm testing is not
> configured via spring properties.
>

What do you mean with spring properties? Can you post your example in full?


> Here is what I'm doing in the unit test to setup the interceptor:
>
>        RouteDefinition myRoute =
>            context.getRouteDefinition("myRoute");
>
>        myRoute.adviceWith(new RouteBuilder()
>        {
>
>            @Override
>            public void configure() throws Exception
>            {
>                 interceptSendToEndpoint("http*")
>                    .skipSendToOriginalEndpoint()
>                    .to(mockWsEndpoint);
>            }
>        });
>
> Thanks,
>
> -john
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3302930.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: interceptSendToEndpoint with dynamic endpoint

Posted by John <Jo...@ateb.com>.
Hi Claus,

I'm already using a wild card to try and perform the match. The issue
appears to be with using the adviceWith method to setup the
interceptSendToEndpoint call in my unit test.

This works perfectly when the endpoint in the route I'm testing is not
configured via spring properties.

Here is what I'm doing in the unit test to setup the interceptor:

        RouteDefinition myRoute = 
            context.getRouteDefinition("myRoute");
        
        myRoute.adviceWith(new RouteBuilder()
        {   

            @Override
            public void configure() throws Exception
            {
                 interceptSendToEndpoint("http*")
                    .skipSendToOriginalEndpoint()
                    .to(mockWsEndpoint);                
            }
        });

Thanks,

-john

-- 
View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3302930.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: interceptSendToEndpoint with dynamic endpoint

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Dec 12, 2010 at 7:07 AM, John <Jo...@ateb.com> wrote:
>
> Hi,
>
> I am using camel 2.2, though I did give this a shot with 2.5
>
> I have a route that has an http endpoint that is configured at startup. In
> my route builder I have something like:
>
> String wsUrl = "http://host/ws";
>
> from("activemq:somequeue")
>    .bean("someBean")
>    .to(wsUrl);
>
> While trying to create a unit test for this route, I am adding an
> interceptSendToEndpoint to direct any requests to the wsUrl endpoint to a
> mock endpoint.
>
> I am unable to get the interceptor to work as long as I have a variable in
> the original route endpoint. If I replace .to(wsUrl) with
> .to("http://host/ws") everything works fine in my test. The documentation
> mentions that interceptSendToEndpoint should be fine with a dynamic URI.
>

Read the documentation, you can use wildcards in the interceptor, for
example a * or an reg exp expressions
http://camel.apache.org/intercept.html

And in later Camel releases you can use property placeholders in your
routes to avoid hardcoding
http://camel.apache.org/properties.html

> Is there a way to use the interceptor in my test without a hard coded string
> in the route endpoint?
>
> Thanks,
>
> -john
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/interceptSendToEndpoint-with-dynamic-endpoint-tp3301978p3301978.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/