Loading the routeconfiguration through: loader.loadRoutes(resource);
also doesn't work. Directly from Java is no problem. Is this a bug or should the XML RouteConfiguration loaded differently? Raymond On Mon, Apr 11, 2022 at 10:26 PM ski n <raymondmees...@gmail.com> wrote: > As a note: > > When when using the routeConfiguration from Java and load it: > > public class MyJavaErrorHandler extends RouteConfigurationBuilder { > > @Override > public void configuration() throws Exception { > routeConfiguration("xmlError") > .onException(Exception.class).handled(true) > .log("Java WARN: ${exception.message}"); > } > } > > context.addRoutes(new MyJavaErrorHandler()); > > then it works as expected. Thus, it must be because of the way the > routeconfiguration was loaded. I loaded it using: > > loader.updateRoutes(resource); > > I assumed it worked similar to the old "addOrUpdateXml" method as it says > > "Loads or updates existing RoutesBuilder". However it works differently > (at least for RouteConfiguration). When changing the > routeConfiguration to: > > loader.loadRoutes(resource); > > then it worked. > > Raymond > > > > > > > > > > > > > On Mon, Apr 11, 2022 at 9:13 PM ski n <raymondmees...@gmail.com> wrote: > >> Yes, with the try-catch-finally clause one can have more fine-grained. >> However, I am not the one who writes the routes. I am only loading them. >> That's why I need a more generic behavior (errorHandler) with some >> configuration options (routeConfiguration). >> >> I assumed that the XML routeConfiguration can be loaded the same as a >> 'normal' xml route. I loaded the following: >> >> <routeConfiguration id="xmlError"> >> <onException> >> <exception>java.lang.Exception</exception> >> <handled><constant>true</constant></handled> >> <log message="XML WARN: ${exception.message}"/> >> </onException></routeConfiguration> >> >> And then the route: >> >> <route routeConfigurationId="xmlError"> >> <from uri="timer:xml?period=5s"/> >> <log message="I am XML"/> >> <throwException exceptionType="java.lang.Exception" message="Some kind >> of XML error"/></route> >> >> >> I see the error thrown "Some kind of XML error", but I don't see it >> handled (for example the XML WARN message). Is there something that I am >> missing? >> >> Raymond >> >> >> >> >> >> On Mon, Apr 11, 2022 at 6:06 PM Chirag <chirag.sangh...@gmail.com> wrote: >> >>> 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 >>> >>