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 2012/08/14 10:42:28 UTC

svn commit: r1372774 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/model/dataformat/ components/camel-hl7/ components/camel-hl7/src/main/java/org/apache/camel/component/hl7/ components/c...

Author: ningjiang
Date: Tue Aug 14 08:42:27 2012
New Revision: 1372774

URL: http://svn.apache.org/viewvc?rev=1372774&view=rev
Log:
CAMEL-5488 Update and improve camel-hl7

Added:
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/Terser.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserExpression.java
      - copied, changed from r1372485, camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserLanguage.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/ValidationContextPredicate.java
    camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/language/
    camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/language/terser
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckExpressionTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7XmlDataFormatTest.java
      - copied, changed from r1372485, camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/MessageValidatorTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/TerserExpressionTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java
    camel/trunk/components/camel-hl7/pom.xml
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7Converter.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPConfig.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPDecoder.java
    camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPEncoder.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecBoundaryTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecLongTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecStandAndEndBytesTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java
    camel/trunk/parent/pom.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java Tue Aug 14 08:42:27 2012
@@ -186,6 +186,15 @@ public class DataFormatClause<T extends 
         hl7.setValidate(validate);
         return dataFormat(hl7);
     }
+    
+    /**
+     * Uses the HL7 data format
+     */
+    public T hl7(Object parser) {
+        HL7DataFormat hl7 = new HL7DataFormat();
+        hl7.setParser(parser);
+        return dataFormat(hl7);
+    }    
 
     /**
      * Uses the PGP data format

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java Tue Aug 14 08:42:27 2012
@@ -34,6 +34,8 @@ import org.apache.camel.spi.DataFormat;
 public class HL7DataFormat extends DataFormatDefinition {
     @XmlAttribute
     private Boolean validate;
+    @XmlAttribute
+    private Object parser;
 
     public HL7DataFormat() {
         super("hl7");
@@ -52,8 +54,17 @@ public class HL7DataFormat extends DataF
         this.validate = validate;
     }
 
-    @Override
+    public Object getParser() {
+		return parser;
+	}
+
+	public void setParser(Object parser) {
+		this.parser = parser;
+	}
+
+	@Override
     protected void configureDataFormat(DataFormat dataFormat) {
+		setProperty(dataFormat, "parser", getParser());
         setProperty(dataFormat, "validate", isValidate());
     }
 

Modified: camel/trunk/components/camel-hl7/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/pom.xml?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/pom.xml (original)
+++ camel/trunk/components/camel-hl7/pom.xml Tue Aug 14 08:42:27 2012
@@ -46,6 +46,7 @@
             <artifactId>hapi-base</artifactId>
             <version>${hapi-version}</version>
         </dependency>
+        <!--
         <dependency>
             <groupId>org.apache.mina</groupId>
             <artifactId>mina-core</artifactId>
@@ -60,6 +61,18 @@
 	            </exclusion>
 	        </exclusions>
 	    </dependency>
+	    -->
+        <dependency>
+            <groupId>org.apache.mina</groupId>
+            <artifactId>mina-core</artifactId>
+            <version>${mina2-version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-simple</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>	    
 
         <!-- testing -->
         <dependency>
@@ -81,7 +94,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-mina</artifactId>
+            <artifactId>camel-mina2</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>

Added: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java (added)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckCode.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,32 @@
+/**
+ * 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;
+
+public enum AckCode {
+    AA(false), CA(false), AR(true), CR(true), AE(true), CE(true);
+
+    private final boolean error;
+
+    AckCode(boolean error) {
+        this.error = error;
+    }
+
+    public boolean isError() {
+        return error;
+    }
+
+}
\ No newline at end of file

Added: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java (added)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/AckExpression.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,80 @@
+/**
+ * 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 ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.model.Message;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.support.ExpressionAdapter;
+import org.apache.camel.util.ObjectHelper;
+
+public class AckExpression extends ExpressionAdapter {
+
+    private AckCode acknowledgementCode;
+    private String errorMessage;
+    private int errorCode = HL7Exception.APPLICATION_INTERNAL_ERROR;
+
+    public AckExpression() {
+        super();
+    }
+
+    public AckExpression(AckCode acknowledgementCode) {
+        super();
+        this.acknowledgementCode = acknowledgementCode;
+    }
+
+    public AckExpression(AckCode acknowledgementCode, String errorMessage, int errorCode) {
+        this(acknowledgementCode);
+        this.errorMessage = errorMessage;
+        this.errorCode = errorCode;
+    }
+
+    @Override
+    public Object evaluate(Exchange exchange) {
+        Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
+        Message msg = exchange.getIn().getBody(Message.class);
+        try {
+            HL7Exception hl7e = generateHL7Exception(t);
+            AckCode code = acknowledgementCode;
+            if (t != null && code == null) {
+                code = AckCode.AE;
+            }
+            return msg.generateACK(code == null ? null : code.name(), hl7e);
+        } catch (Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
+
+    private HL7Exception generateHL7Exception(Throwable t) {
+        HL7Exception hl7Exception = null;
+        if (t == null) {
+            if (acknowledgementCode != null && acknowledgementCode.isError()) {
+                hl7Exception = new HL7Exception(errorMessage, errorCode);
+            }
+        } else {
+            if (t instanceof HL7Exception) {
+                hl7Exception = (HL7Exception)t;
+            } else {
+                hl7Exception = new HL7Exception(errorMessage != null ? errorMessage : t.getMessage(),
+                                                errorCode, t);
+            }
+        }
+        return hl7Exception;
+    }
+
+}

Added: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java (added)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,55 @@
+/**
+ * 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 ca.uhn.hl7v2.validation.ValidationContext;
+
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+import org.apache.camel.builder.ValueBuilder;
+
+public final class HL7 {
+    
+    private HL7() {
+        // Helper class
+    }
+
+    public static ValueBuilder terser(String expression) {
+        return new ValueBuilder(new TerserExpression(expression));
+    }
+
+    public static Expression ack() {
+        return new AckExpression();
+    }
+
+    public static Expression ack(AckCode code) {
+        return new AckExpression(code);
+    }
+
+    public static Expression ack(AckCode code, String errorMessage, int errorCode) {
+        return new AckExpression(code, errorMessage, errorCode);
+    }
+
+    public static Predicate messageConformsTo(ValidationContext validationContext) {
+        return new ValidationContextPredicate(validationContext);
+    }
+
+    public static Predicate messageConformsTo(Expression expression) {
+        return new ValidationContextPredicate(expression);
+    }
+
+}

Modified: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7Converter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7Converter.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7Converter.java (original)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7Converter.java Tue Aug 14 08:42:27 2012
@@ -20,7 +20,7 @@ import ca.uhn.hl7v2.HL7Exception;
 import ca.uhn.hl7v2.model.Message;
 import ca.uhn.hl7v2.parser.Parser;
 import ca.uhn.hl7v2.parser.PipeParser;
-import ca.uhn.hl7v2.validation.impl.NoValidation;
+
 import org.apache.camel.Converter;
 
 /**
@@ -35,31 +35,22 @@ public final class HL7Converter {
 
     @Converter
     public static String toString(Message message) throws HL7Exception {
-        return encode(message, true);
+        return encode(message, new PipeParser());
     }
 
     @Converter
     public static Message toMessage(String body) throws HL7Exception {
-        return parse(body, true);
+        return parse(body, new PipeParser());
     }
-
-    static Message parse(String body, boolean validate) throws HL7Exception {
+    
+    static Message parse(String body, Parser parser) throws HL7Exception {
         // replace \n with \r as HL7 uses 0x0d = \r as segment terminators and HAPI only parses with \r
         body = body.replace('\n', '\r');
-
-        Parser parser = new PipeParser();
-        if (!validate) {
-            parser.setValidationContext(new NoValidation());
-        }
         return parser.parse(body);
-    }
-
-    static String encode(Message message, boolean validate) throws HL7Exception {
-        Parser parser = new PipeParser();
-        if (!validate) {
-            parser.setValidationContext(new NoValidation());
-        }
+    }    
+    
+    static String encode(Message message, Parser parser) throws HL7Exception {
         return parser.encode(message);
-    }
+    }    
 
 }

Modified: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java (original)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java Tue Aug 14 08:42:27 2012
@@ -18,13 +18,31 @@ package org.apache.camel.component.hl7;
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
 
 import ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.parser.GenericParser;
+import ca.uhn.hl7v2.parser.Parser;
 import ca.uhn.hl7v2.util.Terser;
+import ca.uhn.hl7v2.validation.impl.NoValidation;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.util.ExchangeHelper;
 
+import static org.apache.camel.component.hl7.HL7Constants.HL7_MESSAGE_CONTROL;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_MESSAGE_TYPE;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_PROCESSING_ID;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_RECEIVING_APPLICATION;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_RECEIVING_FACILITY;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_SECURITY;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_SENDING_APPLICATION;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_SENDING_FACILITY;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_TIMESTAMP;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_TRIGGER_EVENT;
+import static org.apache.camel.component.hl7.HL7Constants.HL7_VERSION_ID;
+
 /**
  * HL7 DataFormat (supports v2.x of the HL7 protocol).
  * <p/>
@@ -37,65 +55,84 @@ import org.apache.camel.util.ExchangeHel
  * <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).
+ * Uses the default GenericParser from the HAPI API. This DataFormat <b>only</b> supports both the EDI based HL7
+ * messages and the XML based messages.
  * <p/>
  * The <tt>unmarshal</tt> operation adds these MSH fields as headers on the Camel message (key, MSH-field):
  * <ul>
- *   <li>hl7.msh.sendingApplication = MSH-3</li>
- *   <li>hl7.msh.sendingFacility = MSH-4</li>
- *   <li>hl7.msh.receivingApplication = MSH-5</li>
- *   <li>hl7.msh.receivingFacility = MSH-6</li>
- *   <li>hl7.msh.timestamp = MSH-7</li>
- *   <li>hl7.msh.security = MSH-8</li>
- *   <li>hl7.msh.messageType = MSH-9-1</li>
- *   <li>hl7.msh.triggerEvent = MSH-9-2</li>
- *   <li>hl7.msh.messageControl = MSH-10</li>
- *   <li>hl7.msh.processingId = MSH-11</li>
- *   <li>hl7.msh.versionId = MSH-12</li>
+ *   <li>CamelHL7SendingApplication = MSH-3</li>
+ *   <li>CamelHL7SendingFacility = MSH-4</li>
+ *   <li>CamelHL7ReceivingApplication = MSH-5</li>
+ *   <li>CamelHL7ReceivingFacility = MSH-6</li>
+ *   <li>CamelHL7Timestamp = MSH-7</li>
+ *   <li>CamelHL7Security = MSH-8</li>
+ *   <li>CamelHL7MessageType = MSH-9-1</li>
+ *   <li>CamelHL7TriggerEvent = MSH-9-2</li>
+ *   <li>CamelHL7MessageControl = MSH-10</li>
+ *   <li>CamelHL7ProcessingId = MSH-11</li>
+ *   <li>CamelHL7VersionId = MSH-12</li>
  * </ul>
  * All headers are String types.
  * <p/>
- * The <a href="http://www.hl7.org/Special/IG/final.pdf">HL7 spec</a> can be downloaded as a pdf at
  *
  * @see org.apache.camel.component.hl7.HL7MLLPCodec
  */
 public class HL7DataFormat implements DataFormat {
 
-    private boolean validate = true;
+    private static final Map<String, String> HEADER_MAP = new HashMap<String, String>();
+
+    private Parser parser = new GenericParser();
+    
+    static {
+        HEADER_MAP.put(HL7_SENDING_APPLICATION, "MSH-3");
+        HEADER_MAP.put(HL7_SENDING_FACILITY, "MSH-4");
+        HEADER_MAP.put(HL7_RECEIVING_APPLICATION, "MSH-5");
+        HEADER_MAP.put(HL7_RECEIVING_FACILITY, "MSH-6");
+        HEADER_MAP.put(HL7_TIMESTAMP, "MSH-7");
+        HEADER_MAP.put(HL7_SECURITY, "MSH-8");
+        HEADER_MAP.put(HL7_MESSAGE_TYPE, "MSH-9-1");
+        HEADER_MAP.put(HL7_TRIGGER_EVENT, "MSH-9-2");
+        HEADER_MAP.put(HL7_MESSAGE_CONTROL, "MSH-10");
+        HEADER_MAP.put(HL7_PROCESSING_ID, "MSH-11");
+        HEADER_MAP.put(HL7_VERSION_ID, "MSH-12");
+    }
 
     public void marshal(Exchange exchange, Object body, OutputStream outputStream) throws Exception {
         Message message = ExchangeHelper.convertToMandatoryType(exchange, Message.class, body);
-        String encoded = HL7Converter.encode(message, validate);
+        String encoded = HL7Converter.encode(message, parser);
         outputStream.write(encoded.getBytes());
     }
 
     public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
         String body = ExchangeHelper.convertToMandatoryType(exchange, String.class, inputStream);
-        Message message = HL7Converter.parse(body, validate);
+        Message message = HL7Converter.parse(body, parser);
 
         // add MSH fields as message out headers
         Terser terser = new Terser(message);
-        exchange.getOut().setHeader(HL7Constants.HL7_SENDING_APPLICATION, terser.get("MSH-3"));
-        exchange.getOut().setHeader(HL7Constants.HL7_SENDING_FACILITY, terser.get("MSH-4"));
-        exchange.getOut().setHeader(HL7Constants.HL7_RECEIVING_APPLICATION, terser.get("MSH-5"));
-        exchange.getOut().setHeader(HL7Constants.HL7_RECEIVING_FACILITY, terser.get("MSH-6"));
-        exchange.getOut().setHeader(HL7Constants.HL7_TIMESTAMP, terser.get("MSH-7"));
-        exchange.getOut().setHeader(HL7Constants.HL7_SECURITY, terser.get("MSH-8"));
-        exchange.getOut().setHeader(HL7Constants.HL7_MESSAGE_TYPE, terser.get("MSH-9-1"));
-        exchange.getOut().setHeader(HL7Constants.HL7_TRIGGER_EVENT, terser.get("MSH-9-2"));
-        exchange.getOut().setHeader(HL7Constants.HL7_MESSAGE_CONTROL, terser.get("MSH-10"));
-        exchange.getOut().setHeader(HL7Constants.HL7_PROCESSING_ID, terser.get("MSH-11"));
-        exchange.getOut().setHeader(HL7Constants.HL7_VERSION_ID, terser.get("MSH-12"));
+        for (Map.Entry<String, String> entry : HEADER_MAP.entrySet()) {
+            exchange.getOut().setHeader(entry.getKey(), terser.get(entry.getValue()));
+        }
         return message;
     }
 
     public boolean isValidate() {
-        return validate;
+        return parser.getValidationContext() instanceof NoValidation;
     }
 
     public void setValidate(boolean validate) {
-        this.validate = validate;
+        if (!validate) {
+            parser.setValidationContext(new NoValidation());
+        }
+    }
+
+    public Parser getParser() {
+        return parser;
+    }
+
+    public void setParser(Parser parser) {
+        this.parser = parser;
     }
+    
+    
 }
 

Modified: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java (original)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java Tue Aug 14 08:42:27 2012
@@ -18,6 +18,7 @@ package org.apache.camel.component.hl7;
 
 import java.nio.charset.Charset;
 
+import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolEncoder;
@@ -49,11 +50,11 @@ public class HL7MLLPCodec implements Pro
 
     private HL7MLLPConfig config = new HL7MLLPConfig();
 
-    public ProtocolDecoder getDecoder() throws Exception {
+    public ProtocolDecoder getDecoder(IoSession session) throws Exception {
         return new HL7MLLPDecoder(config);
     }
 
-    public ProtocolEncoder getEncoder() throws Exception {
+    public ProtocolEncoder getEncoder(IoSession session) throws Exception {
         return new HL7MLLPEncoder(config);
     }
 

Modified: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPConfig.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPConfig.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPConfig.java (original)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPConfig.java Tue Aug 14 08:42:27 2012
@@ -18,6 +18,10 @@ package org.apache.camel.component.hl7;
 
 import java.nio.charset.Charset;
 
+import ca.uhn.hl7v2.parser.Parser;
+import ca.uhn.hl7v2.parser.PipeParser;
+import ca.uhn.hl7v2.validation.impl.NoValidation;
+
 class HL7MLLPConfig {
 
     private Charset charset = Charset.defaultCharset();
@@ -30,8 +34,8 @@ class HL7MLLPConfig {
     private char endByte1 = 0x1c; // 28 decimal
 
     private char endByte2 = 0x0d; // 13 decimal
-
-    private boolean validate = true;
+    
+    private Parser parser = new PipeParser();
 
     public Charset getCharset() {
         return charset;
@@ -72,12 +76,22 @@ class HL7MLLPConfig {
     public void setEndByte2(char endByte2) {
         this.endByte2 = endByte2;
     }
+    
+    public Parser getParser() {
+        return parser;
+    }
+
+    public void setParser(Parser parser) {
+        this.parser = parser;
+    }
 
     public boolean isValidate() {
-        return validate;
+        return parser.getValidationContext() instanceof NoValidation;
     }
 
     public void setValidate(boolean validate) {
-        this.validate = validate;
+        if (!validate) {
+            parser.setValidationContext(new NoValidation());
+        }
     }
 }

Modified: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPDecoder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPDecoder.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPDecoder.java (original)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPDecoder.java Tue Aug 14 08:42:27 2012
@@ -19,8 +19,8 @@ package org.apache.camel.component.hl7;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.CharsetDecoder;
 
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 import org.slf4j.Logger;
@@ -44,7 +44,7 @@ class HL7MLLPDecoder extends CumulativeP
     }
 
     @Override
-    protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) {
+    protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) {
 
         // Scan the buffer of start and/or end bytes
         boolean foundEnd = scan(session, in);
@@ -59,7 +59,7 @@ class HL7MLLPDecoder extends CumulativeP
         return foundEnd;
     }
 
-    private void writeString(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) {
+    private void writeString(IoSession session, IoBuffer in, ProtocolDecoderOutput out) {
         DecoderState state = decoderState(session);
         if (state.posStart == 0) {
             LOG.warn("No start byte found, reading from beginning of data");
@@ -68,10 +68,7 @@ class HL7MLLPDecoder extends CumulativeP
         in.position(state.posStart);
         try {
             String body = in.getString(state.length(), charsetDecoder(session));
-
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Decoded HL7 from byte stream of length {} to String of length {}", state.length(), body.length());
-            }
+            LOG.debug("Decoded HL7 from byte stream of length {} to String of length {}", state.length(), body.length());
             out.write(body);
             // Avoid redelivery of scanned message
             state.reset();
@@ -97,23 +94,21 @@ class HL7MLLPDecoder extends CumulativeP
      * @return <code>true</code> if the end bytes were found, <code>false</code>
      *         otherwise
      */
-    private boolean scan(IoSession session, ByteBuffer in) {
+    private boolean scan(IoSession session, IoBuffer in) {
         DecoderState state = decoderState(session);
         // Start scanning where we left
         in.position(state.current);
-        LOG.debug("Start scanning buffer at position " + in.position());
+        LOG.debug("Start scanning buffer at position {}", in.position());
         while (in.hasRemaining()) {
             byte b = in.get();
             // Check start byte
             if (b == config.getStartByte()) {
                 if (state.posStart > 0 || state.waitingForEndByte2) {
-                    LOG.warn("Ignoring message start at position " + in.position() + " before previous message has ended.");
+                    LOG.warn("Ignoring message start at position {} before previous message has ended.", in.position());
                 } else {
                     state.posStart = in.position();
                     state.waitingForEndByte2 = false;
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Message starts at position {}", state.posStart);
-                    }
+                    LOG.debug("Message starts at position {}", state.posStart);
                 }
             }
             // Check end byte1 
@@ -121,7 +116,7 @@ class HL7MLLPDecoder extends CumulativeP
                 if (!state.waitingForEndByte2 && state.posStart > 0) {
                     state.waitingForEndByte2 = true;
                 } else {
-                    LOG.warn("Ignoring unexpected 1st end byte " + b + ". Expected 2nd endpoint  " + config.getEndByte2());
+                    LOG.warn("Ignoring unexpected 1st end byte {}. Expected 2nd endpoint {}", b, config.getEndByte2());
                 }
             }
             // Check end byte2 
@@ -129,9 +124,7 @@ class HL7MLLPDecoder extends CumulativeP
                 state.posEnd = in.position() - 2; // use -2 to skip these
                                                   // last 2 end markers
                 state.waitingForEndByte2 = false;
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Message ends at position {}", state.posEnd);
-                }
+                LOG.debug("Message ends at position {}", state.posEnd);
                 break;
             }
         }

Modified: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPEncoder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPEncoder.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPEncoder.java (original)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPEncoder.java Tue Aug 14 08:42:27 2012
@@ -18,8 +18,9 @@ package org.apache.camel.component.hl7;
 
 import java.nio.charset.CharsetEncoder;
 import ca.uhn.hl7v2.model.Message;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolEncoder;
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
 import org.slf4j.Logger;
@@ -61,7 +62,7 @@ class HL7MLLPEncoder implements Protocol
         // convert to string
         String body;
         if (message instanceof Message) {
-            body = HL7Converter.encode((Message)message, config.isValidate());
+            body = HL7Converter.encode((Message)message, config.getParser());
         } else if (message instanceof String) {
             body = (String)message;
         } else if (message instanceof byte[]) {
@@ -71,13 +72,13 @@ class HL7MLLPEncoder implements Protocol
                                                + message.getClass().getCanonicalName());
         }
 
-        // replace \n with \r as HL7 uses 0x0d = \r as segment termninators
+        // replace \n with \r as HL7 uses 0x0d = \r as segment terminators
         if (config.isConvertLFtoCR()) {
             body = body.replace('\n', '\r');
         }
 
         // put the data into the byte buffer
-        ByteBuffer buf = ByteBuffer.allocate(body.length() + 3).setAutoExpand(true);
+        IoBuffer buf = IoBuffer.allocate(body.length() + 3).setAutoExpand(true);
         buf.put((byte)config.getStartByte());
         buf.putString(body, encoder);
         buf.put((byte)config.getEndByte1());
@@ -85,9 +86,7 @@ class HL7MLLPEncoder implements Protocol
 
         // flip the buffer so we can use it to write to the out stream
         buf.flip();
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Encoding HL7 from {} to byte stream", message.getClass().getCanonicalName());
-        }
+        LOG.debug("Encoding HL7 from {} to byte stream", message.getClass().getCanonicalName());
         out.write(buf);
     }
 

Added: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/Terser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/Terser.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/Terser.java (added)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/Terser.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,33 @@
+/**
+ * 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 java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.camel.language.LanguageAnnotation;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
+@LanguageAnnotation(language = "terser")
+public @interface Terser {
+    String value();
+}

Copied: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserExpression.java (from r1372485, camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserExpression.java?p2=camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserExpression.java&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java&r1=1372485&r2=1372774&rev=1372774&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/HL7DataFormat.java (original)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserExpression.java Tue Aug 14 08:42:27 2012
@@ -14,47 +14,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.model.dataformat;
+package org.apache.camel.component.hl7;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.camel.model.DataFormatDefinition;
-import org.apache.camel.spi.DataFormat;
+import org.apache.camel.model.language.ExpressionDefinition;
 
-/**
- * Represents a <a href="http://camel.apache.org/hl7.html">HL7</a> {@link org.apache.camel.spi.DataFormat}.
- *
- * @version 
- */
-@XmlRootElement(name = "hl7")
+@XmlRootElement(name = "terser")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class HL7DataFormat extends DataFormatDefinition {
-    @XmlAttribute
-    private Boolean validate;
-
-    public HL7DataFormat() {
-        super("hl7");
-    }
-
-    public boolean isValidate() {
-        // defaults to true if not configured
-        return validate != null ? validate : true;
-    }
-
-    public Boolean getValidate() {
-        return validate;
-    }
+class TerserExpression extends ExpressionDefinition {
 
-    public void setValidate(Boolean validate) {
-        this.validate = validate;
+    public TerserExpression(String expression) {
+        super(expression);
     }
 
     @Override
-    protected void configureDataFormat(DataFormat dataFormat) {
-        setProperty(dataFormat, "validate", isValidate());
+    public String getLanguage() {
+        return "terser";
     }
 
-}
\ No newline at end of file
+}

Added: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserLanguage.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserLanguage.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserLanguage.java (added)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/TerserLanguage.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,66 @@
+/**
+ * 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 ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.util.Terser;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+import org.apache.camel.spi.Language;
+import org.apache.camel.support.ExpressionAdapter;
+import org.apache.camel.util.ExpressionToPredicateAdapter;
+import org.apache.camel.util.ObjectHelper;
+
+
+public class TerserLanguage implements Language {
+
+    public static Expression terser(final String expression) {
+        ObjectHelper.notNull(expression, "expression");
+        return new ExpressionAdapter() {
+
+            @Override
+            public Object evaluate(Exchange exchange) {
+                Message message = exchange.getIn().getBody(Message.class);
+                try {
+                    return new Terser(message).get(expression.trim());
+                } catch (HL7Exception e) {
+                    throw ObjectHelper.wrapRuntimeCamelException(e);
+                }
+            }
+
+            @Override
+            public String toString() {
+                return "terser(" + expression + ")";
+            }
+
+        };
+    }
+
+    @Override
+    public Predicate createPredicate(String expression) {
+        return ExpressionToPredicateAdapter.toPredicate(createExpression(expression));
+    }
+
+    @Override
+    public Expression createExpression(String expression) {
+        return terser(expression);
+    }
+
+}

Added: camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/ValidationContextPredicate.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/ValidationContextPredicate.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/ValidationContextPredicate.java (added)
+++ camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/ValidationContextPredicate.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,54 @@
+/**
+ * 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 ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.validation.MessageValidator;
+import ca.uhn.hl7v2.validation.ValidationContext;
+
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+import org.apache.camel.builder.ExpressionBuilder;
+import org.apache.camel.util.ObjectHelper;
+
+public class ValidationContextPredicate implements Predicate {
+
+    private Expression validatorExpression;
+
+    public ValidationContextPredicate(ValidationContext validationContext) {
+        this(ExpressionBuilder.constantExpression(validationContext));
+    }
+
+    public ValidationContextPredicate(Expression expression) {
+        this.validatorExpression = expression;
+    }
+
+    @Override
+    public boolean matches(Exchange exchange) {
+        try {
+            ValidationContext context = validatorExpression.evaluate(exchange, ValidationContext.class);
+            MessageValidator validator = new MessageValidator(context, false);
+            return validator.validate(exchange.getIn().getBody(Message.class));
+        } catch (HL7Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
+
+}

Added: camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/language/terser
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/language/terser?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/language/terser (added)
+++ camel/trunk/components/camel-hl7/src/main/resources/META-INF/services/org/apache/camel/language/terser Tue Aug 14 08:42:27 2012
@@ -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.
+#
+
+class=org.apache.camel.component.hl7.TerserLanguage
\ No newline at end of file

Added: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckExpressionTest.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckExpressionTest.java (added)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/AckExpressionTest.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,128 @@
+/**
+ * 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 ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.model.v24.message.ACK;
+import ca.uhn.hl7v2.model.v24.message.ADT_A01;
+import ca.uhn.hl7v2.model.v24.segment.MSH;
+import ca.uhn.hl7v2.model.v24.segment.PID;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import static org.apache.camel.component.hl7.HL7.ack;
+import static org.apache.camel.component.hl7.HL7.terser;
+
+public class AckExpressionTest extends CamelTestSupport {
+
+    @Test
+    public void testAckExpression() throws Exception {
+        ADT_A01 a01 = createADT01Message();
+        ACK ack = template.requestBody("direct:test1", a01, ACK.class);
+        assertEquals("AA", ack.getMSA().getAcknowledgementCode().getValue());
+        assertEquals(a01.getMSH().getMessageControlID().getValue(), ack.getMSA().getMessageControlID()
+            .getValue());
+    }
+
+    @Test
+    public void testAckExpressionWithCode() throws Exception {
+        ADT_A01 a01 = createADT01Message();
+        ACK ack = template.requestBody("direct:test2", a01, ACK.class);
+        assertEquals("CA", ack.getMSA().getAcknowledgementCode().getValue());
+        assertEquals(a01.getMSH().getMessageControlID().getValue(), ack.getMSA().getMessageControlID()
+            .getValue());
+    }
+
+    @Test
+    public void testNakExpression() throws Exception {
+        ADT_A01 a01 = createADT01Message();
+        ACK ack = template.requestBody("direct:test3", a01, ACK.class);
+        assertEquals("AE", ack.getMSA().getAcknowledgementCode().getValue());
+        assertEquals(a01.getMSH().getMessageControlID().getValue(), ack.getMSA().getMessageControlID()
+            .getValue());
+        assertEquals(String.valueOf(HL7Exception.APPLICATION_INTERNAL_ERROR), ack.getERR()
+            .getErrorCodeAndLocation(0).getCodeIdentifyingError().getIdentifier().getValue());
+    }
+
+    @Test
+    public void testNakExpressionWithParameters() throws Exception {
+        ADT_A01 a01 = createADT01Message();
+        ACK ack = template.requestBody("direct:test4", a01, ACK.class);
+        assertEquals("AR", ack.getMSA().getAcknowledgementCode().getValue());
+        assertEquals(a01.getMSH().getMessageControlID().getValue(), ack.getMSA().getMessageControlID()
+            .getValue());
+        assertEquals(String.valueOf(HL7Exception.APPLICATION_INTERNAL_ERROR), ack.getERR()
+            .getErrorCodeAndLocation(0).getCodeIdentifyingError().getIdentifier().getValue());
+        assertEquals("Problem!", ack.getERR().getErrorCodeAndLocation(0).getCodeIdentifyingError()
+            .getAlternateText().getValue());
+    }
+
+    @Test
+    public void testNakExpressionWithoutException() throws Exception {
+        ADT_A01 a01 = createADT01Message();
+        ACK ack = template.requestBody("direct:test5", a01, ACK.class);
+        assertEquals("AR", ack.getMSA().getAcknowledgementCode().getValue());
+        assertEquals(a01.getMSH().getMessageControlID().getValue(), ack.getMSA().getMessageControlID()
+            .getValue());
+        assertEquals(String.valueOf(HL7Exception.DATA_TYPE_ERROR), ack.getERR().getErrorCodeAndLocation(0)
+            .getCodeIdentifyingError().getIdentifier().getValue());
+        assertEquals("Problem!", ack.getERR().getErrorCodeAndLocation(0).getCodeIdentifyingError()
+            .getAlternateText().getValue());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:test1").transform(ack());
+                from("direct:test2").transform(ack(AckCode.CA));
+                from("direct:test3").onException(HL7Exception.class).handled(true).transform(ack()).end()
+                    .transform(terser("/.BLORG"));
+                from("direct:test4").onException(HL7Exception.class).handled(true)
+                    .transform(ack(AckCode.AR, "Problem!", HL7Exception.APPLICATION_INTERNAL_ERROR)).end()
+                    .transform(terser("/.BLORG"));
+                from("direct:test5").transform(ack(AckCode.AR, "Problem!", HL7Exception.DATA_TYPE_ERROR));
+            }
+        };
+    }
+
+    private static ADT_A01 createADT01Message() throws Exception {
+        ADT_A01 adt = new ADT_A01();
+
+        // Populate the MSH Segment
+        MSH mshSegment = adt.getMSH();
+        mshSegment.getFieldSeparator().setValue("|");
+        mshSegment.getEncodingCharacters().setValue("^~\\&");
+        mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
+        mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
+        mshSegment.getMessageControlID().setValue("123");
+        mshSegment.getSequenceNumber().setValue("123");
+        mshSegment.getMessageType().getMessageType().setValue("ADT");
+        mshSegment.getMessageType().getTriggerEvent().setValue("A01");
+
+        // Populate the PID Segment
+        PID pid = adt.getPID();
+        pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
+        pid.getPatientName(0).getGivenName().setValue("John");
+        pid.getPatientIdentifierList(0).getID().setValue("123456");
+
+        return adt;
+    }
+
+}

Modified: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecBoundaryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecBoundaryTest.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecBoundaryTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecBoundaryTest.java Tue Aug 14 08:42:27 2012
@@ -48,7 +48,7 @@ public class HL7MLLPCodecBoundaryTest ex
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec").process(new Processor() {
+                from("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         // check presence of correct message type
                         exchange.getIn().getBody(MDM_T02.class);
@@ -72,7 +72,7 @@ public class HL7MLLPCodecBoundaryTest ex
         assertEquals(1022, message.length());
         MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
         mockEndpoint.expectedMessageCount(1);
-        template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", message);
+        template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", message);
         mockEndpoint.assertIsSatisfied();
     }
 

Modified: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecLongTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecLongTest.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecLongTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecLongTest.java Tue Aug 14 08:42:27 2012
@@ -54,7 +54,7 @@ public class HL7MLLPCodecLongTest extend
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec").process(new Processor() {
+                from("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         assertEquals(70010, exchange.getIn().getBody().toString().length());
                         MDM_T02 input = (MDM_T02)exchange.getIn().getBody(Message.class);
@@ -81,7 +81,7 @@ public class HL7MLLPCodecLongTest extend
         }
         message = message.substring(0, message.length() - 1);
         assertEquals(70010, message.length());
-        String out = (String)template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", message);
+        String out = (String)template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", message);
         assertEquals("some response", out);
         // END SNIPPET: e2
     }

Modified: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecPlainStringTest.java Tue Aug 14 08:42:27 2012
@@ -48,7 +48,7 @@ public class HL7MLLPCodecPlainStringTest
         mock.expectedBodiesReceived("Bye World");
 
         // send plain hello world as String
-        Object out = template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", "Hello World");
+        Object out = template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", "Hello World");
 
         assertMockEndpointsSatisfied();
 
@@ -61,7 +61,7 @@ public class HL7MLLPCodecPlainStringTest
         return new RouteBuilder() {
             public void configure() throws Exception {
                 // START SNIPPET: e2
-                from("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec")
+                from("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec")
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             // use plain String as message format

Modified: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecStandAndEndBytesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecStandAndEndBytesTest.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecStandAndEndBytesTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecStandAndEndBytesTest.java Tue Aug 14 08:42:27 2012
@@ -53,7 +53,7 @@ public class HL7MLLPCodecStandAndEndByte
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec")
+                from("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec")
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             Message input = exchange.getIn().getBody(Message.class);
@@ -81,7 +81,7 @@ public class HL7MLLPCodecStandAndEndByte
         in.append("\r");
         in.append(line2);
 
-        String out = (String)template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
+        String out = (String)template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
 
         String[] lines = out.split("\r");
         assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123", lines[0]);
@@ -109,7 +109,7 @@ public class HL7MLLPCodecStandAndEndByte
         QRD qrd = adr.getQRD();
         qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");
 
-        return adr.getMessage();
+        return adr;
     }
 
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java Tue Aug 14 08:42:27 2012
@@ -50,7 +50,7 @@ public class HL7MLLPCodecTest extends Ca
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec")
+                from("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec")
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             Message input = exchange.getIn().getBody(Message.class);
@@ -79,7 +79,7 @@ public class HL7MLLPCodecTest extends Ca
         in.append("\n");
         in.append(line2);
 
-        String out = (String)template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
+        String out = (String)template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
         // END SNIPPET: e2
 
         String[] lines = out.split("\r");
@@ -109,7 +109,7 @@ public class HL7MLLPCodecTest extends Ca
         QRD qrd = adr.getQRD();
         qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");
 
-        return adr.getMessage();
+        return adr;
     }
     // END SNIPPET: e3
 

Modified: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7RouteTest.java Tue Aug 14 08:42:27 2012
@@ -64,7 +64,7 @@ public class HL7RouteTest extends CamelT
         in.append("\n");
         in.append(line2);
 
-        String out = (String) template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
+        String out = (String) template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
 
         String[] lines = out.split("\r");
         assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123", lines[0]);
@@ -87,7 +87,7 @@ public class HL7RouteTest extends CamelT
         in.append("\n");
         in.append(line2);
 
-        String out = (String) template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
+        String out = (String) template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
         String[] lines = out.split("\r");
         assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123", lines[0]);
         assertEquals("PID|||123456||Doe^John", lines[1]);
@@ -109,7 +109,7 @@ public class HL7RouteTest extends CamelT
         in.append("\n");
         in.append(line2);
 
-        template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
+        template.requestBody("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
 
         assertMockEndpointsSatisfied();
     }
@@ -121,7 +121,7 @@ public class HL7RouteTest extends CamelT
                 // START SNIPPET: e1
                 DataFormat hl7 = new HL7DataFormat();
                 // we setup or HL7 listener on port 8888 (using the hl7codec) and in sync mode so we can return a response
-                from("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec")
+                from("mina2:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec")
                     // we use the HL7 data format to unmarshal from HL7 stream to the HAPI Message model
                     // this ensures that the camel message has been enriched with hl7 specific headers to
                     // make the routing much easier (see below)
@@ -213,7 +213,7 @@ public class HL7RouteTest extends CamelT
         pid.getPatientName(0).getGivenName().setValue("John");
         pid.getPatientIdentifierList(0).getID().setValue("123456");
 
-        return adt.getMessage();
+        return adt;
     }
 
 }

Modified: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java Tue Aug 14 08:42:27 2012
@@ -18,17 +18,20 @@ package org.apache.camel.component.hl7;
 
 import ca.uhn.hl7v2.HL7Exception;
 import ca.uhn.hl7v2.model.DataTypeException;
+import ca.uhn.hl7v2.parser.Parser;
+import ca.uhn.hl7v2.parser.PipeParser;
+import ca.uhn.hl7v2.validation.impl.NoValidation;
+
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-/**
- * @version 
- */
 public class HL7ValidateTest extends CamelTestSupport {
 
+    private HL7DataFormat hl7;
+
     @Test
     public void testUnmarshalFailed() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:unmarshal");
@@ -46,6 +49,7 @@ public class HL7ValidateTest extends Cam
 
         assertMockEndpointsSatisfied();
     }
+        
 
     @Test
     public void testUnmarshalOk() throws Exception {
@@ -57,13 +61,29 @@ public class HL7ValidateTest extends Cam
 
         assertMockEndpointsSatisfied();
     }
+    
+    @Test
+    public void testUnmarshalOkCustom() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:unmarshal");
+        mock.expectedMessageCount(1);
+
+        String body = createHL7AsString();
+        template.sendBody("direct:unmarshalOkCustom", body);
+
+        assertMockEndpointsSatisfied();
+    }    
 
     protected RouteBuilder createRouteBuilder() throws Exception {
+        Parser p = new PipeParser();
+        p.setValidationContext(new NoValidation());
+        hl7 = new HL7DataFormat();
+        hl7.setParser(p);
+        
         return new RouteBuilder() {
             public void configure() throws Exception {
                 from("direct:unmarshalFailed").unmarshal().hl7().to("mock:unmarshal");
-
                 from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
+                from("direct:unmarshalOkCustom").unmarshal(hl7).to("mock:unmarshal");
             }
         };
     }

Copied: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7XmlDataFormatTest.java (from r1372485, camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7XmlDataFormatTest.java?p2=camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7XmlDataFormatTest.java&p1=camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java&r1=1372485&r2=1372774&rev=1372774&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7XmlDataFormatTest.java Tue Aug 14 08:42:27 2012
@@ -16,9 +16,12 @@
  */
 package org.apache.camel.component.hl7;
 
-import ca.uhn.hl7v2.HL7Exception;
-import ca.uhn.hl7v2.model.DataTypeException;
-import org.apache.camel.CamelExecutionException;
+import ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.parser.GenericParser;
+import ca.uhn.hl7v2.parser.Parser;
+import ca.uhn.hl7v2.util.Terser;
+import ca.uhn.hl7v2.validation.impl.NoValidation;
+
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -27,43 +30,47 @@ import org.junit.Test;
 /**
  * @version 
  */
-public class HL7ValidateTest extends CamelTestSupport {
+public class HL7XmlDataFormatTest extends CamelTestSupport {
+
+    private HL7DataFormat hl7;
 
     @Test
-    public void testUnmarshalFailed() throws Exception {
+    public void testUnmarshalOk() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:unmarshal");
-        mock.expectedMessageCount(0);
+        mock.expectedMessageCount(1);
 
         String body = createHL7AsString();
-        try {
-            template.sendBody("direct:unmarshalFailed", body);
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(HL7Exception.class, e.getCause());
-            assertIsInstanceOf(DataTypeException.class, e.getCause());
-            assertTrue("Should be a validation error message", e.getCause().getMessage().startsWith("Failed validation rule"));
-        }
+        template.sendBody("direct:unmarshalOk", body);
 
         assertMockEndpointsSatisfied();
     }
-
+    
     @Test
-    public void testUnmarshalOk() throws Exception {
+    public void testUnmarshalOkXml() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:unmarshal");
         mock.expectedMessageCount(1);
 
         String body = createHL7AsString();
-        template.sendBody("direct:unmarshalOk", body);
+        Message msg = hl7.getParser().parse(body);
+        String xml = hl7.getParser().encode(msg, "XML");
+        assertTrue(xml.contains("<ORM_O01"));
+        template.sendBody("direct:unmarshalOkXml", xml);
 
         assertMockEndpointsSatisfied();
-    }
+        Message received = mock.getReceivedExchanges().get(0).getIn().getMandatoryBody(Message.class);
+        assertEquals("O01", new Terser(received).get("MSH-9-2"));
+    }    
 
     protected RouteBuilder createRouteBuilder() throws Exception {
+        Parser p = new GenericParser();
+        p.setValidationContext(new NoValidation());
+        hl7 = new HL7DataFormat();
+        hl7.setParser(p);
+        
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("direct:unmarshalFailed").unmarshal().hl7().to("mock:unmarshal");
-
                 from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
+                from("direct:unmarshalOkXml").unmarshal(hl7).to("mock:unmarshal");
             }
         };
     }

Added: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/MessageValidatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/MessageValidatorTest.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/MessageValidatorTest.java (added)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/MessageValidatorTest.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,136 @@
+/**
+ * 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 ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.model.v24.message.ADT_A01;
+import ca.uhn.hl7v2.model.v24.segment.MSH;
+import ca.uhn.hl7v2.model.v24.segment.PID;
+import ca.uhn.hl7v2.validation.MessageRule;
+import ca.uhn.hl7v2.validation.ValidationContext;
+import ca.uhn.hl7v2.validation.ValidationException;
+import ca.uhn.hl7v2.validation.impl.DefaultValidation;
+import ca.uhn.hl7v2.validation.impl.MessageRuleBinding;
+import ca.uhn.hl7v2.validation.impl.ValidationContextImpl;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import static org.apache.camel.component.hl7.HL7.messageConformsTo;
+
+public class MessageValidatorTest extends CamelTestSupport {
+
+    private static final ValidationException[] VALIDATION_OK = new ValidationException[0];
+    private ValidationContext defaultContext;
+    private ValidationContextImpl customContext;
+
+    @Override
+    protected void doPreSetup() throws Exception {
+        defaultContext = new DefaultValidation();
+        customContext = new DefaultValidation();
+        @SuppressWarnings("serial")
+        MessageRule rule = new MessageRule() {
+
+            @Override
+            public String getDescription() {
+                return null;
+            }
+
+            @Override
+            public String getSectionReference() {
+                return null;
+            }
+
+            @Override
+            public ValidationException[] test(Message msg) {
+                ADT_A01 a01 = (ADT_A01)msg;
+                if (a01.getPID().getAdministrativeSex().getValue() == null) {
+                    ValidationException[] e = new ValidationException[1];
+                    e[0] = new ValidationException("No gender provided!");
+                    return e;
+                }
+                return VALIDATION_OK;
+            }
+
+        };
+        MessageRuleBinding binding = new MessageRuleBinding("2.4", "ADT", "A01", rule);
+        customContext.getMessageRuleBindings().add(binding);
+    }
+
+    @Test
+    public void testDefaultValidationContext() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:test1");
+        mock.expectedMessageCount(1);
+        Message msg = createADT01Message();
+        template.sendBody("direct:test1", msg);
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test(expected = CamelExecutionException.class)
+    public void testCustomValidationContext() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:test2");
+        mock.expectedMessageCount(0);
+        Message msg = createADT01Message();
+        template.sendBody("direct:test2", msg);
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testDynamicCustomValidationContext() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:test3");
+        mock.expectedMessageCount(1);
+        Message msg = createADT01Message();
+        template.sendBodyAndHeader("direct:test3", msg, "validator", defaultContext);
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:test1").validate(messageConformsTo(defaultContext)).to("mock:test1");
+                from("direct:test2").validate(messageConformsTo(customContext)).to("mock:test2");
+                from("direct:test3").validate(messageConformsTo(header("validator"))).to("mock:test3");
+            }
+        };
+    }
+
+    private static Message createADT01Message() throws Exception {
+        ADT_A01 adt = new ADT_A01();
+
+        // Populate the MSH Segment
+        MSH mshSegment = adt.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("ADT");
+        mshSegment.getMessageType().getTriggerEvent().setValue("A01");
+
+        // Populate the PID Segment
+        PID pid = adt.getPID();
+        pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
+        pid.getPatientName(0).getGivenName().setValue("John");
+        pid.getPatientIdentifierList(0).getID().setValue("123456");
+
+        return adt;
+    }
+}

Added: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/TerserExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/TerserExpressionTest.java?rev=1372774&view=auto
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/TerserExpressionTest.java (added)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/TerserExpressionTest.java Tue Aug 14 08:42:27 2012
@@ -0,0 +1,125 @@
+/**
+ * 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 ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.model.v24.message.ADT_A01;
+import ca.uhn.hl7v2.model.v24.segment.MSH;
+import ca.uhn.hl7v2.model.v24.segment.PID;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import static org.apache.camel.component.hl7.HL7.terser;
+
+
+public class TerserExpressionTest extends CamelTestSupport {
+
+    private static final String PATIENT_ID = "123456";
+
+    @Test
+    public void testTerserExpression() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:test1");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived(PATIENT_ID);
+        template.sendBody("direct:test1", createADT01Message());
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testTerserPredicateValue() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:test2");
+        mock.expectedMessageCount(1);
+        template.sendBody("direct:test2", createADT01Message());
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testTerserPredicateNull() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:test3");
+        mock.expectedMessageCount(1);
+        template.sendBody("direct:test3", createADT01Message());
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test(expected = CamelExecutionException.class)
+    public void testTerserInvalidExpression() throws Exception {
+        template.sendBody("direct:test4", createADT01Message());
+    }
+
+    @Test(expected = CamelExecutionException.class)
+    public void testTerserInvalidMessage() throws Exception {
+        template.sendBody("direct:test4", "text instead of message");
+    }
+
+    @Test
+    public void testTerserAnnotatedMethod() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:test5");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived(PATIENT_ID);
+        template.sendBody("direct:test5", createADT01Message());
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+
+        final TerserBean terserBean = new TerserBean();
+
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:test1").transform(terser("PID-3-1")).to("mock:test1");
+                from("direct:test2").filter(terser("PID-3-1").isEqualTo(PATIENT_ID)).to("mock:test2");
+                from("direct:test3").filter(terser("PID-4-1").isNull()).to("mock:test3");
+                from("direct:test4").filter(terser("blorg gablorg").isNull()).to("mock:test3");
+                from("direct:test5").bean(terserBean).to("mock:test5");
+            }
+        };
+    }
+
+    private static Message createADT01Message() throws Exception {
+        ADT_A01 adt = new ADT_A01();
+
+        // Populate the MSH Segment
+        MSH mshSegment = adt.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("ADT");
+        mshSegment.getMessageType().getTriggerEvent().setValue("A01");
+
+        // Populate the PID Segment
+        PID pid = adt.getPID();
+        pid.getPatientName(0).getFamilyName().getSurname().setValue("Doe");
+        pid.getPatientName(0).getGivenName().setValue("John");
+        pid.getPatientIdentifierList(0).getID().setValue(PATIENT_ID);
+
+        return adt;
+    }
+
+    public class TerserBean {
+        public String patientId(@Terser(value = "PID-3-1") String patientId) {
+            return patientId;
+        }
+    }
+}

Modified: camel/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1372774&r1=1372773&r2=1372774&view=diff
==============================================================================
--- camel/trunk/parent/pom.xml (original)
+++ camel/trunk/parent/pom.xml Tue Aug 14 08:42:27 2012
@@ -93,7 +93,7 @@
     <guiceyfruit-version>2.0</guiceyfruit-version>
     <hadoop-version>1.0.3</hadoop-version>
     <hamcrest-version>1.1</hamcrest-version>
-    <hapi-version>1.2</hapi-version>
+    <hapi-version>2.0</hapi-version>
     <hawtbuf-version>1.9</hawtbuf-version>
     <hawtdb-version>1.6</hawtdb-version>
     <hawtdispatch-version>1.11</hawtdispatch-version>