camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r683518 - in /activemq/camel/trunk: ./ apache-camel/ apache-camel/bundle/ apache-camel/src/main/descriptors/ components/ components/camel-hl7/ components/camel-hl7/src/ components/camel-hl7/src/main/ components/camel-hl7/src/main/java/ comp...
Date Thu, 07 Aug 2008 05:56:28 GMT
Author: davsclaus
Date: Wed Aug  6 22:56:26 2008
New Revision: 683518

URL: http://svn.apache.org/viewvc?rev=683518&view=rev
Log:
CAMEL-786: Added new camel-hl7 component for working with the HL7 protocol (used by health care)

Added:
    activemq/camel/trunk/components/camel-hl7/   (with props)
    activemq/camel/trunk/components/camel-hl7/pom.xml   (with props)
    activemq/camel/trunk/components/camel-hl7/src/
    activemq/camel/trunk/components/camel-hl7/src/main/
    activemq/camel/trunk/components/camel-hl7/src/main/java/
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/mina/
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/mina/HL7MLLPCodec.java   (with props)
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7Converter.java   (with props)
    activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7DataFormat.java   (with props)
    activemq/camel/trunk/components/camel-hl7/src/main/resources/
    activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/
    activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/LICENSE.txt   (with props)
    activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/NOTICE.txt   (with props)
    activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/
    activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/
    activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/
    activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/
    activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/TypeConverter   (with props)
    activemq/camel/trunk/components/camel-hl7/src/test/
    activemq/camel/trunk/components/camel-hl7/src/test/java/
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/mina/
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/mina/HL7MLLPCodecTest.java   (with props)
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/
    activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java   (with props)
    activemq/camel/trunk/components/camel-hl7/src/test/resources/
    activemq/camel/trunk/components/camel-hl7/src/test/resources/log4j.properties   (with props)
Modified:
    activemq/camel/trunk/apache-camel/bundle/pom.xml
    activemq/camel/trunk/apache-camel/pom.xml
    activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml
    activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml
    activemq/camel/trunk/components/pom.xml
    activemq/camel/trunk/pom.xml

Modified: activemq/camel/trunk/apache-camel/bundle/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/bundle/pom.xml?rev=683518&r1=683517&r2=683518&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/bundle/pom.xml (original)
+++ activemq/camel/trunk/apache-camel/bundle/pom.xml Wed Aug  6 22:56:26 2008
@@ -76,6 +76,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-hl7</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-http</artifactId>
     </dependency>
     <dependency>

Modified: activemq/camel/trunk/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/pom.xml?rev=683518&r1=683517&r2=683518&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/pom.xml (original)
+++ activemq/camel/trunk/apache-camel/pom.xml Wed Aug  6 22:56:26 2008
@@ -97,6 +97,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-hl7</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-ibatis</artifactId>
     </dependency>
     <dependency>
@@ -255,12 +259,12 @@
     <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-example-etl</artifactId>
-    </dependency>	
+    </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-example-loan-broker</artifactId>
     </dependency>
-	<dependency>
+    <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-example-jms-file</artifactId>
     </dependency>

Modified: activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml?rev=683518&r1=683517&r2=683518&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml (original)
+++ activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml Wed Aug  6 22:56:26 2008
@@ -103,6 +103,7 @@
         <include>org.apache.camel:camel-ftp</include>
         <include>org.apache.camel:camel-groovy</include>
         <include>org.apache.camel:camel-hamcrest</include>
+        <include>org.apache.camel:camel-hl7</include>
         <include>org.apache.camel:camel-http</include>
         <include>org.apache.camel:camel-ibatis</include>
         <include>org.apache.camel:camel-irc</include>

Modified: activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml?rev=683518&r1=683517&r2=683518&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml (original)
+++ activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml Wed Aug  6 22:56:26 2008
@@ -109,6 +109,7 @@
         <include>org.apache.camel:camel-ftp</include>
         <include>org.apache.camel:camel-groovy</include>
         <include>org.apache.camel:camel-hamcrest</include>
+        <include>org.apache.camel:camel-hl7</include>
         <include>org.apache.camel:camel-http</include>
         <include>org.apache.camel:camel-ibatis</include>
         <include>org.apache.camel:camel-irc</include>

Propchange: activemq/camel/trunk/components/camel-hl7/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Aug  6 22:56:26 2008
@@ -0,0 +1,8 @@
+.checkstyle
+.pmd
+eclipse-classes
+target
+.classpath
+.project
+.settings
+*.i??

Added: activemq/camel/trunk/components/camel-hl7/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/pom.xml?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/pom.xml (added)
+++ activemq/camel/trunk/components/camel-hl7/pom.xml Wed Aug  6 22:56:26 2008
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>1.5-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-hl7</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: HL7</name>
+    <description>Camel HL7 support</description>
+
+    <properties>
+        <camel.osgi.export.pkg>org.apache.camel.dataformat.hl7.*;org.apache.camel.component.mina.*</camel.osgi.export.pkg>
+    </properties>
+
+    <repositories>
+        <repository>
+            <id>servicemix</id>
+            <name>Apache ServiceMix Repository</name>
+            <url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url>
+        </repository>
+    </repositories>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.hl7</groupId>
+            <artifactId>hapi</artifactId>
+            <version>0.5.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.mina</groupId>
+            <artifactId>mina-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+        </dependency>
+
+        <!-- testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-mina</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!-- to allow Spring annotations (jmx) to be tested -->
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-aop</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <childDelegation>false</childDelegation>
+                    <useFile>true</useFile>
+                    <forkMode>pertest</forkMode>
+                    <includes>
+                        <include>**/*Test.*</include>
+                    </includes>
+                    <excludes>
+                        <!-- <exclude>**/XXXTest.*</exclude> -->
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Propchange: activemq/camel/trunk/components/camel-hl7/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-hl7/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-hl7/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/mina/HL7MLLPCodec.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/mina/HL7MLLPCodec.java?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/mina/HL7MLLPCodec.java (added)
+++ activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/mina/HL7MLLPCodec.java Wed Aug  6 22:56:26 2008
@@ -0,0 +1,187 @@
+/**
+ * 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.mina;
+
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.camel.dataformat.hl7.HL7DataFormat;
+import org.apache.camel.dataformat.hl7.HL7Converter;
+
+import ca.uhn.hl7v2.model.Message;
+
+/**
+ * HL7 MLLP codec.
+ * <p/>
+ * This codec supports encoding/decoding the HL7 MLLP protocol.
+ * It will use the default markers for start and end combination:
+ * <ul>
+ *   <li>0x0b (11 decimal) = start marker</li>
+ *   <li>0x0d (13 decimal = the \r char) = segment terminators</li>
+ *   <li>0x1c (28 decimal) = end 1 marker</li>
+ *   <li>0x0d (13 decimal) = end 2 marker</li>
+ * </ul>
+ * <p/>
+ * The decoder is used for decoding from MLLP (bytes) to String. The String will not contain any of
+ * the start and end markers.
+ * <p/>
+ * The encoder is used for encoding from String to MLLP (bytes). The String should <b>not</b> contain
+ * any of the start and end markers, the enoder will add these, and stream the string as bytes.
+ * Also the enocder will convert any <tt>\n</tt> (line breaks) as segment terminators to <tt>\r</tt>.
+ * <p/>
+ * This codes supports charset encoding/decoding between bytes and String. The JVM platform default charset
+ * is used, but the charset can be configued on this codec using the setter method.
+ * The decoder will use the JVM platform default charset for decoding, but the charset can be configued on the this codec.
+ */
+public class HL7MLLPCodec implements ProtocolCodecFactory {
+
+    private static final String CHARSET_ENCODER = HL7MLLPCodec.class.getName() + ".charsetencoder";
+    private static final String CHARSET_DECODER = HL7MLLPCodec.class.getName() + ".charsetdecoder";
+
+    // HL7 MLLP start and end markers
+    private static final byte START_MARKER = 0x0b; // 11 decimal
+    private static final byte END_MARKER_1 = 0x1c; // 28 decimal
+    private static final byte END_MARKER_2 = 0x0d; // 13 decimal
+
+    private Charset charset = Charset.defaultCharset();
+
+    public ProtocolEncoder getEncoder() throws Exception {
+        return new ProtocolEncoder() {
+            public void encode(IoSession session, Object message, ProtocolEncoderOutput out)
+                throws Exception {
+                
+                if (message == null) {
+                    throw new IllegalArgumentException("Message to encode is null");
+                }
+
+                CharsetEncoder encoder = (CharsetEncoder)session.getAttribute(CHARSET_ENCODER);
+                if (encoder == null) {
+                    encoder = charset.newEncoder();
+                    session.setAttribute(CHARSET_ENCODER, encoder);
+                }
+
+                // convert to string
+                String body;
+                if (message instanceof byte[]) {
+                    // body is most likely a byte[]
+                    body = new String((byte[])message, encoder.charset().name());
+                } else if (message instanceof Message) {
+                    // but can also be a HL7 Message
+                    body = HL7Converter.toString((Message)message);
+                } else {
+                    // fallback to the toString method
+                    body = message.toString();
+                }
+                // replace \n with \r as HL7 uses 0x0d = \r as segment termninators
+                body = body.replace('\n', '\r');
+
+                // put the data into the byte buffer
+                ByteBuffer bb = ByteBuffer.allocate(body.length() + 3).setAutoExpand(true);
+                bb.put(START_MARKER);
+                bb.putString(body, encoder);
+                bb.put(END_MARKER_1);
+                bb.put(END_MARKER_2);
+
+                // flip the buffer so we can use it to write to the out stream
+                bb.flip();
+                out.write(bb);
+            }
+
+            public void dispose(IoSession session) throws Exception {
+                session.removeAttribute(CHARSET_ENCODER);
+            }
+        };
+    }
+
+    public ProtocolDecoder getDecoder() throws Exception {
+        return new ProtocolDecoder() {
+            public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
+
+                // find position where we have the end1 end2 combination
+                int posEnd = 0;
+                int posStart = 0;
+                while (in.hasRemaining()) {
+                    byte b = in.get();
+                    if (b == START_MARKER) {
+                        posStart = in.position();
+                    }
+                    if (b == END_MARKER_1) {
+                        byte next = in.get();
+                        if (next == END_MARKER_2) {
+                            posEnd = in.position();
+                            break;
+                        }
+                    }
+                }
+
+                // okay we have computed the start and end position of the special HL7 markers
+                // rewind the bytebuffer so we can read from it again
+                in.rewind();
+
+                // narrow the buffer to only include between the start and end markers
+                in.skip(posStart);
+                if (posEnd > 0) {
+                    in.limit(posEnd);
+                }
+
+                try {
+                    // convert to string using the charset decoder
+                    CharsetDecoder decoder = (CharsetDecoder)session.getAttribute(CHARSET_DECODER);
+                    if (decoder == null) {
+                        decoder = charset.newDecoder();
+                        session.setAttribute(CHARSET_DECODER, decoder);
+                    }
+                    String body = in.getString(decoder);
+
+                    out.write(body);
+                } finally {
+                    // clear the buffer now that we have transfered the data to the String
+                    in.clear();
+                }
+            }
+
+            public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception {
+                // do nothing
+            }
+
+            public void dispose(IoSession session) throws Exception {
+                session.removeAttribute(CHARSET_DECODER);
+            }
+        };
+    }
+
+    public Charset getCharset() {
+        return charset;
+    }
+
+    public void setCharset(Charset charset) {
+        this.charset = charset;
+    }
+
+    public void setCharset(String charsetName) {
+        this.charset = Charset.forName(charsetName);
+    }
+
+}

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

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

Added: activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7Converter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7Converter.java?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7Converter.java (added)
+++ activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7Converter.java Wed Aug  6 22:56:26 2008
@@ -0,0 +1,52 @@
+/**
+ * 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.dataformat.hl7;
+
+import org.apache.camel.Converter;
+
+import ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.parser.Parser;
+import ca.uhn.hl7v2.parser.PipeParser;
+
+/**
+ * HL7 converters.
+ */
+@Converter
+public class HL7Converter {
+
+    private HL7Converter() {
+    }
+
+    @Converter
+    public static String toString(Message message) throws HL7Exception {
+        Parser parser = new PipeParser();
+        String encoded = parser.encode(message);
+        return encoded;
+    }
+
+    @Converter
+    public static Message toMessage(String body) throws HL7Exception {
+        // replace \n with \r as HL7 uses 0x0d = \r as segment termninators
+        body = body.replace('\n', '\r');
+
+        Parser parser = new PipeParser();
+        Message message = parser.parse(body);
+        return message;
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7Converter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7Converter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7DataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7DataFormat.java?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7DataFormat.java (added)
+++ activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7DataFormat.java Wed Aug  6 22:56:26 2008
@@ -0,0 +1,59 @@
+/**
+ * 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.dataformat.hl7;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.util.ExchangeHelper;
+
+import ca.uhn.hl7v2.model.Message;
+
+/**
+ * HL7 DataFormat (supports v2.x of the HL7 protocol).
+ * <p/>
+ * This data format supports two operations:
+ * <ul>
+ *   <li>marshal = from Message to String (used when returning as response using the HL7 MLLP codec).</li>
+ *   <li>unmarshal = from String to Message (used when recieving streamed data from the HL7 MLLP codec)</li>
+ * </ul>
+ * <p/>
+ * Uses the <a href="http://hl7api.sourceforge.net/index.html">HAPI (HL7 API)</a> for HL7 parsing.
+ * <p/>
+ * Uses the default PipeParser from the HAPI API. This DataFormat <b>only</b> supports the EDI based HL7
+ * messages and not the XML based (their are not commonly used).
+ *
+ * @see org.apache.camel.component.mina.HL7MLLPCodec
+ */
+public class HL7DataFormat implements DataFormat {
+
+    public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
+        Message message = ExchangeHelper.convertToMandatoryType(exchange, Message.class, body);
+        String encoded = HL7Converter.toString(message);
+        outputStream.write(encoded.getBytes());
+    }
+
+    public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
+        String body = ExchangeHelper.convertToMandatoryType(exchange, String.class, inputStream);
+        Message message = HL7Converter.toMessage(body);
+        return message;
+    }
+
+}
+

Propchange: activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7DataFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/dataformat/hl7/HL7DataFormat.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/LICENSE.txt?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/LICENSE.txt (added)
+++ activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/LICENSE.txt Wed Aug  6 22:56:26 2008
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

Propchange: activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/NOTICE.txt?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/NOTICE.txt (added)
+++ activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/NOTICE.txt Wed Aug  6 22:56:26 2008
@@ -0,0 +1,14 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   This product includes software developed by
+   The HAPI Project (http://hl7api.sourceforge.net/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

Propchange: activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/TypeConverter (added)
+++ activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/TypeConverter Wed Aug  6 22:56:26 2008
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.dataformat.hl7
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/mina/HL7MLLPCodecTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/mina/HL7MLLPCodecTest.java?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/mina/HL7MLLPCodecTest.java (added)
+++ activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/mina/HL7MLLPCodecTest.java Wed Aug  6 22:56:26 2008
@@ -0,0 +1,101 @@
+/**
+ * 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.mina;
+
+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.impl.JndiRegistry;
+
+import ca.uhn.hl7v2.model.Message;
+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;
+
+/**
+ * Unit test for the HL7MLLP Codec.
+ */
+public class HL7MLLPCodecTest extends ContextTestSupport {
+
+    protected JndiRegistry createRegistry() throws Exception {
+        HL7MLLPCodec codec = new HL7MLLPCodec();
+        codec.setCharset("iso-8859-1");
+
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("hl7codec", codec);
+
+        return jndi;
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("mina:tcp://localhost:8888?sync=true&codec=hl7codec")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            Message response = createHL7AsMessage();
+                            exchange.getOut().setBody(response);
+                        }
+                    })
+                    .to("mock:result");
+            }
+        };
+    }
+
+    public void testSendHL7Message() throws Exception {
+        String line1 = "MSH|^~\\&|ARIA|HERLEV|CAPS||200612211200||QRY^A19|MessageID: 1234|P|2.4";
+        String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|1606943605|DEM||";
+
+        StringBuffer in = new StringBuffer();
+        in.append(line1);
+        in.append("\n");
+        in.append(line2);
+
+        String out = (String)template.requestBody("mina:tcp://localhost:8888?sync=true&codec=hl7codec", in.toString());
+
+        String[] lines = out.split("\r");
+        assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123", lines[0]);
+        assertEquals("MSA|AA|123", lines[1]);
+    }
+
+    private static Message createHL7AsMessage() throws Exception {
+        ADR_A19 adr = new ADR_A19();
+
+        // Populate the MSH Segment
+        MSH mshSegment = adr.getMSH();
+        mshSegment.getFieldSeparator().setValue("|");
+        mshSegment.getEncodingCharacters().setValue("^~\\&");
+        mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
+        mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
+        mshSegment.getSequenceNumber().setValue("123");
+        mshSegment.getMessageType().getMessageType().setValue("ADR");
+        mshSegment.getMessageType().getTriggerEvent().setValue("A19");
+
+        // Populate the PID Segment
+        MSA msa = adr.getMSA();
+        msa.getAcknowledgementCode().setValue("AA");
+        msa.getMessageControlID().setValue("123");
+
+        QRD qrd = adr.getQRD();
+        qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");
+
+        return adr.getMessage();
+    }
+
+}

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

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

Added: 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=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java (added)
+++ activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java Wed Aug  6 22:56:26 2008
@@ -0,0 +1,110 @@
+/**
+ * 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.dataformat.hl7;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.DataFormat;
+
+import ca.uhn.hl7v2.model.Message;
+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;
+
+/**
+ * Unit test for HL7 DataFormat.
+ */
+public class HL7DataFormatTest extends ContextTestSupport {
+
+    private DataFormat hl7 = new HL7DataFormat();
+
+    public void testMarshal() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:marshal");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(byte[].class);
+        mock.message(0).bodyAs(String.class).contains("MSA|AA|123");
+        mock.message(0).bodyAs(String.class).contains("QRD|20080805120000");
+
+        Message message = createHL7AsMessage();
+        template.sendBody("direct:marshal", message);
+
+        assertMockEndpointsSatisifed();
+    }
+
+    public void testUnmarshal() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:unmarshal");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(Message.class);
+
+        String body = createHL7AsString();
+        template.sendBody("direct:unmarshal", body);
+
+        assertMockEndpointsSatisifed();
+
+        Message msg = mock.getExchanges().get(0).getIn().getBody(Message.class);
+        assertEquals("2.4", msg.getVersion());
+        QRD qrd = (QRD)msg.get("QRD");
+        assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:marshal").marshal(hl7).to("mock:marshal");
+                from("direct:unmarshal").unmarshal(hl7).to("mock:unmarshal");
+            }
+        };
+    }
+
+    private static String createHL7AsString() {
+        String line1 = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4";
+        String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";
+
+        StringBuffer body = new StringBuffer();
+        body.append(line1);
+        body.append("\n");
+        body.append(line2);
+        return body.toString();
+    }
+
+    private static Message createHL7AsMessage() throws Exception {
+        ADR_A19 adr = new ADR_A19();
+
+        // Populate the MSH Segment
+        MSH mshSegment = adr.getMSH();
+        mshSegment.getFieldSeparator().setValue("|");
+        mshSegment.getEncodingCharacters().setValue("^~\\&");
+        mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
+        mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
+        mshSegment.getSequenceNumber().setValue("123");
+        mshSegment.getMessageType().getMessageType().setValue("ADR");
+        mshSegment.getMessageType().getTriggerEvent().setValue("A19");
+
+        // Populate the PID Segment
+        MSA msa = adr.getMSA();
+        msa.getAcknowledgementCode().setValue("AA");
+        msa.getMessageControlID().setValue("123");
+
+        QRD qrd = adr.getQRD();
+        qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");
+
+        return adr.getMessage();
+    }
+    
+}

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

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

Added: activemq/camel/trunk/components/camel-hl7/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/test/resources/log4j.properties?rev=683518&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/src/test/resources/log4j.properties (added)
+++ activemq/camel/trunk/components/camel-hl7/src/test/resources/log4j.properties Wed Aug  6 22:56:26 2008
@@ -0,0 +1,35 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, file
+
+# CONSOLE appender not used by default
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+log4j.appender.file.file=target/camel-hl7-test.log
+
+# debug loging for Camel
+log4j.logger.org.apache.camel.component.hl7=DEBUG

Propchange: activemq/camel/trunk/components/camel-hl7/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/pom.xml?rev=683518&r1=683517&r2=683518&view=diff
==============================================================================
--- activemq/camel/trunk/components/pom.xml (original)
+++ activemq/camel/trunk/components/pom.xml Wed Aug  6 22:56:26 2008
@@ -82,6 +82,7 @@
     <module>camel-xmpp</module>
     <module>camel-xstream</module>
     <module>camel-spring-integration</module>   
+    <module>camel-hl7</module>
   </modules>
 
 </project>

Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?rev=683518&r1=683517&r2=683518&view=diff
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Wed Aug  6 22:56:26 2008
@@ -308,6 +308,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-hl7</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-http</artifactId>
         <version>${project.version}</version>
       </dependency>
@@ -741,11 +746,11 @@
       <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-orm</artifactId>
-	<version>${spring-version}</version>
+        <version>${spring-version}</version>
       </dependency>
       <dependency>
-      	<groupId>org.springframework</groupId>
-      	<artifactId>spring-jms</artifactId>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-jms</artifactId>
         <version>${spring-version}</version>	  
       </dependency>
       <dependency>
@@ -762,7 +767,7 @@
       <dependency>
         <groupId>org.springframework.osgi</groupId>
         <artifactId>spring-osgi-core</artifactId>
-	<version>${spring-osgi-version}</version>
+        <version>${spring-osgi-version}</version>
       </dependency>
 
       <dependency>



Mime
View raw message