Search code examples
apache-camelnettyhl7spring-camel

Camel HL7 - ClosedChannelException while sending ACK back to the client


I'm building a HL7 listener using netty4 and processing HL7 messages. Once succesfully processed an ACK is sent back.

 from("hl7NettyListener") 
      .routeId("route_hl7listener")
        .startupOrder(997)
          .unmarshal()
           .hl7(false)               
           .to("direct:a");



    from("direct:a") 
        .doTry()
            .to("bean:processHL7?method=process")        
        .doCatch(HL7Exception.class)
            .to("direct:ErrorACK")
            //.transform(ack())
            .stop()
        .end()
        .transform(ack())       
        .wireTap("direct:b");

This is working fine in my local eclipse. I fire a HL7 message and I get a ACk back.

But i package this application into a jar and put it on my server and then try doing a

cat example.hl7 | netcat localhost 4444 (to fire a HL7 message to port 4444 on linux env)

I dont get an ACK back. I get a closedconnection exception.

DEBUG NettyConsumer - Channel: [id: 0xdf13b06b, L:0.0.0.0/0.0.0.0:4444] writing body: MSH|^~\&|Karisma||Kestral|Kestral|20180309144109.827+1300||ACK^R01|701||2.3.1 2018-03-09 14:41:09,838 [ad #3 - WireTap] DEBUG WireTapProcessor - >>>> (wiretap) direct:b Exchange[] 2018-03-09 14:41:09,839 [ServerTCPWorker] DEBUG NettyConsumer - Caused by: [org.apache.camel.CamelExchangeException - Cannot write response to null. Exchange[ID-annan06-56620-1520559639101-0-2]. Caused by: [java.nio.channels.ClosedChannelException - null]] org.apache.camel.CamelExchangeException: Cannot write response to null. Exchange[ID-annan06-56620-1520559639101-0-2]. Caused by: [java.nio.channels.ClosedChannelException - null] at org.apache.camel.component.netty4.handlers.ServerResponseFutureListener.operationComplete(ServerResponseFutureListener.java:54) at org.apache.camel.component.netty4.handlers.ServerResponseFutureListener.operationComplete(ServerResponseFutureListener.java:36) at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:514) at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:488) at io.netty.util.concurrent.DefaultPromise.access$000(DefaultPromise.java:34) at io.netty.util.concurrent.DefaultPromise$1.run(DefaultPromise.java:438) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:440) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) at java.lang.Thread.run(Thread.java:748) Caused by: java.nio.channels.ClosedChannelException at io.netty.channel.AbstractChannel$AbstractUnsafe.write(...)(Unknown Source)


Solution

  • That worked. It was failing because netcat was immediately closing the connection. Had put a ”netcat -i 5 localhost” for netcat to wait for 5 secs and successfully received the ACK back.