You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Kriti <kr...@gmail.com> on 2016/05/05 12:31:34 UTC

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

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



--
View this message in context: http://camel.465427.n5.nabble.com/Unable-to-catch-and-deal-with-the-ProtocolDecoderException-thrown-by-Mina-in-our-camel-tp5782230.html
Sent from the Camel - Users mailing list archive at Nabble.com.