Below is a way of doing http redirect in Camel, and it is  from a test case 
inside Camel jetty component distribution.
https://fisheye6.atlassian.com/browse/camel-git/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java?r=9d97b5b2bda394f434ed3696fa1e37ab3473ae49



  @Override
   protected RouteBuilder createRouteBuilder() throws Exception {
       return new RouteBuilder() {
           @Override
           public void configure() throws Exception {
               from("jetty://http://localhost:{{port}}/test";)
                   .process(new Processor() {
                       public void process(Exchange exchange) throws Exception {
                           
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 301);
                           exchange.getOut().setHeader("location", 
"http://localhost:"; + getPort() + "/newtest");
                       }
                   });
           }
       };
   }


Shing




On Monday, January 20, 2014 8:30 PM, Shing Hing Man <mat...@yahoo.com> wrote:
 
Thanks for the info !

Shing





On Monday, January 20, 2014 5:55 PM, Claus Ibsen <claus.ib...@gmail.com> wrote:
Hi

If you are good at using url rewrite libraries then we have that in Camel too
http://camel.apache.org/urlrewrite.html

Or do as in the bottom of the page, write an impl of that interface
and compute the rewrite url to use.


On Mon, Jan 20, 2014 at 5:52 PM, Shing Hing Man <mat...@yahoo.com> wrote:
> Hi,
>
>  I have an endpoint to receive an incoming http request. Then use a processor 
>to derive a new value from some query parameters before
>
> redirecting the request to another URL. Roughly, my code is below.
>
> from("jetty:http4://localhost:8081/test?matchOnUriPrefix=true").to(redirectProcessor);
>
>
> In my RedirectProccessor :
>
> public void process(Exchange exchange) throws Exception {
> HttpServletResponse response = exchange.getIn().getBody(
> HttpServletResponse.class);
> String fooValue = (compute fooValue depends on a HttpRequest parameter).
> String url = "http://a.b.com/test?foo="; + fooValue;
> response.sendRedirect(url);
> }
>
>
>
> I wonder if there is a more elegant way to achieve the above. Something like:
>
>
> from("jetty:http4://localhost:8081/test?matchOnUriPrefix=true").transform(...).("redirect:http://a.b.c.com/test";);
>
>
>
> Thanks in advance for any assistance !
>
>
> Shing



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io

Reply via email to