You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2008/08/27 14:21:02 UTC

svn commit: r689457 - in /activemq/camel/trunk/components/camel-hl7/src: main/java/org/apache/camel/component/hl7/ test/java/org/apache/camel/component/hl7/ test/java/org/apache/camel/dataformat/hl7/

Author: davsclaus
Date: Wed Aug 27 05:21:01 2008
New Revision: 689457

URL: http://svn.apache.org/viewvc?rev=689457&view=rev
Log:
CAMEL-859: HL7MLLP codec is message format agnostic - ie you can get the data as plain String and do parsing yourself. Added unit test to demonstrate this.

Added:
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java   (with props)
Modified:
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java

Modified: activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java?rev=689457&r1=689456&r2=689457&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java (original)
+++ activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java Wed Aug 27 05:21:01 2008
@@ -137,7 +137,7 @@
                     if (b == END_MARKER_1) {
                         byte next = in.get();
                         if (next == END_MARKER_2) {
-                            posEnd = in.position();
+                            posEnd = in.position() - 2; // use -2 to skip these last 2 end markers
                             break;
                         } else {
                             // we expected the 2nd end marker

Added: activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java?rev=689457&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java (added)
+++ activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java Wed Aug 27 05:21:01 2008
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hl7;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * Unit test to demonstrate the HL7MLLPCodec is message format agnostic (don't require the HAPI library).
+ * The message format can be java.lang.String.
+ */
+public class HL7MLLPCodecPlainStringTest extends ContextTestSupport {
+
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+
+        HL7MLLPCodec codec = new HL7MLLPCodec();
+        codec.setCharset("iso-8859-1");
+
+        jndi.bind("hl7codec", codec);
+
+        return jndi;
+    }
+
+    public void testPlainString() throws Exception {
+        // START SNIPPET: e1
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Bye World");
+
+        // send plain hello world as String
+        Object out = template.requestBody("mina:tcp://localhost:8888?sync=true&codec=hl7codec", "Hello World");
+
+        assertMockEndpointsSatisifed();
+
+        // and the response is also just plain String
+        assertEquals("Bye World", out);
+        // END SNIPPET: e1
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                // START SNIPPET: e2
+                from("mina:tcp://localhost:8888?sync=true&codec=hl7codec")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            // use plain String as message format
+                            String body = exchange.getIn().getBody(String.class);
+                            assertEquals("Hello World", body);
+
+                            // return the response as plain string
+                            exchange.getOut().setBody("Bye World");
+                        }
+                    })
+                    .to("mock:result");
+                // END SNIPPET: e2
+            }
+        };
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java?rev=689457&r1=689456&r2=689457&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java (original)
+++ activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java Wed Aug 27 05:21:01 2008
@@ -28,8 +28,6 @@
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
 
-
-
 /**
  * Unit test for the HL7MLLP Codec.
  */

Modified: activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java?rev=689457&r1=689456&r2=689457&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java (original)
+++ activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java Wed Aug 27 05:21:01 2008
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 package org.apache.camel.component.hl7;
+
 import ca.uhn.hl7v2.model.Message;
 import ca.uhn.hl7v2.model.v24.message.ADR_A19;
 import ca.uhn.hl7v2.model.v24.message.ADT_A01;
@@ -31,7 +32,6 @@
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.spi.DataFormat;
 
-
 /**
  * Unit test for HL7 routing.
  */

Modified: activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java?rev=689457&r1=689456&r2=689457&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java (original)
+++ activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java Wed Aug 27 05:21:01 2008
@@ -21,12 +21,9 @@
 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.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spi.DataFormat;
-
 
 /**
  * Unit test for HL7 DataFormat.