How do I shutdown and throw an exception when an Apache Camel FTP Route has a connection error? - apache-camel

I have the following Apache Camel FTP file download Route:
from(downloadUri)
.routeId(routeId)
.aggregate(new CustomListAggregationStrategy())
.constant(true)
.completionFromBatchConsumer()
.to("direct:" + routeDestinationId);
I add this Route to a context and then request data with a ConsumerTemplate:
List<ResultType> result = consumerTemplate.receiveBody(CAMEL_DIRECT_OBJECT_PREFIX
+ routeId, List.class);
When a connection error occurs (e.g. unknown host, host not reachable), I want to shutdown the Route and throw an exception after the "receiveBody" line where I try to read the downloaded files.
How can I do this?
I tried an onException-handler for the Route where I added a process block to it and called exchange.getContext().stop(); in that processing block. But the application just keeps running.

Stopping a route during routing an existing message is a bit tricky. The reason for that is Camel will Graceful Shutdown the route you are stopping. And if you do that while a message is being routed the Graceful Shutdown will try to wait until that message has been processed.
You can find more info here : https://camel.apache.org/manual/faq/how-can-i-stop-a-route-from-a-route.html

Related

What is the reason of below error in vespa.ai?

We are facing this below error in Vespa, after restarting the cluster we got this below issue.
1600455444.680758 10.10.000.00 1030/1 container Container.com.yahoo.filedistribution.fileacquirer.FileAcquirerImpl info Retrying waitFor for file 'e0ce64d459828eb0': 103 -- Request timed out after 60.0 seconds.
1600455446.819853 10.10.000.00 32752/146 configproxy configproxy.com.yahoo.vespa.filedistribution.FileReferenceDownloader info Request failed. Req: request filedistribution.serveFile(e0ce64d459828eb0,0)\nSpec: tcp/10.10.000.00:19070, error code: 103, set error for connection and use another for next request
We faced this issue second time, earlier we kept it ideal and it was resolved automatically, but this time it is persistent.
Looks like the configproxy is unable to talk to the config server (which is listening to port 19070 on the same host: Spec: tcp/10.10.000.00:19070). Is the config server really runnning and listening on port 19070 on this host? Try running the vespa-config-status script to see if all is well with the config system

gatling-3.0.0: javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate

i am using Gatling 3.0.0 as a plugin in SBT i am configuring the browser as given in the https://gatling.io/docs/current/http/recorder/#recorder under configuration heading after then when i start the recorder using gatling:startRecorder in sbt and try to hit my website https://www.example.com/ Firefox displayed
Did Not Connect: Potential Security Issue
Firefox detected a potential security threat and did not continue to www.mydomain.com because this website requires a secure connection.
www.mydomain.com has a security policy called HTTP Strict Transport Security (HSTS), which means that Firefox can only connect to it securely. You can’t add an exception to visit this site
and here are the exception logs
ioEventLoopGroup-2-1] DEBUG io.netty.handler.ssl.util.InsecureTrustManagerFactory - Accepting a server certificate: CN=www.mydomain.com
14:44:55.604 [nioEventLoopGroup-4-2] DEBUG io.gatling.recorder.http.Mitm$ - Open new server channel
14:44:55.607 [nioEventLoopGroup-4-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:472)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:128)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:279)
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:181)
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164)
at java.base/sun.security.ssl.SSLEngineImpl.decode(SSLEngineImpl.java:672)
at java.base/sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:627)
at java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:443)
at java.base/sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:422)
at java.base/javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:634)
at io.netty.handler.ssl.SslHandler$SslEngineType$3.unwrap(SslHandler.java:294)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1297)
at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1199)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1243)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:441)
... 16 common frames omitted
14:44:55.609 [recorder-akka.actor.default-dispatcher-4] DEBUG io.gatling.recorder.http.flows.SecuredNoProxyMitmActor - Server channel 6acf48e4 was closed while in Connected state, closing
14:44:55.622 [recorder-akka.actor.default-dispatcher-2] DEBUG io.gatling.recorder.http.flows.PlainNoProxyMitmActor - serverChannel=8d7b2171 received init request http://detectportal.firefox.com/success.txt, connecting
14:44:55.622 [recorder-akka.actor.default-dispatcher-2] DEBUG io.gatling.recorder.http.flows.PlainNoProxyMitmActor - Connecting to Remote(detectportal.firefox.com,80)
14:44:55.629 [recorder-akka.actor.default-dispatcher-4] INFO akka.actor.RepointableActorRef - Message [io.gatling.recorder.http.flows.MitmMessage$ClientChannelInactive] without sender to Actor[akka://recorder/user/$a#-1754914561] was not delivered. [1] dead letters encountered. If this is not an expected behavior, then [Actor[akka://recorder/user/$a#-1754914561]] may have terminated unexpectedly, This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
14:44:55.655 [nioEventLoopGroup-2-2] DEBUG io.gatling.recorder.http.Mitm$ - Open new client channel
How did you configured proxy in your firefox? Do you have proxy only for http or also for https? If you are proxing also https requests then in recorder settings you need to switch "HTTPS mode" to "Certificate Authority". There will be a button to generate new certificate authority file that you need to import to your browser (Preferences / Privacy & Security / Certificates / View certificates / Import). After that your browser will know that it can trust Gatling proxy server and you should be able to proxy also ssl requests.

Apache Camel shuts down right after start, no reason logged, no exception thrown

I observe, that errors in the route definition lead to a silent shutdown of the application, caused by Camel. How can I configure Camel to telling me what exactly it dislikes.
Simple example: Assigning duplicate route names
If I define two routes with different names [by using: .id ("route name")], then the application starts and reports readiness.
If I mistakenly use a name twice, the application fails to start completely and Camel announces:
Apache Camel 2.22.0 (CamelContext: camel-1) is shutting down
Apache Camel 2.22.0 (CamelContext: camel-1) uptime 0.332 seconds
Apache Camel 2.22.0 (CamelContext: camel-1) is shutdown in 0.017 seconds
Stopping service [Tomcat]
HikariPool-1 - Shutdown initiated ...
HikariPool-1 - Shutdown completed.
Process finished with exit code 0
The exit code 0 seems to suggest a non-exceptional shutdown.
The same early shutdown happened, when I added a CronScheduledRoutePolicy to a route. [e.g. with .routePolicy (policy)]
It shuts down if I add a default instance or if I make any settings to the policy.
I increased the log level and got significantly more background noise, but no new findings. [using application.yml: logging: level: ROOT: DEBUG]
A try catch around the route definition didn't help. No exception was caught at the time of the route definition.
I tried to set the CronScheduledRoutePolicy an exception handler. [E.g. with policy.setExceptionHandler (myCamelExceptionHandlerLoggingEverything)]
Nothing got logged. No breakpoint was hit.
I would be very grateful for your help or references to any solutions.
Ralf
There are multiple ways to print an exact error and it depends on how developer design app/class with the camel route. I have mentioned below example which will give exact error you are looking for.
public class CamelPrintingExample {
public static void main(String[] args) throws Exception {
CamelContext camelContext = new DefaultCamelContext();
try {
camelContext.addRoutes(new RouteBuilder() {
public void configure() {
from("file:C:\\input\\").routeId("demo")
.to("file:C:\\output\\").end();
from("file:C:\\input\\").routeId("demo")
.to("file:C:\\output\\").end();
}
});
camelContext.start();
Thread.sleep(300000);
camelContext.stop();
} catch (Exception camelException) {
camelException.printStackTrace();
}
}
}
By running this I got below error.
org.apache.camel.FailedToStartRouteException: Failed to start route demo because of duplicate id detected: demo. Please correct ids to be unique among all your routes.
You can try defining a custom shutdown strategy. Read here
Try to add this in your route and then start it:
getContext().setTracing(true);
P.S. a problem could also be in your error handler

WebSocket Request (xhr_send) getting stalled (Tomcat and Apache HTTP)

My application used sockjs & Application is running on Tomcat 8 and APACHE HTTP as front end web server. I have observed that xhr_send request getting stalled and so hangs the application. On Chrome developer console, received following error
when xhr_send request stalled I never received CONNECTED response.
I used following code to setup websocket
socket = new SockJS(applicationMainService.getUrl()+'/ws');
stompClient = Stomp.over(socket);
Also received following error in Tomcat logs
[org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler#1e7904b0]: org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS request, uri=https://pods.jlrint.com:443/PODSWeb/ws/112/fvi5za3c/websocket; nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException: WebSocket handshake failure; nested exception is java.lang.UnsupportedOperationException: HTTP upgrade is not supported by the AJP protocol
06:35:04.129 [ajp-nio-8009-exec-11] DEBUG o.s.web.servlet.DispatcherServlet - Could not complete request
org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS request, uri=https://xyzabc.com:443/MyRoot/ws/112/fvi5za3c/websocket; nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException: WebSocket handshake failure; nested exception is java.lang.UnsupportedOperationException: HTTP upgrade is not supported by the AJP protocol
at org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler.handleRequest(SockJsHttpRequestHandler.java:91) ~[spring-websocket-4.0.2.RELEASE.jar:4.0.2.RELEASE]
Please help.

IBM MQ ISSUE in Apache Camel because Spring JMS Listener

I am new to IBM MQ with Apache camel. below is my configuration
<from IBM MQ>
<parallel>
<to ACTIVE MQ>
<to IBM MQ>
</parallel>
my application is running in Spring Container. some time I am getting this below warning, hence My route is not working ( IBM MQ is not reading msg). for getting warning, Route is not working .
Exception
org.springframework.jms.listener.DefaultMessageListenerContainer handleListenerSetupFailure
WARNING: Setup of JMS message listener invoker failed for destination 'temporary' - trying to recover. Cause: User XXXXXX is not authorized to create: temp-queue://ID:IP Address-1:26:1
Feb 20, 2015 2:59:07 AM org.springframework.jms.listener.DefaultMessageListenerContainer refreshConnectionUntilSuccessful
INFO: Successfully refreshed JMS Connection
Feb 20, 2015 2:59:08 AM org.springframework.jms.listener.DefaultMessageListenerContainer handleListenerSetupFailure
WARNING: Setup of JMS message listener invoker failed for destination 'temporary' - trying to recover. Cause: JMSWMQ2008: Failed to open MQ queue 'SYSTEM.DEFAULT.MODEL.QUEUE'.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2035' ('MQRC_NOT_AUTHORIZED').**
I am using Active & IBM MQ, why Spring JMS Listener is throwing warning ?
You should make sure you don't have request-reply specified as exchange pattern.
I would explicitly state that the message should be "InOnly".
<inOnly uri="ACTIVEMQ..."/>
<inOnly uri="IBM MQ..."/>
If you intend to do a request/reply, then you need to make sure your WebSphere MQ user has rights to access SYSTEM.DEFAULT.MODEL.QUEUE.
Something like this should allow authority:
setmqaut -m QMGR -t q -n SYSTEM.DEFAULT.MODEL.QUEUE -g mygroup +dsp +inq +get

Resources