Unable to catch and deal with the ProtocolDecoderException thrown by Mina in our camel route

141 views
Skip to first unread message

kriti tandon

unread,
May 5, 2016, 4:01:19 AM5/5/16
to ipf-user
Hi All,

Following is a code snippet from the camel route we have-


class CacheRouteBuilder extends CustomRouteBuilder {
-------
-------

void configure() throws DataException, DataExchangeException, Exception{
//Refer CCG Customizer Parser
def Parser ccgParser = new CAPIPipeParser()
/**
* Code for Exception Handling
*
*/
onException(Exception.class)
.handled(true)
.process{
Throwable caused = it.getProperty(it.EXCEPTION_CAUGHT, Exception.class)
logger.error("Exception in Cache Route : ",caused)
def ack = createNakMessage(it,caused.getMessage())
it.out.body = ack
logger.debug("after setting nack....")
}
.marshal().hl7();

/**
* Step 1 - read input from TCP MINA Endpoint
* Step 2 - un-marshal the input 
* Step 3 - save the original message 
* Step 4 - forward to direct endpoint
*/
from('mina2:tcp://' + incomingHL7Listener.getIp() + ':' + incomingHL7Listener.getPort() + '?codec=#hl7codec')
        
//convert to UTF-8 string
.transmogrify('hl7Transmogrifier').staticParams(incomingHL7Listener.getCharset())
------------
                                ------------
                                ------------
.to('direct:parsedHL7');
}
}

In the spring configuration, hl7codec is configured to take camel's HL7MLLPCodec-

<bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
<property name="charset" value="UTF-8" />
</bean>

Due to some erroneous messages being sent to this route, whenever Mina is not able to decode the message, it throws a Runtime exception which actually comes as a warning to our code. Following are the details of the exception that can be seen in our logs-

2016-05-05 11:58:00 WARN  [org.apache.camel.component.mina2.Mina2Consumer]  "Closing session as an exception was thrown from MINA" 
2016-05-05 11:58:00 WARN  [org.apache.mina.core.filterchain.DefaultIoFilterChain]  "Unexpected exception from exceptionCaught handler." 
org.apache.camel.CamelException: org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.RuntimeException: java.nio.charset.MalformedInputException: Input length = 2 (Hexdump: 0B 4D 53 48 7C 5E 7E 5C 26 7C 52 49 53 7C 46 41 43 49 4C 49 54 59 7C 44 4D 57 4C 7C 47 45 50 41 43 53 7C 32 30 31 36 30 35 30 33 31 31 32 31 32 30 7C 34 30 36 35 7C 4F 52 4D 5E 4F 30 31 7C 31 33 31 39 39 31 7C 50 7C 32 2E 33 0D 50 49 44 7C 7C 7C 48 4E 45 31 33 35 37 35 31 33 34 34 36 5E 5E 5E 50 49 5E 50 49 7C 7C 4C 4F 56 44 41 48 4C 5E 43 48 41 52 4C 4F 54 54 45 5E 4D 41 52 49 45 5E 5E 5E 5E 4C 7C 7C 31 39 35 38 30 34 33 30 7C 46 7C 7C 43 7C 7C 7C 32 36 32 36 33 37 32 32 32 38 5E 50 52 4E 5E 50 48 7C 7C 7C 7C 7C 31 30 33 36 39 38 39 34 36 5E 5E 5E 41 4E 5E 41 4E 0D 50 56 31 7C 7C 4F 7C 41 55 53 5E 20 5E 20 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 4E 7C 7C 7C 31 30 33 36 39 38 39 34 36 5E 5E 5E 56 4E 5E 56 4E 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 32 30 31 36 30 35 30 33 31 31 32 31 32 30 0D 4F 52 43 7C 4E 57 7C 31 30 30 30 30 35 36 38 37 34 5E 43 43 47 50 4C 4F 52 7C 31 30 30 30 30 35 36 38 37 34 5E 43 43 47 46 4C 4F 52 7C 7C 49 50 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 41 55 53 0D 4F 42 52 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 20 7C 7C 7C 7C 7C 31 30 30 30 30 35 36 38 37 34 7C 31 30 30 30 30 35 36 38 37 34 7C 31 30 30 30 30 35 36 38 37 34 7C 20 7C 7C 7C 7C 7C 7C 5E 5E 5E 32 30 31 36 30 35 30 33 31 31 33 30 30 30 5E 5E 52 7C 7C 7C 7C 5E 69 6E 63 69 64 65 6E 74 61 6C 20 68 79 70 6F 61 74 74 65 6E 75 61 74 69 6E 67 20 6C 69 76 65 72 20 6C 65 73 69 6F 6E 73 20 6F 6E 20 EF BE 3F 20 43 54 20 73 63 61 6E 20 69 6E 20 32 30 31 30 2C 0D 5A 44 53 7C 31 2E 32 2E 38 34 30 2E 31 31 33 36 31 39 2E 32 2E 31 38 32 2E 31 30 38 30 38 36 31 37 39 35 33 31 36 35 2E 31 34 36 32 32 39 32 34 39 35 2E 31 31 38 32 31 35 0D 5A 46 4C 7C 7C 55 4E 4B 4E 4F 57 4E 5F 57 4C 43 0D 5A 44 54 7C 7C 7C 7C 7C 32 7C 69 6E 63 69 64 65 6E 74 61 6C 20 68 79 70 6F 61 74 74 65 6E 75 61 74 69 6E 67 20 6C 69 76 65 72 20 6C 65 73 69 6F 6E 73 20 6F 6E 20 EF BE 3F 20 43 54 20 73 63 61 6E 20 69 6E 20 32 30 31 30 2C 20 0D 1C 0D)
at org.apache.camel.component.mina2.Mina2Consumer$ReceiveHandler.exceptionCaught(Mina2Consumer.java:314)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.exceptionCaught(DefaultIoFilterChain.java:672)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:461)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:760)
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:93)
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:769)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:761)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:703)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.RuntimeException: java.nio.charset.MalformedInputException: Input length = 2 (Hexdump: 0B 4D 53 48 7C 5E 7E 5C 26 7C 52 49 53 7C 46 41 43 49 4C 49 54 59 7C 44 4D 57 4C 7C 47 45 50 41 43 53 7C 32 30 31 36 30 35 30 33 31 31 32 31 32 30 7C 34 30 36 35 7C 4F 52 4D 5E 4F 30 31 7C 31 33 31 39 39 31 7C 50 7C 32 2E 33 0D 50 49 44 7C 7C 7C 48 4E 45 31 33 35 37 35 31 33 34 34 36 5E 5E 5E 50 49 5E 50 49 7C 7C 4C 4F 56 44 41 48 4C 5E 43 48 41 52 4C 4F 54 54 45 5E 4D 41 52 49 45 5E 5E 5E 5E 4C 7C 7C 31 39 35 38 30 34 33 30 7C 46 7C 7C 43 7C 7C 7C 32 36 32 36 33 37 32 32 32 38 5E 50 52 4E 5E 50 48 7C 7C 7C 7C 7C 31 30 33 36 39 38 39 34 36 5E 5E 5E 41 4E 5E 41 4E 0D 50 56 31 7C 7C 4F 7C 41 55 53 5E 20 5E 20 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 4E 7C 7C 7C 31 30 33 36 39 38 39 34 36 5E 5E 5E 56 4E 5E 56 4E 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 32 30 31 36 30 35 30 33 31 31 32 31 32 30 0D 4F 52 43 7C 4E 57 7C 31 30 30 30 30 35 36 38 37 34 5E 43 43 47 50 4C 4F 52 7C 31 30 30 30 30 35 36 38 37 34 5E 43 43 47 46 4C 4F 52 7C 7C 49 50 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 41 55 53 0D 4F 42 52 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 7C 20 7C 7C 7C 7C 7C 31 30 30 30 30 35 36 38 37 34 7C 31 30 30 30 30 35 36 38 37 34 7C 31 30 30 30 30 35 36 38 37 34 7C 20 7C 7C 7C 7C 7C 7C 5E 5E 5E 32 30 31 36 30 35 30 33 31 31 33 30 30 30 5E 5E 52 7C 7C 7C 7C 5E 69 6E 63 69 64 65 6E 74 61 6C 20 68 79 70 6F 61 74 74 65 6E 75 61 74 69 6E 67 20 6C 69 76 65 72 20 6C 65 73 69 6F 6E 73 20 6F 6E 20 EF BE 3F 20 43 54 20 73 63 61 6E 20 69 6E 20 32 30 31 30 2C 0D 5A 44 53 7C 31 2E 32 2E 38 34 30 2E 31 31 33 36 31 39 2E 32 2E 31 38 32 2E 31 30 38 30 38 36 31 37 39 35 33 31 36 35 2E 31 34 36 32 32 39 32 34 39 35 2E 31 31 38 32 31 35 0D 5A 46 4C 7C 7C 55 4E 4B 4E 4F 57 4E 5F 57 4C 43 0D 5A 44 54 7C 7C 7C 7C 7C 32 7C 69 6E 63 69 64 65 6E 74 61 6C 20 68 79 70 6F 61 74 74 65 6E 75 61 74 69 6E 67 20 6C 69 76 65 72 20 6C 65 73 69 6F 6E 73 20 6F 6E 20 EF BE 3F 20 43 54 20 73 63 61 6E 20 69 6E 20 32 30 31 30 2C 20 0D 1C 0D)
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:242)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)
at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:109)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireMessageReceived(DefaultIoFilterChain.java:410)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:710)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:664)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:653)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:67)
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1124)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
... 1 more
Caused by: java.lang.RuntimeException: java.nio.charset.MalformedInputException: Input length = 2
at org.apache.camel.component.hl7.HL7MLLPDecoder.writeString(HL7MLLPDecoder.java:79)
at org.apache.camel.component.hl7.HL7MLLPDecoder.doDecode(HL7MLLPDecoder.java:54)
at org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtocolDecoder.java:176)
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:232)
... 15 more
Caused by: java.nio.charset.MalformedInputException: Input length = 2
at java.nio.charset.CoderResult.throwException(Unknown Source)
at org.apache.mina.core.buffer.AbstractIoBuffer.getString(AbstractIoBuffer.java:1768)
at org.apache.camel.component.hl7.HL7MLLPDecoder.writeString(HL7MLLPDecoder.java:70)
... 18 more

We need to be able to catch this exception through our code/route and send a negative acknowledgement back to the sending system. The onException block of code above is not being able to do that for us. In case an exception is thrown at route level, camel actually processes the onException block but in our case, this exception is thrown by Mina's Codec itself and there is no way we can get the system diagnose it and break out from there.

Kindly let us know if there are any suggestions around this issue. Thanks in advance!

Regards,
Kriti

Dmytro Rud

unread,
May 5, 2016, 4:15:49 AM5/5/16
to ipf-...@googlegroups.com
Hello Kriti,

From a Camel route you can handle only exceptions which occur within the route, while the Mina exception occurs before the route starts.  What you can do: deploy a custom interceptor between Mina and Camel, similarly to org.openehealth.ipf.platform.camel.ihe.mllp.core.intercept.consumer.ConsumerAuthenticationFailureInterceptor.  Documentation: http://openehealth.org/display/ipf2/mllp-common-interceptors.

Best regards
Dmytro



--
You received this message because you are subscribed to the Google Groups "ipf-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ipf-user+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kriti tandon

unread,
May 5, 2016, 5:08:52 AM5/5/16
to ipf-user
Thanks a lot for the suggestion Dmytro.

Regards,
Kriti

Dmytro Rud

unread,
May 5, 2016, 7:02:51 AM5/5/16
to ipf-...@googlegroups.com
Forgot to mention: the proposed approach will work only if you use an IPF MLLP component instead of the standard Camel mina2 component.

kriti tandon

unread,
May 5, 2016, 7:59:21 AM5/5/16
to ipf-user
We are actually using the standard Camel mina2 component. Do you have any suggestions to achieve this in case we want to continue using the Camel's component?

Dmytro Rud

unread,
May 5, 2016, 8:19:09 AM5/5/16
to ipf-...@googlegroups.com
It means that your question is not related to IPF at all.  Try to ask it in the Camel mailing list.

Boris Stanojević

unread,
May 12, 2016, 9:23:19 AM5/12/16
to ipf-...@googlegroups.com
Hi Kriti,

this is what I would suggest you. I wrote several weeks ago this Mina-IOFilter in order to address this missbehavior:

https://github.com/oehf/ipf/blob/master/platform-camel/ihe/mllp/src/main/java/org/openehealth/ipf/platform/camel/ihe/mllp/core/MllpExceptionIoFilter.java

 

You should re-write a Camel-Mina2Component (see the sample project attached) which would include this IOFilter at the end of the MinaIOFilterChain. Then you will be able to use standard Camel feature „consumer.bridgeErrorHandler=true“ which would propagate the Exception to your RouteBuilder ExceptionHandler!!


Example RouteBuilder:


onException(Throwable.class)
.handled(true)
.... CREATE NAK .....
        .end()
from("rmina2:tcp://0.0.0.0:7777?sync=true&codec=#hl7codec&consumer.bridgeErrorHandler=true")
    .....

Best regards,
Boris
rmina2.zip

kriti tandon

unread,
May 12, 2016, 10:40:37 AM5/12/16
to ipf-...@googlegroups.com
Hi Boris,

Thanks a ton for the suggestion. I was hoping this would work for us but we are currently using camel-core-2.11.0 jar and the class UriEndpointComponent in org.apache.camel.impl does not seem to present in this old version of camel. It looks like camel 2.15 provides this. So, this might not be a very feasible approach for us. Any other suggestions would be more than welcome. 

Best Regards,
Kriti




You received this message because you are subscribed to a topic in the Google Groups "ipf-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ipf-user/ORJ4GLm1z7I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ipf-user+u...@googlegroups.com.

Boris Stanojević

unread,
May 13, 2016, 4:31:42 PM5/13/16
to ipf-...@googlegroups.com
Hi Kiri,

that should be no problem; camel-2.11 also supports the consumer.bridgeErrorHandler option.

Please find the same project based on camel-2.11 attached, Usage explained in my previous Mail.

Cheers,
Boris
rmina2.zip
Reply all
Reply to author
Forward
0 new messages