You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ramrubio <ra...@yahoo.com> on 2013/03/08 21:46:08 UTC

Routing REST request to external URI

Does Camel support routing an incoming REST request to an external RESTful
service for all http operations.

For example,

Client Submits REST request to server A.  Server A uses Camel to route to
appropriate service which resides in Server B.

I would like to to this for all HTTP operations (GET, POST, DELETE, etc...).

Is this possible with Camel?

Thanks,

/Ramon



--
View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Routing REST request to external URI

Posted by ramrubio <ra...@yahoo.com>.
Ok.  Found my answer. Added removeHeader to route.

this.from("servlet:///?matchOnUriPrefix=true").removeHeader(Exchange.HTTP_PATH).dynamicRouter(method(CamelRoute.class,
"slip"));



--
View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852p5729142.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Routing REST request to external URI

Posted by ramrubio <ra...@yahoo.com>.
Further info.  Method where original request HTTP_PATH is being appended is 
HttpHelper:208.



/Ramon



--
View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852p5729140.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Routing REST request to external URI

Posted by ramrubio <ra...@yahoo.com>.
Thanks for the feedback.

I've run into another issue.  I'm trying to route an incoming URI to a
different URI but HttpProducer method appends the original URI to the new
route in HttpProducer.createURL.

The following is the use case:
1.  Client requests http://server1:8080/public/users
2.  Proxy receives and routes request to http://server2:8080/private/users

My camel proxy produces the following in step 2:
http://server2:8080/private/users/public/users

My setup is as follows:

1.  Setup Dynamic Router
this.from("servlet:///?matchOnUriPrefix=true").dynamicRouter(method(CamelRoute.class,
"slip"));

2.  Slip method return new http route with bridgeEndpoint=true.

Is there anyway to prevent original path from being appended?  Or maybe i'm
missing a configuration.

Thanks in advance.

/Ramon



--
View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852p5729139.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Routing REST request to external URI

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Mar 12, 2013 at 5:33 PM, ramrubio <ra...@yahoo.com> wrote:
> Hi,
>
> Noticed that RouteBuilder is cached and called only once to construct the
> routes.
>
> From documentation they mention using DynamicRouter for implementing dynamic
> uri routing.
>
> But it seems that even in this case it is not dynamic routing as the routes
> need to be predefined and the dynamic part is simply returning the route id
> in the slip method to determine which pre-defined route to choose?
>
> What i would like to do is dynamically add the route (not pre-defined) is
> this possible through Dynamic Router Pattern or am i looking at the wrong
> thing?
>
> /Ramon
>

You can use the API from CamelContext to add/remove routes dynamically
at runtime.

And you can also call this API from within a route.
Though mind that if you want to stop and remove a route from within
the same route, then this is a bit more tricky. Then see this FAQ
http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html

The EIPs themselves is part of an existing route.
http://camel.apache.org/eip


>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852p5729004.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Re: Routing REST request to external URI

Posted by ramrubio <ra...@yahoo.com>.
Hi,

Noticed that RouteBuilder is cached and called only once to construct the
routes.  

>From documentation they mention using DynamicRouter for implementing dynamic
uri routing.

But it seems that even in this case it is not dynamic routing as the routes
need to be predefined and the dynamic part is simply returning the route id
in the slip method to determine which pre-defined route to choose?

What i would like to do is dynamically add the route (not pre-defined) is
this possible through Dynamic Router Pattern or am i looking at the wrong
thing?

/Ramon



--
View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852p5729004.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Routing REST request to external URI

Posted by Henryk Konsek <he...@gmail.com>.
> I also wanted to confirm that Camel support dynamic routing for all http
> operations (GET, POST, PUT, DELETE)

>From Jetty component documentation [1] - "you can get the
request.parameter from the message header not only from Get Method,
but also other HTTP method".

> and that proxied request from Camel
> Proxy End Point to actual server end point is the same http operation with
> original http headers as the original request originated by the client.

Another excerpt from Jetty component documentation [1] - "Camel also
populates all request.parameter and request.headers".

> I wanted to confirm this is possible with Camel on Tomcat.

Certainly it is :) I strongly suggest you to read the Jetty component
documentation [1] as the lecture would address many of your doubts.

[1] http://camel.apache.org/jetty.html

--
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: Routing REST request to external URI

Posted by Willem jiang <wi...@gmail.com>.
It's easy to get HTTP method from the message header , if you are using camel-servlet or camel-jetty component.


--  
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 Sunday, March 10, 2013 at 5:49 AM, ramrubio wrote:

> I want to setup camel as a proxy between my client and server.
>  
> My proxy server is running on tomcat.
>  
> On my proxy server (camel end point) i want to perform dynamic routing to
> route request to appropiate service end point on a different server.
>  
> I'm new to camel but did notice that it supports dynamic routing. I want to
> set this up on my tomcat server and was wondering if there were any examples
> that i can begin with (new to camel).
>  
> I also wanted to confirm that Camel support dynamic routing for all http
> operations (GET, POST, PUT, DELETE) and that proxied request from Camel
> Proxy End Point to actual server end point is the same http operation with
> original http headers as the original request originated by the client.
>  
> For Example:
>  
> Client performs HTTP POST (with special headers) -> Camel Receives HTTP
> POST and Routes to Server B as an HTTP POST (with special headers) -> Server
> B receives HTTP POST (with special headers).
>  
> I wanted to confirm this is possible with Camel on Tomcat.
>  
> Thanks,
>  
> /Ramon
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852p5728885.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Routing REST request to external URI

Posted by ramrubio <ra...@yahoo.com>.
I want to setup camel as a proxy between my client and server.

My proxy server is running on tomcat.

On my proxy server (camel end point) i want to perform dynamic routing to
route request to appropiate service end point on a different server.

I'm new to camel but did notice that it supports dynamic routing.  I want to
set this up on my tomcat server and was wondering if there were any examples
that i can begin with (new to camel).

I also wanted to confirm that Camel support dynamic routing for all http
operations (GET, POST, PUT, DELETE) and that proxied request from Camel
Proxy End Point to actual server end point is the same http operation with
original http headers as the original request originated by the client.

For Example:

Client performs HTTP POST (with special headers) ->  Camel Receives HTTP
POST and Routes to Server B as an HTTP POST (with special headers) -> Server
B receives HTTP POST (with special headers).

I wanted to confirm this is possible with Camel on Tomcat.

Thanks,

/Ramon





--
View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852p5728885.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Routing REST request to external URI

Posted by Henryk Konsek <he...@gmail.com>.
Hi Ramon,

> Is it possible on tomcat?

Sure. Camel Jetty component [1] opens new embedded HTTP server on the
port of your choice, so it don't have to conflict with ports opened by
Tomcat.

> Any examples?

You can deploy the example mentioned [2] by Claus on Tomcat as well.

> Also I want to be able to dynamically route the requests to
> different servers.

Camel is pretty dynamic animal :) Could you elaborate what exactly do
you want to achieve here?

Best regards.

[1] http://camel.apache.org/jetty.html
[2] http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html

--
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: Routing REST request to external URI

Posted by ramrubio <ra...@yahoo.com>.
Is it possible on tomcat?

Any examples?  Also I want to be able to dynamically route the requests to
different servers.

Thanks in advance.

/Ramon



--
View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852p5728879.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Routing REST request to external URI

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

See also this little example
http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html



On Fri, Mar 8, 2013 at 9:46 PM, ramrubio <ra...@yahoo.com> wrote:
> Does Camel support routing an incoming REST request to an external RESTful
> service for all http operations.
>
> For example,
>
> Client Submits REST request to server A.  Server A uses Camel to route to
> appropriate service which resides in Server B.
>
> I would like to to this for all HTTP operations (GET, POST, DELETE, etc...).
>
> Is this possible with Camel?
>
> Thanks,
>
> /Ramon
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Re: Routing REST request to external URI

Posted by Christian Müller <ch...@gmail.com>.
Yes, checkout the jetty and servlet component.

Sent from a mobile device
Am 08.03.2013 13:46 schrieb "ramrubio" <ra...@yahoo.com>:

> Does Camel support routing an incoming REST request to an external RESTful
> service for all http operations.
>
> For example,
>
> Client Submits REST request to server A.  Server A uses Camel to route to
> appropriate service which resides in Server B.
>
> I would like to to this for all HTTP operations (GET, POST, DELETE,
> etc...).
>
> Is this possible with Camel?
>
> Thanks,
>
> /Ramon
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Routing-REST-request-to-external-URI-tp5728852.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>