You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/05/29 17:06:54 UTC
[3/4] camel git commit: CAMEL-8812 Fixed the Memory leak in
HL7MLLPNettyDecoder with thanks to Gijsbert
CAMEL-8812 Fixed the Memory leak in HL7MLLPNettyDecoder with thanks to Gijsbert
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/38a856d5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/38a856d5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/38a856d5
Branch: refs/heads/camel-2.15.x
Commit: 38a856d53660c27986250f27baaca0b4c88961e2
Parents: c17f8c9
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri May 29 22:23:00 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri May 29 23:03:57 2015 +0800
----------------------------------------------------------------------
.../camel/component/hl7/HL7MLLPNettyDecoder.java | 18 +++++++++++-------
.../camel/component/hl7/HL7MLLPCodecTest.java | 2 +-
2 files changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/38a856d5/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java
----------------------------------------------------------------------
diff --git a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java
index 4938cd5..9c04448 100644
--- a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java
+++ b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java
@@ -59,13 +59,17 @@ class HL7MLLPNettyDecoder extends DelimiterBasedFrameDecoder {
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
ByteBuf buf = (ByteBuf) super.decode(ctx, buffer);
if (buf != null) {
- int pos = buf.bytesBefore((byte) config.getStartByte());
- if (pos >= 0) {
- ByteBuf msg = buf.readerIndex(pos + 1).slice();
- LOG.debug("Message ends with length {}", msg.readableBytes());
- return config.isProduceString() ? asString(msg) : asByteArray(msg);
- } else {
- throw new DecoderException("Did not find start byte " + (int) config.getStartByte());
+ try {
+ int pos = buf.bytesBefore((byte) config.getStartByte());
+ if (pos >= 0) {
+ ByteBuf msg = buf.readerIndex(pos + 1).slice();
+ LOG.debug("Message ends with length {}", msg.readableBytes());
+ return config.isProduceString() ? asString(msg) : asByteArray(msg);
+ } else {
+ throw new DecoderException("Did not find start byte " + (int) config.getStartByte());
+ }
+ } finally {
+ buf.release();
}
}
// Message not complete yet - return null to be called again
http://git-wip-us.apache.org/repos/asf/camel/blob/38a856d5/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
index 1d9afef..96d6396 100644
--- a/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
+++ b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
@@ -21,7 +21,6 @@ import ca.uhn.hl7v2.model.v24.message.ADR_A19;
import ca.uhn.hl7v2.model.v24.segment.MSA;
import ca.uhn.hl7v2.model.v24.segment.MSH;
import ca.uhn.hl7v2.model.v24.segment.QRD;
-
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
@@ -32,6 +31,7 @@ import org.junit.Test;
* Unit test for the HL7MLLP Codec.
*/
public class HL7MLLPCodecTest extends HL7TestSupport {
+
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();