You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by kalyan <re...@gmail.com> on 2013/05/13 18:53:44 UTC

How do I change message body without changing response status

I have a simple RouteBuilder as follows:

RouteBuilder routeBuilder = new RouteBuilder()
{
	@Override
	public void configure()
	{
		onException(HttpOperationFailedException.class).handled(true)
        .process(new Processor()
        {
            @Override
            public void process(Exchange exchange)
                throws Exception
            {
                //Expecting that there is an exception this code is reached.
                LOGGER.warn("############### msg:" +
exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
HttpOperationFailedException.class).getMessage());
            }
        }).transform().constant("There was an exception");
        
		from("servlet:///test?matchOnUriPrefix=true")
        .to("http://localhost:8080/mywar/sample?bridgeEndpoint=true");
	}
};

when I have handled(true), it changes the response status to 200. However, I
would like to update only the body information (to "There was an exception")
when there is an exception without changing other values.

Is this possible ?

Regards,
Kalyan



--
View this message in context: http://camel.465427.n5.nabble.com/How-do-I-change-message-body-without-changing-response-status-tp5732419.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How do I change message body without changing response status

Posted by kalyan <re...@gmail.com>.
I'm sorry.. but I have just found the solution.

what I needed was:

HttpOperationFailedException ex =
exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
HttpOperationFailedException.class);
                ex.getStatusCode();

Thank you.



--
View this message in context: http://camel.465427.n5.nabble.com/onException-How-do-I-change-message-body-without-changing-response-status-tp5732419p5732424.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How do I change message body without changing response status

Posted by kalyan <re...@gmail.com>.
Thank you for the reply Claus.

However, the HTTP response code received is not constant. It changes with
the input url (like 400, 404, 500, 503 etc).

handled(true) is changing it to 200.

Is there a way to preserve the response code with out getting to know its
value ?



--
View this message in context: http://camel.465427.n5.nabble.com/onException-How-do-I-change-message-body-without-changing-response-status-tp5732419p5732422.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How do I change message body without changing response status

Posted by Claus Ibsen <cl...@gmail.com>.
Just set a header with the key Exchange.HTTP_RESPONSE_CODE and the
integer for the code you want to use.
Then Camel will use that.


On Mon, May 13, 2013 at 6:53 PM, kalyan <re...@gmail.com> wrote:
> I have a simple RouteBuilder as follows:
>
> RouteBuilder routeBuilder = new RouteBuilder()
> {
>         @Override
>         public void configure()
>         {
>                 onException(HttpOperationFailedException.class).handled(true)
>         .process(new Processor()
>         {
>             @Override
>             public void process(Exchange exchange)
>                 throws Exception
>             {
>                 //Expecting that there is an exception this code is reached.
>                 LOGGER.warn("############### msg:" +
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> HttpOperationFailedException.class).getMessage());
>             }
>         }).transform().constant("There was an exception");
>
>                 from("servlet:///test?matchOnUriPrefix=true")
>         .to("http://localhost:8080/mywar/sample?bridgeEndpoint=true");
>         }
> };
>
> when I have handled(true), it changes the response status to 200. However, I
> would like to update only the body information (to "There was an exception")
> when there is an exception without changing other values.
>
> Is this possible ?
>
> Regards,
> Kalyan
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-do-I-change-message-body-without-changing-response-status-tp5732419.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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