Transforming HL7 v2 to XML using apache camel routes - hl7-v2

I am new to HL7 .I have to convert the HL7v2 to XML using apache camel routes.I am extracting the HL7 message from file.
Can any one help me how to convert HL7 to XML

There is an HL7 component for unmarshalling the file into a HAPI message. The HAPI api also includes an XMLParser that will convert the message into xml. So you should be able to combine the two into a simple camel route like the following:
<bean id="hl7XmlConverter" class="example.Hl7XmlConverter" />
<bean id="hl7FileFilter"
class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter">
<property name="includes" value="*.hl7" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="hl7FileRoute">
<from
uri="file:///tmp/test/?delete=true&moveFailed=.error&filter=#hl7FileFilter" />
<convertBodyTo type="java.lang.String" />
<log message="HL7 Request: ${body}" />
<unmarshal>
<hl7 validate="true" />
</unmarshal>
<bean ref="hl7XmlConverter"/>
<log message="HL7 Response: ${body}" />
</route>
</camelContext>
Where the bean is just a simple method:
public String convertMessage(Message message) throws HL7Exception{
XMLParser parser = new DefaultXMLParser();
return parser.encode(message);
}
Depending on your desired xml format, you could also add an xslt after the bean.

Related

Retrieve clob data using apache camel

I am polling clob column using apache camel as below.
<route>
<from uri="timer://timer1?period=2m" />
<setBody>
<simple>
SELECT CLOB_COLUMN FROM TABLE WHERE STATUS=1
</simple>
</setBody>
<to uri="jdbc:dataSource?outputType=StreamList" />
<split streaming="true">
<simple>${body}</simple>
<setProperty name="myProperty">
<simple>${body[CLOB_COLUMN]}</simple>
</setProperty>
<to uri="direct:processing"/>
</split>
</route>
Body of processing route shows like oracle.sql.clob#123456. How can I convert that value to String format.
Camel 2.23 version used to give value as String format but after upgraded to 3.16, its giving clob value.

JMS Selector for messages having an underscore in one header with Camel and Blueprint

I need to cleanup some messages in a JMS queue (ActiveMQ) where some of the message header contains an underscore.
Some example
Message 1:
header MyObject=urn:sap:order:ID1234
body = <some xml>
Message 2:
header MyObject=urn:sap:order:ID9834_ABC
body = <some xml>
My goal is to move the only messages looking like Message 2 (and all similar containing an underscore) and not messages without underscores (like Message 1) from the original queue MY_ORDERS.
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
<cm:property-placeholder persistent-id="com.mycompany.order-temp" update-strategy="reload">
<cm:default-properties>
<cm:property name="amq.url" value="tcp://localhost:61616" />
<cm:property name="queue.to.dump" value="activemq:queue:MY_ORDERS?selector=MyObject+LIKE+'urn:order:%_%'" />
</cm:default-properties>
</cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<onException useOriginalMessage="true">
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="activemq:queue:MY_ORDERS_DLQ?preserveMessageQos=true" />
</onException>
<route id="route-orders-to-temp">
<from uri="{{queue.to.dump}}" />
<to uri="activemq:queue:MY_ORDERS_TEMP" />
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="${amq.url}" />
</bean>
</blueprint>
By using the following posts and because the official ActiveMQ Documentation about selectors says it uses SQL 92 syntax:
https://stackoverflow.com/a/17102616/628006
https://stackoverflow.com/a/5822/628006
I tried all the following combinations:
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%\_%'
selector=MyObject+LIKE+'urn:sap:order:%[_]%'
selector=MyObject+LIKE+'urn:sap:order:[a-Z0-9]*_[a-Z0-9]*'
But none of them seems to work. Any thoughts?
Finally I found the solution of my problem: there is a special syntax to define the escaping character which does not seems to be set by default.
By looking on Internet I finally found the following post which clearly shows the underscore must be escaped by e.g. \ then defining the escape character with ESCAPE '\'
If I apply to my cases the following lines:
selector=MyObject+LIKE+'urn:sap:order:%_%' ESCAPE '\'
selector=MyObject+LIKE+'urn:sap:order:%\_%' ESCAPE '\'
will just work fine with the additional ESCAPE '\' at the end of the selector.

Camel Spring DSL Route: set http query parameter

I'm new to camel and in my opinion the documentation is large but could be structured better. So it's hard to find what you are looking for.
My problem: I've defined a camel route in spring DSL for redirection from the camel servlet to another http endpoint. On redirecting, some http query parameter like PARAM1 should be set:
<route id="bridge">
<from uri="servlet:bridge" />
<setHeader headerName="HTTP_QUERY">
<constant>PARAM1=value1</constant>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
The redirection works, but the "TO" endpoint doesn't gets the parameter PARAM1.
Where is my mistake?
regards jundl
To send query parameters to an http end point you can use HTTP_QUERY header as below
<route>
<from uri="servlet:bridge" />
<setHeader headerName="HTTP_QUERY">
<constant>param1=value1&param2=value2</constant>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
and if you want some dynamic values like a header value as value1 you must use camel simple tag as below
<route>
<from uri="servlet:bridge" />
<setHeader headerName="HTTP_QUERY">
<simple>param1=${headerNameOfValue1}&param2=value2</simple>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
Hope it helps!
try this http://camel.apache.org/constant.html
<route>
<from uri="servlet:bridge" />
<setHeader headerName="PARAM1">
<constant>value1</constant>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
You are using a wrong headerName. If you want to use in a DSL route the Exchange.HTTP_QUERY constant, you need to write its value. That is, instead of write "HTTP_QUERY", you have to write "CamelHttpQuery". Take a look to https://camel.apache.org/maven/current/camel-core/apidocs/constant-values.html.
If you change your code in this way, it will work:
<route id="bridge">
<from uri="servlet:bridge" />
<setHeader headerName="CamelHttpQuery">
<constant>PARAM1=value1</constant>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>

Message splitting in Camel

I am trying to write a camel route which would send different elements of a list to different queues.
The message body would be a list with 2 xml's. For example:
<Cat>
<Name>Cat1</Name>
</Cat>,
<Dog>
<Name>Dog1</Name>
</Dog>
Now, I need to send the 'Cat' part of the message i.e. Cat1 part to queue1 and the 'Dog' part of xml i.e. Dog1 to a different queue?
This is the route that I have, but is not working:
<route>
<from uri="jms:queue:InQueue" />
<choice>
<when>
<simple>${in.body} regex 'Cat'</simple>
<to uri="jms:queue:CatQueue" />
</when>
<when>
<simple>${in.body} regex 'Dog'</simple>
<to uri="jms:queue:DogQueue" />
</when>
</choice>
</route>
Any ideas on what am i doing wrong here?
First, you have to split the list using the , token. Second, you have to parse the XML parts using XPath expressions and send the messages to the appropriate JMS queues:
<route>
<from uri="jms:queue:InQueue" />
<split>
<tokenize token=","/>
<log message="Working on split: ${body}" />
<choice>
<when>
<xpath>/Cat</xpath>
<to uri="jms:queue:CatQueue" />
</when>
<when>
<xpath>/Dog</xpath>
<to uri="jms:queue:DogQueue" />
</when>
</choice>
</split>
</route>

How We Can Break a String in Wso2esb using Xpath

I wish to break a string in wso2esb using xpath
my input like this
<property name="Message" value="assetname:ups,assetcode:452chi,assetid:548935,assetvalue:215" scope="default"/>
i need break in same property using xpath
i need like this
assetname:ups
assetcode=452chi
assetid=54895
assetvalue=215
for this i tried with tokenize function but wso2esb showing errors
my configure file
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Xpathcheck" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="max" value="1" scope="default" type="STRING"/>
<property name="min" value="1" scope="default" type="STRING"/>
<property name="MessageText" expression="fn:concat('Assetid:',get-property('min'),',','Assetname:',get-property('max'))" scope="default" type="STRING"/>
<property name="Tokenize" expression="fn:tokenize(get-property('Messagetext'),',')" scope="default" type="STRING"/>
<log>
<property name="MessageText" expression="get-property('MessageText')"/>
<property name="Tokenize" expression="get-property('Tokenize')"/>
</log>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
But its throwing errors like this u have any idea for this i need store this in Db table as a one field which look like separate lines
error is
ERROR - SynapseXPath Evaluation of the XPath expression fn:tokenize(get-property('Messagetext'),',') resulted in an error
org.jaxen.UnresolvableException: No Such Function tokenize
tokenize is a function comes with XPath 2.0. To enable XPath 2.0 functions uncomment the following entry in the synapse.properties file which is located at $ESB_HOME/repository/conf directory
synapse.xpath.dom.failover.enabled=true
then you have to specify the mediator as follows,
<property name="Message" value="a,b,c,d,e" scope="default"/>
<property xmlns:fn="http://www.w3.org/2005/xpath-functions" name="Tokenize" expression="fn:tokenize(syn:get-property('Message'),',')" scope="default" type="STRING"/>
I dont think this can be done through XPath, XPath is to navigate elements in an XML. You can do this by using a script mediator and write a JS to break the property values.
use the following to access the ESB params from the script mediator
<script language="js"> var test_param = mc.getProperty('Message')
Use the following to retrieve the params within the script mediator back to the ESB
mc.setProperty("param1",var1)
mc.setProperty("param2",var2)
Use the javascript to carry out the required string manupulations

Resources