You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by qu...@apache.org on 2018/02/12 20:26:06 UTC

[camel] branch master updated: CAMEL-12258: use the configured readTimeout for the initial HL7 message read attempt

This is an automated email from the ASF dual-hosted git repository.

quinn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 5884ab7  CAMEL-12258:  use the configured readTimeout for the initial HL7 message read attempt
5884ab7 is described below

commit 5884ab755731d40a1d3d00153cc776fb0c068936
Author: Quinn Stevenson <qu...@apache.org>
AuthorDate: Mon Feb 12 13:25:59 2018 -0700

    CAMEL-12258:  use the configured readTimeout for the initial HL7 message read attempt
---
 .../component/mllp/internal/MllpSocketBuffer.java  | 47 +++++++++++++++++++++-
 .../TcpServerConsumerValidationRunnable.java       |  8 ++--
 .../internal/MllpSocketBufferReadFromTest.java     |  2 +-
 3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/internal/MllpSocketBuffer.java b/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/internal/MllpSocketBuffer.java
index faf6d63..bc06786 100644
--- a/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/internal/MllpSocketBuffer.java
+++ b/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/internal/MllpSocketBuffer.java
@@ -326,10 +326,26 @@ public class MllpSocketBuffer {
         return "";
     }
 
+    public String toPrintFriendlyStringAndReset() {
+        String answer = toPrintFriendlyString();
+
+        reset();
+
+        return answer;
+    }
+
     public synchronized String toHl7String() {
         return this.toHl7String(StandardCharsets.US_ASCII.name());
     }
 
+    public String toHl7StringAndReset() {
+        String answer = toHl7String();
+
+        reset();
+
+        return answer;
+    }
+
     public synchronized String toHl7String(String charsetName) {
         String hl7String = null;
 
@@ -354,6 +370,14 @@ public class MllpSocketBuffer {
         return hl7String;
     }
 
+    public String toHl7StringAndReset(String charsetName) {
+        String answer = toHl7String(charsetName);
+
+        reset();
+
+        return answer;
+    }
+
     /**
      * Convert the enveloped contents of the buffer (excluding enveloping characters) to a print-friendly
      * String representation.
@@ -370,6 +394,14 @@ public class MllpSocketBuffer {
         return "";
     }
 
+    public String toPrintFriendlyHl7StringAndReset() {
+        String answer = toPrintFriendlyHl7String();
+
+        reset();
+
+        return answer;
+    }
+
     public synchronized byte[] toMllpPayload() {
         byte[] mllpPayload = null;
 
@@ -388,6 +420,14 @@ public class MllpSocketBuffer {
         return mllpPayload;
     }
 
+    public byte[] toMllpPayloadAndReset() {
+        byte[] answer = toMllpPayload();
+
+        reset();
+
+        return answer;
+    }
+
     public synchronized int getMllpPayloadLength() {
         int answer = -1;
 
@@ -576,7 +616,12 @@ public class MllpSocketBuffer {
                     updateIndexes(buffer[availableByteCount + i], i);
                 }
                 availableByteCount += readCount;
-                log.trace("Read {} bytes for a total of {} bytes", readCount, availableByteCount);
+
+                if (hasStartOfBlock()) {
+                    log.trace("Read {} bytes for a total of {} bytes", readCount, availableByteCount);
+                } else {
+                    log.warn("Ignoring {} bytes received before START_OF_BLOCK", size(), toPrintFriendlyStringAndReset());
+                }
             }
         } catch (SocketTimeoutException timeoutEx) {
             throw timeoutEx;
diff --git a/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/internal/TcpServerConsumerValidationRunnable.java b/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/internal/TcpServerConsumerValidationRunnable.java
index 066b3db..10a9448 100644
--- a/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/internal/TcpServerConsumerValidationRunnable.java
+++ b/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/internal/TcpServerConsumerValidationRunnable.java
@@ -138,18 +138,18 @@ public class TcpServerConsumerValidationRunnable implements Runnable {
         log.debug("Checking {} for data", combinedAddress);
 
         try {
-            mllpBuffer.readFrom(clientSocket, 500, 50);
+            mllpBuffer.readFrom(clientSocket, Math.min(500, consumer.getConfiguration().getReceiveTimeout()), consumer.getConfiguration().getReadTimeout());
             if (mllpBuffer.hasCompleteEnvelope()  || mllpBuffer.hasStartOfBlock()) {
                 consumer.startConsumer(clientSocket, mllpBuffer);
             } else if (!mllpBuffer.isEmpty()) {
                 // We have some leading out-of-band data but no START_OF_BLOCK
-                log.info("Ignoring out-of-band data on initial read: {}", mllpBuffer.toStringAndReset());
+                log.info("Ignoring out-of-band data on initial read [{} bytes]: {}", mllpBuffer.size(), mllpBuffer.toPrintFriendlyStringAndReset());
                 mllpBuffer.resetSocket(clientSocket);
             }
         } catch (MllpSocketException socketEx) {
             // TODO:  The socket is invalid for some reason
             if (!mllpBuffer.isEmpty()) {
-                log.warn("Exception encountered receiving complete message: ", mllpBuffer.toStringAndReset());
+                log.warn("Exception encountered receiving complete initial message [{} bytes]: {}", mllpBuffer.size(), mllpBuffer.toPrintFriendlyStringAndReset());
             }
             mllpBuffer.resetSocket(clientSocket);
         } catch (SocketTimeoutException timeoutEx) {
@@ -157,7 +157,7 @@ public class TcpServerConsumerValidationRunnable implements Runnable {
                 log.debug("Initial read timed-out but no data was read - starting consumer");
                 consumer.startConsumer(clientSocket, mllpBuffer);
             } else {
-                log.warn("Timeout receiving complete message: {}", mllpBuffer.toStringAndReset());
+                log.warn("Timeout receiving complete initial message on read [{} bytes]: {}", mllpBuffer.size(), mllpBuffer.toPrintFriendlyStringAndReset());
                 mllpBuffer.resetSocket(clientSocket);
             }
         } finally {
diff --git a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/internal/MllpSocketBufferReadFromTest.java b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/internal/MllpSocketBufferReadFromTest.java
index ab2f532..ddf1974 100644
--- a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/internal/MllpSocketBufferReadFromTest.java
+++ b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/internal/MllpSocketBufferReadFromTest.java
@@ -83,7 +83,7 @@ public class MllpSocketBufferReadFromTest extends SocketBufferTestSupport {
             instance.readFrom(socketStub);
             fail("Should have thrown and exception");
         } catch (SocketTimeoutException expectedEx) {
-            assertArrayEquals("FOOBAR".getBytes(), instance.toByteArray());
+            assertNull(instance.toByteArray());
         }
     }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
quinn@apache.org.