You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jfaath <jf...@apache.org> on 2010/02/26 18:31:06 UTC
Default error handler, changing HTTP response code
By consulting the documentation, I came up with this code to handle an error
for messages sent to a jetty http endpoint:
onException(SchemaValidationException.class)
.handled(true)
.transform()
.simple("The format of the incoming message does not conform to the
specification.");
Everything works fine, except using "handled(true)" causes a 200 OK response
to be sent back to the client. When I use "handled(false)" a 500 response
is returned, but I lose my custom error message.
Is there any way to return a 500 error but keep the nice error message?
-JF
--
View this message in context: http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27721146.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Default error handler, changing HTTP response code
Posted by jfaath <jf...@apache.org>.
Yep, that works really well. Thanks for the tip!
Claus Ibsen-2 wrote:
>
> Hi
>
> Well all you needed to do is to set the status code, since you handled
> the exception, and thus Camel thinks its OKAY and will use 200 then.
>
> I have created an unit test and updated the wiki page with how to (see
> bottom)
> http://cwiki.apache.org/confluence/display/CAMEL/Jetty
>
> And this commits:
> http://svn.apache.org/viewvc?rev=918337&view=rev
>
>
> On Tue, Mar 2, 2010 at 10:15 PM, jfaath <jf...@apache.org> wrote:
>>
>> I just tried that and in fact I don't see the behavior changing under any
>> variations of the code. What exactly is that supposed to do?
>>
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> Hi
>>>
>>> Have you tried with the option throwExceptionOnFailure=false
>>>
>>>
>>>
>>> On Tue, Mar 2, 2010 at 7:45 PM, jfaath <jf...@apache.org> wrote:
>>>>
>>>> I don't think it has to do with the browser. I'm using javascript to
>>>> send
>>>> and receive the message. It's a client test file I took from a
>>>> servicemix
>>>> sample:
>>>>
>>>> http://svn.apache.org/repos/asf/servicemix/smx3/trunk/samples/bridge-camel/client.html
>>>>
>>>> And besides, the 500 error is returned when I have 'handled(false)' in
>>>> the
>>>> route. So, it is clear that a 500 error isn't being hidden by any
>>>> external
>>>> forces.
>>>>
>>>>
>>>> Claus Ibsen-2 wrote:
>>>>>
>>>>> On Fri, Feb 26, 2010 at 6:31 PM, jfaath <jf...@apache.org> wrote:
>>>>>>
>>>>>> By consulting the documentation, I came up with this code to handle
>>>>>> an
>>>>>> error
>>>>>> for messages sent to a jetty http endpoint:
>>>>>>
>>>>>> onException(SchemaValidationException.class)
>>>>>> .handled(true)
>>>>>> .transform()
>>>>>> .simple("The format of the incoming message does not conform to the
>>>>>> specification.");
>>>>>>
>>>>>> Everything works fine, except using "handled(true)" causes a 200 OK
>>>>>> response
>>>>>> to be sent back to the client. When I use "handled(false)" a 500
>>>>>> response
>>>>>> is returned, but I lose my custom error message.
>>>>>>
>>>>>> Is there any way to return a 500 error but keep the nice error
>>>>>> message?
>>>>>>
>>>>>
>>>>> I am sure it returns your nice message with HTTP error code 500.
>>>>>
>>>>> I wonder if you webbrowser or what you use to view the result may
>>>>> suppress the nice message and display its own message.
>>>>> The browser may have an setting to disable this.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> -JF
>>>>>>
>>>>>> --
>>>>>> View this message in context:
>>>>>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27721146.html
>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Claus Ibsen
>>>>> Apache Camel Committer
>>>>>
>>>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>>> Open Source Integration: http://fusesource.com
>>>>> Blog: http://davsclaus.blogspot.com/
>>>>> Twitter: http://twitter.com/davsclaus
>>>>>
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27759591.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27761282.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
>
--
View this message in context: http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27770211.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Default error handler, changing HTTP response code
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Well all you needed to do is to set the status code, since you handled
the exception, and thus Camel thinks its OKAY and will use 200 then.
I have created an unit test and updated the wiki page with how to (see bottom)
http://cwiki.apache.org/confluence/display/CAMEL/Jetty
And this commits:
http://svn.apache.org/viewvc?rev=918337&view=rev
On Tue, Mar 2, 2010 at 10:15 PM, jfaath <jf...@apache.org> wrote:
>
> I just tried that and in fact I don't see the behavior changing under any
> variations of the code. What exactly is that supposed to do?
>
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> Have you tried with the option throwExceptionOnFailure=false
>>
>>
>>
>> On Tue, Mar 2, 2010 at 7:45 PM, jfaath <jf...@apache.org> wrote:
>>>
>>> I don't think it has to do with the browser. I'm using javascript to
>>> send
>>> and receive the message. It's a client test file I took from a
>>> servicemix
>>> sample:
>>>
>>> http://svn.apache.org/repos/asf/servicemix/smx3/trunk/samples/bridge-camel/client.html
>>>
>>> And besides, the 500 error is returned when I have 'handled(false)' in
>>> the
>>> route. So, it is clear that a 500 error isn't being hidden by any
>>> external
>>> forces.
>>>
>>>
>>> Claus Ibsen-2 wrote:
>>>>
>>>> On Fri, Feb 26, 2010 at 6:31 PM, jfaath <jf...@apache.org> wrote:
>>>>>
>>>>> By consulting the documentation, I came up with this code to handle an
>>>>> error
>>>>> for messages sent to a jetty http endpoint:
>>>>>
>>>>> onException(SchemaValidationException.class)
>>>>> .handled(true)
>>>>> .transform()
>>>>> .simple("The format of the incoming message does not conform to the
>>>>> specification.");
>>>>>
>>>>> Everything works fine, except using "handled(true)" causes a 200 OK
>>>>> response
>>>>> to be sent back to the client. When I use "handled(false)" a 500
>>>>> response
>>>>> is returned, but I lose my custom error message.
>>>>>
>>>>> Is there any way to return a 500 error but keep the nice error message?
>>>>>
>>>>
>>>> I am sure it returns your nice message with HTTP error code 500.
>>>>
>>>> I wonder if you webbrowser or what you use to view the result may
>>>> suppress the nice message and display its own message.
>>>> The browser may have an setting to disable this.
>>>>
>>>>
>>>>
>>>>
>>>>> -JF
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27721146.html
>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Claus Ibsen
>>>> Apache Camel Committer
>>>>
>>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>> Open Source Integration: http://fusesource.com
>>>> Blog: http://davsclaus.blogspot.com/
>>>> Twitter: http://twitter.com/davsclaus
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27759591.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27761282.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: Default error handler, changing HTTP response code
Posted by jfaath <jf...@apache.org>.
I just tried that and in fact I don't see the behavior changing under any
variations of the code. What exactly is that supposed to do?
Claus Ibsen-2 wrote:
>
> Hi
>
> Have you tried with the option throwExceptionOnFailure=false
>
>
>
> On Tue, Mar 2, 2010 at 7:45 PM, jfaath <jf...@apache.org> wrote:
>>
>> I don't think it has to do with the browser. I'm using javascript to
>> send
>> and receive the message. It's a client test file I took from a
>> servicemix
>> sample:
>>
>> http://svn.apache.org/repos/asf/servicemix/smx3/trunk/samples/bridge-camel/client.html
>>
>> And besides, the 500 error is returned when I have 'handled(false)' in
>> the
>> route. So, it is clear that a 500 error isn't being hidden by any
>> external
>> forces.
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> On Fri, Feb 26, 2010 at 6:31 PM, jfaath <jf...@apache.org> wrote:
>>>>
>>>> By consulting the documentation, I came up with this code to handle an
>>>> error
>>>> for messages sent to a jetty http endpoint:
>>>>
>>>> onException(SchemaValidationException.class)
>>>> .handled(true)
>>>> .transform()
>>>> .simple("The format of the incoming message does not conform to the
>>>> specification.");
>>>>
>>>> Everything works fine, except using "handled(true)" causes a 200 OK
>>>> response
>>>> to be sent back to the client. When I use "handled(false)" a 500
>>>> response
>>>> is returned, but I lose my custom error message.
>>>>
>>>> Is there any way to return a 500 error but keep the nice error message?
>>>>
>>>
>>> I am sure it returns your nice message with HTTP error code 500.
>>>
>>> I wonder if you webbrowser or what you use to view the result may
>>> suppress the nice message and display its own message.
>>> The browser may have an setting to disable this.
>>>
>>>
>>>
>>>
>>>> -JF
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27721146.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27759591.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
>
--
View this message in context: http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27761282.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Default error handler, changing HTTP response code
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Have you tried with the option throwExceptionOnFailure=false
On Tue, Mar 2, 2010 at 7:45 PM, jfaath <jf...@apache.org> wrote:
>
> I don't think it has to do with the browser. I'm using javascript to send
> and receive the message. It's a client test file I took from a servicemix
> sample:
>
> http://svn.apache.org/repos/asf/servicemix/smx3/trunk/samples/bridge-camel/client.html
>
> And besides, the 500 error is returned when I have 'handled(false)' in the
> route. So, it is clear that a 500 error isn't being hidden by any external
> forces.
>
>
> Claus Ibsen-2 wrote:
>>
>> On Fri, Feb 26, 2010 at 6:31 PM, jfaath <jf...@apache.org> wrote:
>>>
>>> By consulting the documentation, I came up with this code to handle an
>>> error
>>> for messages sent to a jetty http endpoint:
>>>
>>> onException(SchemaValidationException.class)
>>> .handled(true)
>>> .transform()
>>> .simple("The format of the incoming message does not conform to the
>>> specification.");
>>>
>>> Everything works fine, except using "handled(true)" causes a 200 OK
>>> response
>>> to be sent back to the client. When I use "handled(false)" a 500
>>> response
>>> is returned, but I lose my custom error message.
>>>
>>> Is there any way to return a 500 error but keep the nice error message?
>>>
>>
>> I am sure it returns your nice message with HTTP error code 500.
>>
>> I wonder if you webbrowser or what you use to view the result may
>> suppress the nice message and display its own message.
>> The browser may have an setting to disable this.
>>
>>
>>
>>
>>> -JF
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27721146.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27759591.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: Default error handler, changing HTTP response code
Posted by jfaath <jf...@apache.org>.
I don't think it has to do with the browser. I'm using javascript to send
and receive the message. It's a client test file I took from a servicemix
sample:
http://svn.apache.org/repos/asf/servicemix/smx3/trunk/samples/bridge-camel/client.html
And besides, the 500 error is returned when I have 'handled(false)' in the
route. So, it is clear that a 500 error isn't being hidden by any external
forces.
Claus Ibsen-2 wrote:
>
> On Fri, Feb 26, 2010 at 6:31 PM, jfaath <jf...@apache.org> wrote:
>>
>> By consulting the documentation, I came up with this code to handle an
>> error
>> for messages sent to a jetty http endpoint:
>>
>> onException(SchemaValidationException.class)
>> .handled(true)
>> .transform()
>> .simple("The format of the incoming message does not conform to the
>> specification.");
>>
>> Everything works fine, except using "handled(true)" causes a 200 OK
>> response
>> to be sent back to the client. When I use "handled(false)" a 500
>> response
>> is returned, but I lose my custom error message.
>>
>> Is there any way to return a 500 error but keep the nice error message?
>>
>
> I am sure it returns your nice message with HTTP error code 500.
>
> I wonder if you webbrowser or what you use to view the result may
> suppress the nice message and display its own message.
> The browser may have an setting to disable this.
>
>
>
>
>> -JF
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27721146.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
>
--
View this message in context: http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27759591.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Default error handler, changing HTTP response code
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Feb 26, 2010 at 6:31 PM, jfaath <jf...@apache.org> wrote:
>
> By consulting the documentation, I came up with this code to handle an error
> for messages sent to a jetty http endpoint:
>
> onException(SchemaValidationException.class)
> .handled(true)
> .transform()
> .simple("The format of the incoming message does not conform to the
> specification.");
>
> Everything works fine, except using "handled(true)" causes a 200 OK response
> to be sent back to the client. When I use "handled(false)" a 500 response
> is returned, but I lose my custom error message.
>
> Is there any way to return a 500 error but keep the nice error message?
>
I am sure it returns your nice message with HTTP error code 500.
I wonder if you webbrowser or what you use to view the result may
suppress the nice message and display its own message.
The browser may have an setting to disable this.
> -JF
>
> --
> View this message in context: http://old.nabble.com/Default-error-handler%2C-changing-HTTP-response-code-tp27721146p27721146.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus