You could wrap it using try/catch.

See:  https://camel.apache.org/manual/try-catch-finally.html

My experience with it is - it depends on the endpoint involved to
throw exceptions and enter doCatch appropriately.

ચિરાગ/चिराग/Chirag
------------------------------------------
Sent from My Gmail Account

On Mon, Apr 11, 2022 at 11:10 AM Claus Ibsen <claus.ib...@gmail.com> wrote:
>
> Hi
>
> See routes configuration
> https://camel.apache.org/manual/route-configuration.html
>
> On Mon, Apr 11, 2022 at 4:30 PM ski n <raymondmees...@gmail.com> wrote:
> >
> > I am indeed using Camel 3 (Currently 3.14.2) and using Maven. I just use
> > plain Java (camel core), so I have a similar setup as your example (only
> > I'm using Java, instead of the application.properties to configure the
> > Camel context and its routes). Your example helped me to also use the Yaml
> > dsl.
> >
> > I am still wondering how to do proper errorHandling/onException with the
> > routesloader.
> >
> > I can set for example the errorHandler globally:
> >
> > extendedCamelContext.setErrorHandlerFactory(routeErrorHandler);
> >
> > But I rather set it per route / per exception (and best of all from the
> > xml/yaml files). Like it used to be done like this:
> >
> >   <camelContext id="myCamelContext" xmlns="
> > http://camel.apache.org/schema/spring";>
> >     <!-- Catch the authorization exception and set the Access Denied
> > message back -->
> >     <onException>
> >       <exception>org.apache.camel.CamelAuthorizationException</exception>
> >       <handled>
> >         <constant>true</constant>
> >       </handled>
> >       <transform>
> >         <simple>Access Denied with the Policy of ${exception.policyId}
> > !</simple>
> >       </transform>
> >     </onException>
> >
> >     <route>
> >       <from uri="servlet:user"/>
> >       <!-- wrap the route in the policy which enforces security check -->
> >       <policy ref="user">
> >         <transform>
> >           <simple>Normal user can access this service</simple>
> >         </transform>
> >       </policy>
> >     </route>
> >
> >     <route>
> >       <from uri="servlet:admin"/>
> >       <!-- wrap the route in the policy which enforces security check -->
> >       <policy ref="admin">
> >         <transform>
> >           <simple>Call the admin operation OK</simple>
> >         </transform>
> >       </policy>
> >     </route>
> >
> >   </camelContext>
> >
> > But such files are not accepted by the routesLoader.
> >
> > I also tried setting the error handler on a specific route from Java like
> > this:
> >
> > Route route = context.getRoute(myRouteId);
> > route.setErrorHandlerFactory(routeErrorHandler);
> >
> > But that didn't change anything.
> >
> > Raymond
> >
> >
> >
> >
> >
> >
> >
> > On Mon, Apr 11, 2022 at 3:36 PM Chirag <chirag.sangh...@gmail.com> wrote:
> >
> > > Hello Raymond,
> > >
> > > Are you trying to use Camel 3 ?
> > > Would you use Maven or Gradle to build?
> > >
> > > Here is an example:
> > > https://github.com/chiragsanghavi/camel-experiments/tree/main/processor
> > > if this helps.
> > >
> > > This example was built to demonstrate a bug- but if you update maven
> > > to use camel 3.1.5 - it should work.
> > > Only thing needed to support YAML is a change in pom.xml to include
> > > yaml dsl and create yaml files and put them into "routes" folder.
> > >
> > > <dependency>
> > > <groupId>org.apache.camel</groupId>
> > > <artifactId>camel-yaml-dsl</artifactId>
> > > </dependency>
> > >
> > >
> > >
> > > ચિરાગ/चिराग/Chirag
> > > ------------------------------------------
> > > Sent from My Gmail Account
> > >
> > > On Mon, Apr 11, 2022 at 6:15 AM ski n <raymondmees...@gmail.com> wrote:
> > > >
> > > > Hi All,
> > > >
> > > > I like to use the routesLoader (
> > > >
> > > https://javadoc.io/static/org.apache.camel/camel-api/3.16.0/org/apache/camel/spi/annotations/RoutesLoader.html
> > > > ).
> > > > I have some questions about how to properly use it.
> > > >
> > > > 1) Is there any documentation on how to use it? (At
> > > > https://camel.apache.org/manual/ or
> > > > https://camel.apache.org/components/next/index.html).
> > > >
> > > > 2) I could find some examples (https://github.com/apache/camel-examples
> > > ),
> > > > there the routesloader example says:
> > > >
> > > > <!--
> > > >     if you want to have multiple routes, you can either have multiple
> > > files
> > > > with 1 <route> per file or
> > > >     you can use <routes> as root tag, such as
> > > > <routes><route>...</route><route>...</route></routes>
> > > > -->
> > > >
> > > > <route>
> > > >     <from uri="timer:xml?period=5s"/>
> > > >     <log message="I am XML"/>
> > > > </route>
> > > >
> > > > These examples loads xml, can it also loads other DSL's? (Like yaml or
> > > > Java).
> > > >
> > > > 3) How to use OnException with the RouteLoader?
> > > >
> > > > I thought maybe like this
> > > >
> > > > <routes xmlns="http://camel.apache.org/schema/spring";>
> > > > <onException>
> > > >  <exception>java.lang.Exception</exception>
> > > >  <redeliveryPolicy maximumRedeliveries="0" redeliveryDelay="5000"/>
> > > >  <handled><constant>true</constant></handled>
> > > >  <toD uri="file://some/directory"/>
> > > > </onException>
> > > > <route>
> > > > <from uri="timer:xml?period=5s"/>
> > > > <log message="I am XML"/>
> > > > </route>
> > > > </routes>
> > > >
> > > > But this gave me a nullpointer exception.
> > > >
> > > > 4) Load from string directly
> > > >
> > > > In Camel 2 you could load routes directly from string like this:
> > > >
> > > > ManagedCamelContext managed =
> > > > context.getExtension(ManagedCamelContext.class);
> > > > managedContext = managed.getManagedCamelContext();
> > > > managedContext.addOrUpdateRoutesFromXml(routeAsString);
> > > >
> > > > In Camel 3 the "addOrUpdateRoutesFromXml" is depracated. With 
> > > > routeLoader
> > > > from string I do it like this:
> > > >
> > > > ExtendedCamelContext extendedCamelContext =
> > > > context.adapt(ExtendedCamelContext.class);
> > > > RoutesLoader loader = extendedCamelContext.getRoutesLoader();
> > > > Resource resource = ResourceHelper.fromString("any.xml", route);
> > > >
> > > > loader.updateRoutes(resource);
> > > >
> > > > Is this the only way in Camel 3, or is there also a specific method to
> > > use
> > > > strings directly (and maybe only specify the DSL used) like:
> > > >
> > > > loader.updateRoutes(routeAsString, "xml");
> > > >
> > > >
> > > > Raymond
> > >
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to