Author: davsclaus
Date: Thu Aug 7 01:52:52 2008
New Revision: 683561
URL: http://svn.apache.org/viewvc?rev=683561&view=rev
Log:
CAMEL-786: hl7 renamed package
Added:
activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/
- copied from r683518,
activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/mina/
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/
- copied from r683518,
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/mina/
Removed:
activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/mina/
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/mina/
Modified:
activemq/camel/trunk/components/camel-hl7/pom.xml
activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java
Modified: activemq/camel/trunk/components/camel-hl7/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/pom.xml?rev=683561&r1=683560&r2=683561&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-hl7/pom.xml (original)
+++ activemq/camel/trunk/components/camel-hl7/pom.xml Thu Aug 7 01:52:52 2008
@@ -34,7 +34,7 @@
<description>Camel HL7 support</description>
<properties>
-
<camel.osgi.export.pkg>org.apache.camel.dataformat.hl7.*;org.apache.camel.component.mina.*</camel.osgi.export.pkg>
+
<camel.osgi.export.pkg>org.apache.camel.component.hl7.*;org.apache.camel.dataformat.hl7.*</camel.osgi.export.pkg>
</properties>
<repositories>
Modified:
activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java?rev=683561&r1=683518&r2=683561&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java
(original)
+++
activemq/camel/trunk/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPCodec.java
Thu Aug 7 01:52:52 2008
@@ -14,12 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.mina;
+package org.apache.camel.component.hl7;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
+import org.apache.camel.dataformat.hl7.HL7Converter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
@@ -27,8 +30,6 @@
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;
@@ -57,6 +58,8 @@
*/
public class HL7MLLPCodec implements ProtocolCodecFactory {
+ private static final transient Log LOG =
LogFactory.getLog(HL7MLLPCodec.class);
+
private static final String CHARSET_ENCODER = HL7MLLPCodec.class.getName()
+ ".charsetencoder";
private static final String CHARSET_DECODER = HL7MLLPCodec.class.getName()
+ ".charsetdecoder";
@@ -84,16 +87,17 @@
// 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
+ if (message instanceof Message) {
body = HL7Converter.toString((Message)message);
+ } else if (message instanceof String) {
+ body = (String)message;
+ } else if (message instanceof byte[]) {
+ body = new String((byte[])message);
} else {
- // fallback to the toString method
- body = message.toString();
+ throw new IllegalArgumentException("The message to encode
is not a supported type: " +
+ message.getClass().getCanonicalName());
}
+
// replace \n with \r as HL7 uses 0x0d = \r as segment
termninators
body = body.replace('\n', '\r');
@@ -106,6 +110,9 @@
// flip the buffer so we can use it to write to the out stream
bb.flip();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Encoding HL7 from " +
message.getClass().getCanonicalName() + " to byte stream");
+ }
out.write(bb);
}
@@ -132,6 +139,9 @@
if (next == END_MARKER_2) {
posEnd = in.position();
break;
+ } else {
+ // we expected the 2nd end marker
+ LOG.warn("The 2nd end marker " + END_MARKER_2 + "
was not found, but was " + b);
}
}
}
@@ -155,6 +165,9 @@
}
String body = in.getString(decoder);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Decoding HL7 from byte stream to String");
+ }
out.write(body);
} finally {
// clear the buffer now that we have transfered the data
to the String
Modified:
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java?rev=683561&r1=683518&r2=683561&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
(original)
+++
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java
Thu Aug 7 01:52:52 2008
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.mina;
+package org.apache.camel.component.hl7;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
@@ -34,11 +34,14 @@
public class HL7MLLPCodecTest extends ContextTestSupport {
protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+
+ // START SNIPPET: e1
HL7MLLPCodec codec = new HL7MLLPCodec();
codec.setCharset("iso-8859-1");
- JndiRegistry jndi = super.createRegistry();
jndi.bind("hl7codec", codec);
+ // END SNIPPET: e1
return jndi;
}
@@ -49,6 +52,12 @@
from("mina:tcp://localhost:8888?sync=true&codec=hl7codec")
.process(new Processor() {
public void process(Exchange exchange) throws
Exception {
+ Message input =
exchange.getIn().getBody(Message.class);
+
+ assertEquals("2.4", input.getVersion());
+ QRD qrd = (QRD)input.get("QRD");
+ assertEquals("0101701234",
qrd.getWhoSubjectFilter(0).getIDNumber().getValue());
+
Message response = createHL7AsMessage();
exchange.getOut().setBody(response);
}
@@ -59,8 +68,9 @@
}
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||";
+ // START SNIPPET: e2
+ 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 in = new StringBuffer();
in.append(line1);
@@ -68,12 +78,14 @@
in.append(line2);
String out =
(String)template.requestBody("mina:tcp://localhost:8888?sync=true&codec=hl7codec",
in.toString());
+ // END SNIPPET: e2
String[] lines = out.split("\r");
assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123",
lines[0]);
assertEquals("MSA|AA|123", lines[1]);
}
+ // START SNIPPET: e3
private static Message createHL7AsMessage() throws Exception {
ADR_A19 adr = new ADR_A19();
@@ -97,5 +109,6 @@
return adr.getMessage();
}
+ // END SNIPPET: e3
}
Modified:
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java?rev=683561&r1=683560&r2=683561&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java
(original)
+++
activemq/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/dataformat/hl7/HL7DataFormatTest.java
Thu Aug 7 01:52:52 2008
@@ -67,6 +67,7 @@
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:marshal").marshal(hl7).to("mock:marshal");
+
from("direct:unmarshal").unmarshal(hl7).to("mock:unmarshal");
}
};