0 Replies Latest reply on May 30, 2016 12:19 PM by smogare

    Camel Servlet continuation Exception - How to catch it and send customized response to caller?

    smogare

      Hello,

       

      I have a major issue in a complex integration environment.

      In my environment, I have series of fuse routes listening on different network ports, they perform simple routing and if needed transformation of message.

      I am using jetty configuration as below:

       

      FuseAddress=jetty:http://0.0.0.0:11000/v1/functionA?matchOnUriPrefix=true&httpClient.timeout=60000

      JavaBlockAddress=jetty:http://JbossServerIP:8080/functionAImplementation/v1?bridgeEndpoint=true

      brokerUrl=tcp://localhost:61616

      brokerUsername=admin

      brokerPassword=secret

       

      My First Question: will the timeout of 1 min really works? Or is there any other better way of configuring the timeouts?

      What I want from this is, if I do not get a response from endpoint within a minute, I want to catch this as an exception and customize the response in velocity template and send it back to caller.

       

      Secondly, my biggest issue at this moment is, one of the fuse route in series is dependent on third party to respond.

      Recently, the third party interface was taking it's own sweet time to respond back and the fuse started throwing the 503 response back, However I would like to catch and handle this by sending customize response back to caller. Secondly, it also gave "camel servlet continuation exception".

       

      I am using the default error handler, no redelivery (I do not want to redeliver) and doTry and doCatch statements in my route.

       

      Below is a snippet:

       

      <?xml version="1.0" encoding="UTF-8"?>

       

       

      <beans xmlns="http://www.springframework.org/schema/beans"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ctx="http://www.springframework.org/schema/context"

        xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:tem="http://tempuri.org/"

        xmlns:camel="http://camel.apache.org/schema/spring"

        xmlns:spring-security="http://www.springframework.org/schema/security"

        xsi:schemaLocation="

          http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd

             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

             http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd

             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

             http://camel.apache.org/schema/spring-security http://camel.apache.org/schema/spring-security/camel-spring-security.xsd

             http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">

       

       

        <camelContext id="myContext" xmlns="http://camel.apache.org/schema/spring">

        

      <route id="1">

               <from uri="direct:In" /> 

        <doTry>

        <convertBodyTo type="java.lang.String" charset="ISO-8859-1" />

      ..... Set the headers

      <to uri={someURI}>

      <doCatch>
      <exception>java.net.ConnectException</exception>
      <camel:log
      message="${headers.routeTenant}::Route failed Connection Exception::ExchangeId::${exchangeId}" />
      <setHeader headerName="Content-Type">
      <constant>application/json</constant>
      </setHeader>
      <camel:setHeader headerName="operationType">
      <camel:constant>CONNECTION_TIMEOUT</camel:constant>
      </camel:setHeader>
      <setHeader headerName="elaborationStartDate">
      <simple>${date:now:yyyy-MM-dd'T'HH:mm:ss}</simple>
      </setHeader>
      <removeHeaders pattern="CamelHttp*" />
      <convertBodyTo type="java.lang.String" />
      <to uri="velocity:/velocity/errors/templateError.vm" />
      <to uri="log:Exception"/>
      </doCatch>
      <doCatch>
      <exception>org.apache.camel.ExchangeTimedOutException</exception>
      <camel:log
      message="${headers.routeTenant}::Route failed TimeOut Exception::ExchangeId::${exchangeId}" />
      <setHeader headerName="Content-Type">
      <constant>application/json</constant>
      </setHeader>
      <camel:setHeader headerName="operationType">
      <camel:constant>EXCHANGE_TIMEOUT</camel:constant>
      </camel:setHeader>
      <setHeader headerName="elaborationStartDate">
      <simple>${date:now:yyyy-MM-dd'T'HH:mm:ss}</simple>
      </setHeader>
      <removeHeaders pattern="CamelHttp*" />
      <convertBodyTo type="java.lang.String" />
      <to uri="velocity:/velocity/errors/templateError.vm" />
      <to uri="log:Exception"/>
      </doCatch>
      <doCatch>
      <exception>org.apache.camel.CamelException</exception>
      <camel:log
      message="${headers.routeTenant}::Route failed CamelException::ExchangeId::${exchangeId}" />
      <setHeader headerName="Content-Type">
      <constant>application/json</constant>
      </setHeader>
      <camel:setHeader headerName="operationType">
      <camel:simple>${exception.message}</camel:simple>
      </camel:setHeader>
      <setHeader headerName="elaborationStartDate">
      <simple>${date:now:yyyy-MM-dd'T'HH:mm:ss}</simple>
      </setHeader>
      <removeHeaders pattern="CamelHttp*" />
      <convertBodyTo type="java.lang.String" />
      <to uri="velocity:/velocity/errors/templateError.vm" />
      <to uri="log:Exception"/>
      </doCatch>
      <doCatch>
      <exception>java.lang.Exception</exception>
      <camel:log
      message="${headers.routeTenant}::Route failed Exception::ExchangeId::${exchangeId}" />
      <setHeader headerName="Content-Type">
      <constant>application/json</constant>
      </setHeader>
      <camel:setHeader headerName="operationType">
      <camel:simple>${exception.message}</camel:simple>
      </camel:setHeader>
      <setHeader headerName="elaborationStartDate">
      <simple>${date:now:yyyy-MM-dd'T'HH:mm:ss}</simple>
      </setHeader>
      <removeHeaders pattern="CamelHttp*" />
      <convertBodyTo type="java.lang.String" />
      <to uri="velocity:/velocity/errors/templateError.vm" />
      <to uri="log:Exception"/>
      </doCatch>
      </doTry>

       

      surprisingly, I am not able to handle the exception mentioned above, which I felt like it will be Exchange TImeout one,

       

      Can I get an expert advice?

       

      Regards,

      Sagar Mogare.