You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Charles Moulliard <cm...@gmail.com> on 2010/12/07 11:28:05 UTC
Spring DSL with Exception
Hi,
I try to convert the following syntax in Spring DSL but get error and
cannot find how to add transform.
from("jetty://http://localhost:{{port}}/myserver")
// use onException tocatch all exceptions andreturn a custom reply message
.onException(Exception.class)
.handled(true)
// create a custom failure response
.transform(constant("Dude something went wrong"))
// we must remember to set error code 500 as handled(true)
// otherwise would let Camel thing its a OK response (200)
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
.end()
// now just force an exception immediately
.throwException(new IllegalArgumentException("I cannotdo this"));
Here is what I have done :
<from uri="jetty:http://localhost:8080/services"/>
<onException>
<exception>java.lang.Exception</exception>
<redeliveryPolicy maximumRedeliveries="1"/>
<handled>
<constant>true</constant>
</handled>
############ HOW CAN I ADD transform() ###############
<header name="Exchange.HTTP_RESPONSE_CODE">
<constant>500</constant>
</header>
</onException>
<bean ref="responseBean"/>
Regards,
Charles
Re: Spring DSL with Exception
Posted by Charles Moulliard <cm...@gmail.com>.
Shame on me to forget setHeader ...
On 07/12/10 11:34, Claus Ibsen wrote:
> Hi
>
> Charles you know better!
>
> The Spring DSL is 1:1 to the Java DSL.
>
> So just use
> <setHeader>
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
> <route>
> <from uri="seda:a"/>
> <setHeader headerName="oldBodyValue">
> <simple>body</simple>
> </setHeader>
> <to uri="mock:b"/>
> </route>
> </camelContext>
>
>
> And check the unit test source code in camel-spring if you are in a
> bit of doubt and want to look for an example.
>
> And check the Spring XSD
> http://camel.apache.org/schema/spring/
>
>
> On Tue, Dec 7, 2010 at 11:28 AM, Charles Moulliard<cm...@gmail.com> wrote:
>> Hi,
>>
>> I try to convert the following syntax in Spring DSL but get error and cannot
>> find how to add transform.
>>
>> from("jetty://http://localhost:{{port}}/myserver")
>> // use onException tocatch all exceptions andreturn a custom reply
>> message
>> .onException(Exception.class)
>> .handled(true)
>> // create a custom failure response
>> .transform(constant("Dude something went wrong"))
>> // we must remember to set error code 500 as handled(true)
>> // otherwise would let Camel thing its a OK response (200)
>> .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
>> .end()
>> // now just force an exception immediately
>> .throwException(new IllegalArgumentException("I cannotdo this"));
>>
>>
>> Here is what I have done :
>>
>> <from uri="jetty:http://localhost:8080/services"/>
>> <onException>
>> <exception>java.lang.Exception</exception>
>> <redeliveryPolicy maximumRedeliveries="1"/>
>> <handled>
>> <constant>true</constant>
>> </handled>
>> ############ HOW CAN I ADD transform() ###############
>> <header name="Exchange.HTTP_RESPONSE_CODE">
>> <constant>500</constant>
>> </header>
>> </onException>
>> <bean ref="responseBean"/>
>>
>> Regards,
>>
>> Charles
>>
>
>
Re: Spring DSL with Exception
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Charles you know better!
The Spring DSL is 1:1 to the Java DSL.
So just use
<setHeader>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="seda:a"/>
<setHeader headerName="oldBodyValue">
<simple>body</simple>
</setHeader>
<to uri="mock:b"/>
</route>
</camelContext>
And check the unit test source code in camel-spring if you are in a
bit of doubt and want to look for an example.
And check the Spring XSD
http://camel.apache.org/schema/spring/
On Tue, Dec 7, 2010 at 11:28 AM, Charles Moulliard <cm...@gmail.com> wrote:
> Hi,
>
> I try to convert the following syntax in Spring DSL but get error and cannot
> find how to add transform.
>
> from("jetty://http://localhost:{{port}}/myserver")
> // use onException tocatch all exceptions andreturn a custom reply
> message
> .onException(Exception.class)
> .handled(true)
> // create a custom failure response
> .transform(constant("Dude something went wrong"))
> // we must remember to set error code 500 as handled(true)
> // otherwise would let Camel thing its a OK response (200)
> .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
> .end()
> // now just force an exception immediately
> .throwException(new IllegalArgumentException("I cannotdo this"));
>
>
> Here is what I have done :
>
> <from uri="jetty:http://localhost:8080/services"/>
> <onException>
> <exception>java.lang.Exception</exception>
> <redeliveryPolicy maximumRedeliveries="1"/>
> <handled>
> <constant>true</constant>
> </handled>
> ############ HOW CAN I ADD transform() ###############
> <header name="Exchange.HTTP_RESPONSE_CODE">
> <constant>500</constant>
> </header>
> </onException>
> <bean ref="responseBean"/>
>
> Regards,
>
> Charles
>
--
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/