Menu
  • HOME
  • TAGS

onException and onCompletion together in RouteBuilder`s route

Tag: apache-camel,onexception

I would like to use OnException & OnComplition together in one route (Camel version 2.10.0.redhat-60024):

from("direct:camelTestEndpoint").
            onCompletion().
                log("onCompletion1").
                log("onCompletion2").
                log("onCompletion3").
            end().
            onException(Throwable.class).
                handled(true).
                log("onException").
            end().

            log("route")
            .throwException(new RuntimeException());

Although it does not work as I expect. Exception in main route causes onComplition route to stop after first processor (it is handled in PipelineHelper`s continueProcessing() method). Camel checks if exception was handled and if yes - stops the processing.

Output:

route
onException
onCompletion1

Is there I gentle way to say camel that it should skip this (without "CamelErrorHandlerHandled" property removal)?

Thanks

Best How To :

This is a bug in that version of Camel.

This has been fixed by CAMEL-7707.

  • https://issues.apache.org/jira/browse/CAMEL-7707

As a workaround you would need to manually remove those details from the exchange, in the first process in the onCompletion you do.

For example something a like

    // must remember some properties which we cannot use during onCompletion processing
    // as otherwise we may cause issues
    Object stop = exchange.removeProperty(Exchange.ROUTE_STOP);
    Object failureHandled = exchange.removeProperty(Exchange.FAILURE_HANDLED);
    Object caught = exchange.removeProperty(Exchange.EXCEPTION_CAUGHT);
    Object errorhandlerHandled = exchange.removeProperty(Exchange.ERRORHANDLER_HANDLED);

Cannot connect to websocket server using AHC-WS component in Apache Camel

apache-camel,slack-api

Looking at the code of the component it seems like it expects that you send a message first as the connection is established at that time. If you just create the consumer it won't connect to the URL. To solve my issue what I did was to add a ping...

apache camel route to split sql results

mysql,jdbc,apache-camel

Below code worked fine for me.. from("direct:insert"). to("sql:select * from my_table"). split(body()). log("${body[id]}"). end(); ...

Throttle requests in camel not working

groovy,apache-camel,throttle,eip

I am not sure how to implement the ThrottlingInflightPolicy you have setup, but you can implement a route like this that should accomplish your goal. from("jms:queue:EndPoint1?concurrentConsumers=20") .throttle(10) .to("Other_Logic_Or_Routing"); Notes: maxInflightExchanges can be controlled by simply lowering concurrentConsumers to 20 Throttle component can ensure that your messaging rate does not exceed...

Automatically restore connection to the main queue when server is up again

java,jms,apache-camel,websphere-mq

Is your HA (high-availability) Active/Passive or Active/Active? The standard HA is Active/Passive, so I will answer your question under that scenario. When your MQ system is normally running - the active queue manager (master) is running (up) and the passive queue manager (slave) is stopped (down). If the the active...

Apache Camel FTP component from a web application

ftp,apache-camel

Yes you can use Quartz in your routePolicy to make the ftp consume for a certain amount of time and then stop: http://camel.apache.org/cronscheduledroutepolicy.html If you want to use a Timer, then this will have to in the "From". Then you can use Poll Enrich to consume from FTP: from("timer://foo?fixedRate=true&period=60000") .pollEnrich("ftp://localhost")...

Sending mail with a custom MIME Message using Camel

java,email,apache-camel,spring-integration

You don't need the session. You can build the text/html message as your body, but then specify a header to hold your plaintext body. Check out the alternativeBodyHeader option in the docs. In this way, Camel will build your multi-part message for you....

Generate Javadoc for OSGi bundle

apache-camel,javadoc,servicemix,osgi-bundle,maven-javadoc-plugin

Ok, i finally found my response after digging more deeply in javadoc page (Javadoc documentation) and add these lines into the build section: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.10.3</version> </plugin> ...

Camel ProducerTemplate not injected with annotation config

java,spring,apache-camel,activemq

You should extend org.apache.camel.spring.javaconfig.CamelConfiguration in AnnotationConfigApp class

How To Disable Camel HTTP Endpoint Stream Caching When Using Servlet in OSGi

apache-camel

If you want to disable the Stream Caching, you need to setup the exchange property to disable the stream caching, but it's impossible to set the exchange property from the HttpConsumer, so I just created a JIRA for it and submit a quick fix for it shortly, you can just...

Can anyone tell me how to test my Camel Route if I have a choice operation?

java,unit-testing,testing,apache-camel

You can simply "advice" your route and add mocks to each choice of your content-based router public void testAdvised() throws Exception { // advice the first route using the inlined route builder context.getRouteDefinition("Actions").adviceWith(context, new RouteBuilder() { @Override public void configure() throws Exception { replaceFromWith("direct:start"); weaveByToString(".*method1.*").after().to("mock:choice1"); weaveByToString(".*method2.*").after().to("mock:choice2"); } }); getMockEndpoint("mock:choice1").expectedMessageCount(1);...

Database not update when using apache camel sql component

apache-camel

According to the docs you must use :# as the placeholder syntax http://camel.apache.org/sql-component So try with .to("sql:update mytable set status = 100 where id = :#${body[0][id]}") ...

Camel file component URI format

java,apache-camel

The // are part of the Camel File Component itself(and also the other camel components). They are optional so u don't have to use it. In the case of the file component and unix absolute paths you can use file:///directoryName for example....

Camel Redirecting to another route on throttling

apache-camel,throttling

If I am understanding your question right you want to throttle your incoming messages then loadbalance those messages out to a different route or system. from("SomethingSendingMeMessages") .throttle(3) .loadbalance().roundRobin() .to("place1", "place2", "place3") .end(); If you need to have the throttling route send to a second route that contains the loadbalancer you...

Camel Multicast; Direct and AMQ

java,web-services,soap,apache-camel,activemq

Ok so I took the lead from Cyaegha (Thank you) and I generated POJO's using wsdl2java using the answer below. Solution for wsdl2java serialization Using these POJO's which implement Serializable interface now works! Happy times! =)...

Does ActiveMQ support multiple transactional consumers?

transactions,apache-camel,activemq,servicemix

I finally found the solution here http://activemq.2283324.n4.nabble.com/Blocking-transactions-td2354801.html;cid=1431937246689-831. The problem is due to prefetch limit. It is recommended to put it to 0 when there are multiple consumers even if they aren't transactional. So I had to change my camel route by adding ?destination.consumer.prefetchSize=0 this way : <route> <from uri="activemq:queue:foo?destination.consumer.prefetchSize=0"/> <transacted...

No component found with Camel Bean Validator

java,validation,apache-camel,bean-validation

The camel-bean-validator doesn't allow the setting of validationProviderResolver until version 2.13 of Camel, as mentioned in the documentation.

Camel requestBodyAndHeaders() doesn't return the route result

apache-camel

You should use the splitter with agg strategy to do the split + aggregate, then its done in the same leg. See the Split aggregate request/reply sample at: http://camel.apache.org/splitter.html ...

Why Does This Apache Camel Route Not Convert JSON to XML?

java,json,xml,apache-camel

It looks like you are missing a step to first convert json text to an object. E.g., from("file:src/data?noop=true").unmarshal().json(JsonLibrary.Jackson, Map.class).marshal().xstream().to("file:target/messages/others"); You may want to convert to a POJO (rather than a Map) to avoid the ugly xml rendering. You'll need include the camel-jackson library (or camel-gson if you prefer) in your...

Is there a way I can autowire a bean in my route without using the .bean keyword in Camel?

java,spring,apache-camel,javabeans,autowired

you have a few other options... can use the bean component to reference a spring bean from("direct:hello").to("bean:bye"); can use the beanRef() API to reference a spring bean from("direct:start").beanRef("beanName", "methodName"); can use the annotation to inject and bean() API to reference the bean @Autowired Private MyService myService; ... from("direct://start").bean(myservice, "process"); ...

Camel pollEnrich and xml 'prettyPrint'

apache-camel

...so the "answer" is that this is an apparent limitation of (or bug within) the log component's "showStreams" logic. I implemented Processor in a <bean>, routed the Exchange output from my pollEnrich to that <bean>, and logged the contents instead, and that matches exactly the output from wget. FYI: this...

Camel as an HTTP Proxy to a REST service - How to route paths and parameters?

rest,servlets,proxy,apache-camel

In the end I couldn't figure out an easy way to do this in config, so I added a bean between the input and the end of the route at the http endpoint that did some transformation and added basic auth, which looked like this: // Get all of the...

What exactly does multicast() do?

apache-camel

In this case - no real difference, since the incoming message body for the stream camel component seems to always be sent onwards as the outgoing message body ;) Imagine however a more substantial case, for example: from("stream:in") .to("direct:one", "direct:two"); In this case, whatever is received on the stream is...

Camel netty component example doesn't work, within Spring MVC

spring,apache-camel,netty

You need to create a spring based camel context, eg CamelContext ccontext = new DefaultCamelContext(); should be CamelContext ccontext = new SpringCamelContext(applicationContext); and then you need to get hold of the spring ApplicationContext so Camel can integrate with Spring and lookup the beans when you define then with <bean>. An...

How to access exception in Camel errorHandler?

java,exception-handling,apache-camel

After some digging, I found out that the original exception is stored as a property in the Exchange. Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); ...

CamelContext doesn't startup if one route is misconfigured

java,apache-camel

You can configure the routes with .autoStartup(false), and then start the routes manually when CamelContext has been started up. To validate its really depending on what kind of component it is. If its some database component you can write some code that does a SQL query to see if the...

Apache Camel - Delay when exception occurs

apache-camel

Did you try redeliveryDelay of redeliveryPolicyProfile? Below policy profile will retry 3 times with the delay of 1000mS between each try. <redeliveryPolicyProfile id="myRedeliveryProfile" maximumRedeliveries="3" redeliveryDelay="1000" allowRedeliveryWhileStopping="false" retryAttemptedLogLevel="INFO" /> Read more on here...

Camel Direct end-point exception

java,apache-camel

By default, the direct component expects that there is a matching consumer for every producer. Note the new configuration option failIfNoConsumers shown in the Camel Documentation. Without a consumer, the exchange has nowhere to go at the end of your route. You may consider adding another route like this: public...

How to transfer files in order (first come first serve) using apache camel

spring,apache-camel

You can use the sortBy-option of the camel file component. See http://camel.apache.org/file2.html for more information.

Toggle for wiretap queue in Camel

java,apache-camel

Hard to say what is a "better way". It can be done shorter for sure using message filter. For instance: public class MyRouteTest extends CamelTestSupport { @Test public void test() throws InterruptedException { template.sendBody("direct:in", "testBody"); MockEndpoint wiretapEndpoint = getMockEndpoint("mock:wiretap"); wiretapEndpoint.expectedMessageCount(0); wiretapEndpoint.assertIsSatisfied(); MockEndpoint outEndpoint = getMockEndpoint("mock:out"); outEndpoint.expectedMessageCount(1); outEndpoint.assertIsSatisfied(); } @Override protected...

Camel JMS - does it pull messages from queue in a loop?

apache-camel,activemq

camel-jms uses Spring JMS MessageListenerContainer for receiving the messages. So you can read about how Spring JMS works to understand it. But yeah Spring JMS has an event loop where it pull messages from the remote JMS broker, and has a default timeout of 1 sec which allows it to...

Why does Jasypt try to decrypt Camel Property Placeholders, regardless of the ENC( prefix?

apache-camel,jbossfuse,jasypt,blueprint-osgi,blueprint

EDIT: Response from RedHat Support So this is a known issue, and theres a couple of Jira issues for it (here and here), and it appears as if the issue has been resolved in newer versions of Camel. I have tested with version 2.12.0.redhat-611412, provided by the patch named jboss-fuse-6.1.0.redhat-379-r1p3,...

Camel Multi-threaded Consumer

java,multithreading,apache-camel,producer

final Semaphore semaphore = new Semaphore(4); from("timer://GetOrder?period=1s") .to("bean:orderInfoDao?method=getNextOrder") .to("jms://process-orders") .process(new Processor() { public void process(Exchange exchange) { semaphore.acquire(); } }) .end(); from("jms://process-orders?concurrentConsumers=4") .to("bean:orderService?method=processOrder(${body})") .process(new Processor() { public void process(Exchange exchange) { semaphore.release(); } }) .to("direct:send-result") .end(); Notice that timer fixedRate is off (default). This is...

Camel Wiretap Error Handling

java,apache-camel

wireTap runs asynchronously thus you cant wait to catch its exceptions. If you want to run it synchronously and wait for possible exceptions, you can use enrich instead. Something like this: .enrich("direct-vm:wiretap_exception", new AggregationStrategy() { @Override public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { return oldExchange; } }) ...

Failed to deploy quickstart to Fabric8 on Jube

java,maven,apache-camel,jbossfuse,fabric8

Unfortunately with recent bigger changes to upgrading to kubernetes v1beta3 apis, and changes on the web console to use web sockets and we are in process of upgrading jube to use hawtio v2 as the web console, so it uses exactly the same web console as you would on a...

Where is this variable coming from in this Apache Camel program?

java,apache-camel

It's in the CamelTestSupport class. protected static volatile ProducerTemplate template; See the source for details...

Changing default settings for JMS messaging in Camel

apache-camel

You can always define your components as a bean and reuse them everywhere. In your case, you can have: <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="concurrentConsumers" value="1"/> <property name="transacted" value="true"/> </bean> ...

Multiple Connection Factories

java,spring,apache-camel,activemq,javabeans

You can set primary=true on one of the connection factory beans

Apache Camel CXF

java,soap,apache-camel

You seem to be running your application on Java 6.0, and Apache Camel has dropped support of Java 6.0 since 2.14.0 (see "Important changes to consider when upgrading" section) Recompiling camel in Java 6.0 wont be feasible, I believe your options are either to upgrade to Java 7.0 or to...

Camel consume single message and stop, transacted

java,transactions,apache-camel,consumer,once

I ended up using the pollEnrich dsl to achieve this. For example my route builder looks like: from("direct:service-endpont").transacted("PROPOGATION_REQUIRED").setExchangePattern(ExchangePattern.InOut).pollEnrich("activemq:test-queue").bean(myHandler); I use the direct endpoint as a service, sending a "request" message to the direct endpoint polls the jms queue for a single message (blocking if required). The transaction started extends to...

Getting Apache Camel to stop retrying if failed to move the file after route completion

java,file-io,exception-handling,locking,apache-camel

This is something that the File component needs to handle, not your route. You can configure how the File component should handle locked files using the readLock option (along with other related options). The option has an extensive description on the File2 component documentation page...

Automatic conversion to JSON when using ProducerTemplate

apache-camel

From my understanding you are trying to take a java object and convert it into a json string. So something like Gson would do wonders for you. Gson gson = new Gson(); String address = gson.toJson(address); Reference: https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html...

Mocking test class Spring camel

junit,apache-camel,spring-test

You can solve this by adding a setter in you class A. The application context will be loaded and A's B object will be injected by the bean declared in the XML but you can still override it with a mock of B by calling the newly defined setter in...

Pros and Cons of setting Lot of headers in Camel Exchange

apache-camel

If you have too many or too large, then by definition there will be problems. But let's consider simply many and large instead. Many Headers The headers in Camel are held in a java.util.TreeMap, so there may be some performance characteristics to consider with this data structure. Perhaps there may...

JBoss Fuse container: Karaf or Wildfly

apache-camel,jbossfuse

JBoss Fuse 6.2 which is being released this summer supports both EAP and Karaf. The 6.1 release and older are Karaf only.

Java & Apache-Camel: From direct-endpoint to file-endpoint

java,apache-camel

You can set the file name when you send using the producer template, as long as the header is propagated during the routing between the routes you are all fine, which Camel does by default. For example @Test public void testRoute() throws Exception { final String uri = "direct:start"; Map...

Refactoring some legacy camel code, is this code unnecessary or am I missing something?

jboss,apache-camel,jbossfuse

Yes the fabric endpoint has built in load balancing where it round robin among the online endpoints. But it does not have built in redelivery, so if you remove the above, you lose out the maximumFailoverAttempts functionality. But Apache Camel provides general error handler where you can also configure it...

Apache Camel FTP - How to start the route manually

ftp,apache-camel

What you need is Poll Enrich: from("direct:myRoute2") .pollEnrich("ftp://localhost") .to("mock:result"); Now trigger the direct (no matter what you send to it) and the ftp consumer starts....

Extract data from JSON in vanilla Java/Camel/Spring

apache-camel,activemq,jolokia

There is no JSOn library out of the box in Java itself. But there is a RFE to maybe add that in a future Java release, maybe Java 9. So if you want to parse json, you need to use a 3rd party library. So you better get your company...

Camel Delete File Exception

java,file,apache-camel

It seems there was a rogue stream that needed changing. I found this out using Process Explorer as it identified the same file twice. One lock was removed and another was not and from this I found an open stream that wasn't handled in the catch block.

Camel Thread Id changing when calling http component

java,redis,apache-camel

camel-ahc component is using non-blocking invocation, so the thread could be change in your camel route. You can consider to store the thread id as the exchange property (you can use it to release the redisLock in redisLockReleaseProcessor) or use other camel http component such as camel-http which is using...