javatomcatapache-camel

How to Configure Apache Camel with an HL7 Listener and deploy inTomcat


I have been looking at using Camel in Tomcat to route HL7 data from a specified port to be processed by a persistence layer. I am really struggling to understand how to do this. I am using the Tomcat without Spring code as a basic configuration example. The Camel HL7 details are here. I don't really understand how to change the uri (or create the appropriate web.xml and camel-config-xml files) so that it will listen for MLLP connections and then route to an appropriate processing class. From the documentation the uri is:

mina:tcp://localhost:8888?sync=true&codec=#hl7codec

So far, I have a spring-servlet.xml like this (with an error cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'camel:camelContext'):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jms="http://www.springframework.org/schema/jms"
       xmlns:camel="http://activemq.apache.org/camel/schema/spring"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://activemq.apache.org/camel/schema/spring
            http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
  <bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
    <property name="charset" value="iso-8859-1"/>
</bean>

<bean id="hl7MessageHandler" class="util.HL7MessageHandlerService"/>

<camelContext id="hl7listener" xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="mina:tcp://localhost:8888?sync=true&amp;codec=#hl7codec"/>
        <to uri="bean:hl7MessageHandler?method=lookupPatient"/>
    </route>
</camelContext>
</beans>

and a web.xml like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>HL7 Consumer</display-name>

  <!-- location of spring xml files -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-servlet.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>CamelServlet</servlet-name>
    <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>CamelServlet</servlet-name>
    <url-pattern>/camel/*</url-pattern>
  </servlet-mapping>

</web-app>

I don't really understand how to configure Camel route and then to ensure that incoming messages are passed to the HL7MessageHandler.


Solution

  • See this tutorial on using Apache Camel in a web application: http://camel.apache.org/tutorial-on-using-camel-in-a-web-application.html

    Then you need to include the needed Camel components and its dependencies in the WAR file, eg the JARs in WEB-INF/lib.