Failed to create route route-t: >>> OnException[[com.sample] -> - apache-camel

I am migrating from camle 2 to camel 3 as below configuration
<onException>
<exception>com.sample</exception>
<redeliveryPolicy disableRedelivery="true"/>
<handled>
<constant>true</constant>
</handled>
<log message="got here, before predict, ${exchangeProperty.firstCall}" loggingLevel="INFO"/>
<choice>
<when>
<method>operation</method>
<bean ref="Procs" method="SampleCommentRequestForError"/>
<setProperty propertyName="firstCall">
<constant>false</constant>
</setProperty>
<log message="got here, after predict, ${exchangeProperty.firstCallOf}" loggingLevel="INFO"/>
<to uri="direct:sample-comment"/>
</when>
</choice>
<bean ref="abc_errorhandler" method="abcException"/>
</onException>
and getting below exception :
Failed to create route route-nsm-client-call at: >>> OnException[[com.sample] -> [Log[got here, before predict, ${exchangeProperty.firstCall], Choice[[When[bean{abc} [From[direct:bbc-call ->... because of Bean language requires bean, beanType, or ref argument
Caused by: java.lang.IllegalArgumentException: Bean language requires bean, beanType, or ref argument
Any idea on this?

This will work camel 2.x operation but if you try to upgrade camel 3.x for existing code. So, in that case you need to change this code to like below sample . but rather than myBean provide whole class package path.
Try below sample code..
for more details, please check below official website..
https://camel.apache.org/components/3.17.x/languages/bean-language.html

Related

Camel blueprint <setHeader headerName="CamelHttpPath" id="_setHeader1"><el>${header.uriPattern}</el></setHeader> waiting for dependencies

I have the following Camel Context.
<camelContext id="_camuatomicservicecontext" xmlns="http://camel.apache.org/schema/blueprint">
<route id="_camuatomicserviceroute1">
<from id="_from1" uri="direct-vm:camuatomicservice">
<description>accepts vm messages directly </description>
</from>
<log id="_log1" message="Camu Atomic Service body = ${body}, header= ${header.uriPattern}"/>
<!-- <to id="_to1" uri="restlet:protocol:localhost:8189/"/> -->
<setHeader headerName="api.key" id="_setHeader1">
<constant>replace later with properties api.key Does not matter for this poc</constant>
</setHeader>
<setHeader headerName="CamelHttpPath" id="_setOutHeader1">
<el>${header.uriPattern}</el>
</setHeader>
<to id="_to1" pattern="InOut" uri="netty4-http:http:localhost:8189/path"/>
<log id="_log2" message="CamuAtomicService Response body ${body}"/>
</route>
</camelContext>
From the documentation I expect the CamelHttpPath header to override the endpoint configuration "/path" such that calling Facade Services can pass the header.uriPattern in and dynamically change the resource they want to access. The bundle worked fine until I added the setHeader for CamelHttpPath and now getting "Waiting for dependencies." I assume I need to install a feature, but Simple EL in other bundles on that server work already so not sure what feature I need to install.
Instead of I used and it worked fine. The choice was farther down in the options.

How can I fail a camel-route when exec returns nonzero?

I'm processing files with a Camel route like this:
<route>
<from uri="file:inbox?delete=true"/>
<recipientList>
<simple>exec://process.sh?args=inbox/${file:name}</simple>
</recipientList>
<log message="processed ${file:name}: ${body.stdout} ${body.stderr}"/>
</route>
Now I'd like the route to fail when process.sh finishes with nonzero exit-code. I found ${headers.CamelExecExitValue} but don't really know what to do with it.
In the example above, the file should not get deleted when process.sh fails. In my actual use-case, the route consumes files from a JMS queue and I want the file to stay in the queue. I think this can be done with <transacted/> but need to know how to fail the route.
I found How to define exception to be thrown through ref in Apache Camel which in combination with CamelExecExitValue lets me abort this way:
<route>
<from uri="file:inbox?delete=true"/>
<to uri="exec://process.sh"/>
<choice>
<when>
<simple>
${headers.CamelExecExitValue} != 0
</simple>
<throwException exceptionType="java.lang.RuntimeException" message="failed importing ${file:name}: ${body.stdout} ${body.stderr}"/>
</when>
</choice>
<log message="processed ${file:name}"/>
</route>
A bit verbose for my taste but works fine.

Is HttpOperationFailedException available with apache's http4?

I'm using apache camel http4 for http server.
JBoss Fuse Karaf container 6.3.0.redhat-310
has bundled camel-core 2.17 - (2.17.0.redhat-630310)
I'm trying to use exception class
org.apache.camel.component.http.HttpOperationFailedException
to catch HTTP response exceptions.
However, the associated routes fail to start due to
Caused by: java.lang.ClassNotFoundException: org.apache.camel.component.http.HttpOperationFailedException
I've added as dependency camel-http, with no change, still fails.
It doesn't seem that this class is included anymore?
Q. Is the Caused by: java.lang.ClassNotFoundException: org.apache.camel.component.http.HttpOperationFailedException available to http4 servers, or does anyone know what I'm doing wrong.
<when id="w2">
<ognl>request.headers.TKNDB == true</ognl>
<process id="a3" ref="assetUploadProcessor"/>
<setHeader headerName="CamelHttpUri" id="h1">
<simple>${header.UPLOADURL}</simple>
</setHeader>
<setHeader headerName="CamelHttpMethod" id="h2">
<constant>GET</constant>
</setHeader>
<doTry id="_doTry1">
<to id="http4-1" uri="http4://d1e53858-2903-4c21-86c0-95edc7a5cef2.predix-uaa.run.aws-usw02-pr.ice.predix.io:443/oauth/token?throwExceptionOnFailure=false"/>
<doCatch id="_doCatch1">
<exception>org.apache.camel.component.http.HttpOperationFailedException</exception>
<onWhen>
<simple>${header.HTTP_RESPONSE_CODE} range "400..600"</simple>
</onWhen>
<log id="_log2" loggingLevel="ERROR" message="HTTP FAILURE - HTTP Response Code: ${header.HTTP_RESPONSE_CODE}"/>
</doCatch>
</doTry>
<log id="l1" loggingLevel="INFO" message="JSON Response: ${body}"/>
<process id="jsonmapperassets" ref="jsonMapperAssets"/>
<split id="as1"
YEILDS
... because of org.apache.camel.component.http.HttpOperationFailedException
Caused by: java.lang.ClassNotFoundException: org.apache.camel.component.http.HttpOperationFailedException
I've also tried using the Global exception handler using
<exception>org.apache.camel.component.http.HttpOperationFailedException</exception>
<continued>true</continued>
</onException>
but, here I get an ERROR exception saying Continued cannot have children????
thank you!
I was facing the same issue, the correct class is
org.apache.camel.http.common.HttpOperationFailedException
it should there inside the http4 component
I just used the simple language to achieve what I needed. I simply need to continue the route after an http error code not OK or 200. this approach works, but I would love to understand how to accomplish this with my original question.
can this be done with camel's http4 component, it appears these classes are not part of it anymore?
also, if someone can, what is wrong with my onException clause?
thanks!
this is what I did
<to id="http4-1" uri="http4://d1e53858-2903-4c21-86c0-95edc7a5cef2.predix-uaa.run.aws-usw02-pr.ice.predix.io:443/oauth/token?throwExceptionOnFailure=false"/>
<choice>
<when>
<simple>${header.CamelHttpResponseCode} == '200'</simple>
<log id="l1" loggingLevel="INFO" message="JSON Response Body: ${body}"/>
<process id="jsonmapperassets" ref="jsonMapperAssets"/>
<split id="as1"
strategyRef="tsAggregationStrategy" streaming="true">
<simple>${body}</simple>
<log id="al6" loggingLevel="INFO" message="Split line ${body}"/>
<process id="p1" ref="getAssets"/>
</split>
<process id="getassetlisting" ref="getAssetListing"/>
<split id="as2"
strategyRef="tsAggregationStrategy" streaming="true">
<simple>${body}</simple>
<log id="sl2" loggingLevel="INFO" message="Split assets ${body}"/>
<process id="gtags" ref="setTagURL"/>
<to id="surl" ref="setURL"/>
</split>
</when>
<otherwise>
<log id="logError1" loggingLevel="ERROR" message="HTTP FAILURE - Response Code: ${header.CamelHttpResponseCode}"/>
<log id="logError2" loggingLevel="ERROR" message="HTTP FAILURE - Response: ${header.CamelHttpResponseText}"/>
</otherwise>
</choice>

Camel Docatch not firing

So I have the following route (Camel 2.20.0)
I was working on a global <onException> block for a new route. For some reason it wasn't firing, so I moved the items to a doTry/doCatch within one specific route just to play with the error handeling.
<camelContext xmlns="http://camel.apache.org/schema/spring" id="jobfeedCamelContext">
<route id="testError">
<from uri="timer://runOnce?repeatCount=1&delay=5000" />
<doTry>
<throwException exceptionType="java.lang.Throwable"/>
<to uri="errorBean"/> <!-- bean does nothing but explicitly throws java.lang.Throwable -->
<doCatch>
<exception>java.lang.Throwable</exception>
<log message="### exception" />
</doCatch>
</doTry>
<log message="### out of try" />
</route>
</camelContext>
For output I get the stack trace from the beans java.Lang.Throwable (but no stacktrace is generated for the<throwException exceptionType="java.lang.Throwable"/>. I do not get my "### exception" log entry in any scenario, but I do get the "### out of try" log entry.
Have used this functionality in other routes on older version of camel, so I can't really see where I am going wrong. Anyone have any ideas? I've turned on route tracing and there is nothing helpful.
<throwException exceptionType="java.lang.Throwable" message="some text"/>

Camel ErrorHandler not invoking

I'm calling out to a WS using cxf:cxfEndpoint and its working fine. I want to catch any exceptions using onException or something similar. For some reason its not working. I have set the dataFormat to PAYLOAD, handleFault attribute on the route and/or the camel context to true. The web service is not running so I'm expecting the exception to be caught but its not working. Same issue with unmarshalling of the XML.
When I throw an exception using it gets caught successfully using java.lang.Exception and written to my dummy exception queue... but when the webservice is down or I pass in some invalid XML and the marshalling fails then an exception gets thrown but not caught.
Is there anything else to be aware of?
EDIT: Included the code for unmarshaling. Switched to using Try/Catch and when i pass in invalid XML the exception does get caught during the junit testing but does not get caught at runtime
<route>
<from uri="jmsamq:In"/>
<doTry>
<unmarshal>
<jaxb contextPath="outbound.message"/>
</unmarshal>
<doCatch>
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<transform>
<simple>Mapping Failed</simple>
</transform>
<to uri="jmsamq:errorqueue1"/>
</doCatch>
</doTry>
<log message="${body}"/>
<multicast stopOnException="true">
<to uri="direct:webservice"/>
<to uri="direct:myqueue"/>
</multicast>
</route>
the incorrect camel-context XML file was being used at runtime.. ignore question!

Resources