camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1430868 - in /camel/branches/camel-2.10.x: ./ components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7DataFormatTest.java
Date Wed, 09 Jan 2013 14:14:02 GMT
Author: ningjiang
Date: Wed Jan  9 14:14:02 2013
New Revision: 1430868

URL: http://svn.apache.org/viewvc?rev=1430868&view=rev
Log:
CAMEL-5943 Applied the patch with thanks to Andrea
Merged revisions 1430724 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1430724 | ningjiang | 2013-01-09 16:06:04 +0800 (Wed, 09 Jan 2013) | 1 line
  
  CAMEL-5943 Applied the patch with thanks to Andrea
........

Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java
    camel/branches/camel-2.10.x/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7DataFormatTest.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1430724

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java?rev=1430868&r1=1430867&r2=1430868&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7DataFormat.java
Wed Jan  9 14:14:02 2013
@@ -24,6 +24,7 @@ import ca.uhn.hl7v2.util.Terser;
 import org.apache.camel.Exchange;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.IOHelper;
 
 /**
  * HL7 DataFormat (supports v2.x of the HL7 protocol).
@@ -67,7 +68,8 @@ public class HL7DataFormat implements Da
     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);
-        outputStream.write(encoded.getBytes());
+        String charsetName = IOHelper.getCharsetName(exchange);
+        outputStream.write(encoded.getBytes(charsetName));
     }
 
     public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception
{

Modified: camel/branches/camel-2.10.x/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7DataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7DataFormatTest.java?rev=1430868&r1=1430867&r2=1430868&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7DataFormatTest.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7DataFormatTest.java
Wed Jan  9 14:14:02 2013
@@ -21,7 +21,7 @@ import ca.uhn.hl7v2.model.v24.message.AD
 import ca.uhn.hl7v2.model.v24.segment.MSA;
 import ca.uhn.hl7v2.model.v24.segment.MSH;
 import ca.uhn.hl7v2.model.v24.segment.QRD;
-
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -31,7 +31,9 @@ import org.junit.Test;
  * Unit test for HL7 DataFormat.
  */
 public class HL7DataFormatTest extends CamelTestSupport {
-
+    private static final String NONE_ISO_8859_1 = 
+        "\u221a\u00c4\u221a\u00e0\u221a\u00e5\u221a\u00ed\u221a\u00f4\u2248\u00ea";
+    
     @Test
     public void testMarshal() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:marshal");
@@ -45,6 +47,32 @@ public class HL7DataFormatTest extends C
 
         assertMockEndpointsSatisfied();
     }
+    
+    @Test
+    public void testMarshalISO8859() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:marshal");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(byte[].class);
+        mock.message(0).body(String.class).contains("MSA|AA|123");
+        mock.message(0).body(String.class).contains("QRD|20080805120000");
+        mock.message(0).body(String.class).not().contains(NONE_ISO_8859_1);
+        Message message = createHL7AsMessage();
+        template.sendBodyAndProperty("direct:marshal", message, Exchange.CHARSET_NAME, "ISO-8859-1");
+        assertMockEndpointsSatisfied();
+    }
+    
+    @Test
+    public void testMarshalUTF8() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:marshal");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(byte[].class);
+        mock.message(0).body(String.class).contains("MSA|AA|123");
+        mock.message(0).body(String.class).contains("QRD|20080805120000");
+        mock.message(0).body(String.class).contains(NONE_ISO_8859_1);
+        Message message = createHL7AsMessage();
+        template.sendBodyAndProperty("direct:marshal", message, Exchange.CHARSET_NAME, "UTF-8");
+        assertMockEndpointsSatisfied();
+    }
 
     @Test
     public void testUnmarshal() throws Exception {
@@ -98,7 +126,7 @@ public class HL7DataFormatTest extends C
 
     private static Message createHL7AsMessage() throws Exception {
         ADR_A19 adr = new ADR_A19();
-
+       
         // Populate the MSH Segment
         MSH mshSegment = adr.getMSH();
         mshSegment.getFieldSeparator().setValue("|");
@@ -113,6 +141,7 @@ public class HL7DataFormatTest extends C
         MSA msa = adr.getMSA();
         msa.getAcknowledgementCode().setValue("AA");
         msa.getMessageControlID().setValue("123");
+        msa.getMsa3_TextMessage().setValue(NONE_ISO_8859_1);
 
         QRD qrd = adr.getQRD();
         qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");



Mime
View raw message