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>
Related
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
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.
I am processing file in cluster environment. The cluster works fine. It is being processed on Only one server.
But on the second server It identifies as duplicates but still execute the form route delete=true
ERROR:
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot delete file:
I am setting header CamelRouteStop to true but the exchange still try's to delete a file, instead of stop executing the route.
All I need is to end the route if it is duplicate.
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="smb:url?delete=true"/>
<idempotentConsumer messageIdRepositoryRef="myRepo">
<header>messageId</header>
<setHeader headerName="fileExist">
<simple>true</simple>
</setHeader>
</idempotentConsumer>
<when>
<simple>${header.fileExist} == null</simple>
<log message="File ${header.CamelFileName} processing/processed by other Nodes - DUPLICATE" loggingLevel="INFO" />
<setHeader headerName="CamelRouteStop">
<simple <simple resultType="java.lang.Boolean">true</simple>>true</simple>
</setHeader>
</when>
</route>
</camelContext>
For CamelRouteStop you need to use setProperty, not setHeader.
In below route , i am using both "try..catch" and onexception features .
If there is any exception in my bean or the lines outside try block..file is moved to ".error" since i used moveFailed option but during exception which are caught by catch block generated by lines of try block,file is lost..
1.when server is down
2.when connection timeout
Please suggest the ways to preserve the file during such failures/exceptions
<camelContext streamCache="false" useMDCLogging="true" id="XXX" xmlns="http://camel.apache.org/schema/spring">
<streamCaching spoolDirectory="/tmp/cachedir/#camelId#/#uuid#" spoolUsedHeapMemoryThreshold="70" bufferSize="65536" anySpoolRules="true" id="myCacheConfig"/>
<onException >
<description>An exception was encountered.</description>
<exception>java.lang.Exception</exception>
<log message="somemessage" loggingLevel="INFO"/>
</onException>
<route >
<from uri="file:D:/Users/Desktop/src?moveFailed=.error" />
<transform>
<method ref="somebean" method="somemethod"/>
</transform>
<doTry>
<to uri="file:D:/Users/Desktop/src" />
<log message="transfered successfully" />
<doCatch>
<exception>java.lang.Exception</exception>
<log message="Exception occurred and Stopping the Route"/>
<to uri="controlbus:route?routeId=XXXX&action=stop"/>
<log message="Stopped the Route:XXX"/>
</doCatch>
</doTry>
</route>
Please suggest the ways to preserve the file during such failures/exceptions
Rethrow the exception in your docatch-block to reach the onException block.
<doCatch>
<exception>java.lang.Exception</exception>
<log message="Exception occurred and Stopping the Route"/>
<to uri="controlbus:route?routeId=XXXX&action=stop&async=true"/> // async=true to resume/finish this route
<log message="Stopped the Route:XXX"/>
<throwException exception="java.lang.Exception"/> // dont know the exact syntax in xml dsl
</doCatch>
I am trying to use sftp using camel, and getting jsch esception.
The route that I created for the SFTP -
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<package>myGroupId</package>
<route>
<from uri="file:src/srcData?noop=true"/>
<choice>
<when>
<xpath>/person/city = 'London'</xpath>
<to uri="file:src/targetData/UK"/>
</when>
<when>
<xpath>/person/city = 'Chicago'</xpath>
<to uri="file:src/targetData/US"/>
</when>
<when>
<xpath>/person/city = 'Tokyo'</xpath>
<to uri="sftp://XXXserverXXX:22/dir1/subdir?username=testUser?password=testPwd&binary=true"/>
</when>
<otherwise>
<to uri="file:src/targetData/OT"/>
</otherwise>
</choice>
</route>
</camelContext>
But with this configuration I am facing the following exception -
com.jcraft.jsch.JSchException: reject HostKey:
You should probably define a hostfile:
The "knownHostsFile" option should point to a ssh known hosts file with the public key of the host you are connecting to in it.
It's actually documented over here: http://camel.apache.org/ftp2.html