message enricher in mule

7
* Message Enricher In Mule

Upload: sashidhar-rao-gds

Post on 07-Jan-2017

945 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Message enricher in mule

*Message Enricher In Mule

Page 2: Message enricher in mule

*One common scenario involves the need to enrich an incoming message with information that isn’t provided by the source system

*Mule currently supports enrichment of flow variables and message headers only.

*The “enrichment resource” can be any message processor, outbound connector, processor-chain or flow-ref.  

*By having inline enrich tags for multiple targets

Page 3: Message enricher in mule

* <?xml version="1.0" encoding="UTF-8"?>*  <mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"

xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"

* xmlns:spring="http://www.springframework.org/schema/beans" * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"* xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-

current.xsd* http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd* http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd* http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd* http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd* http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd* http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">* <http:listener-config name="HTTP_Listener_8124" host="localhost" port="8124" doc:name="HTTP Listener Configuration"/>* <data-mapper:config name="XML_To_XML" transformationGraphPath="xml_to_xml.grf" doc:name="XML_To_XML"/>* <http:request-config name="HTTP_Request_Configuration" host="localhost" port="8124" doc:name="HTTP Request Configuration"/>* <flow name="encricherFlow">* <http:listener config-ref="HTTP_Listener_8124" path="/enricher" doc:name="HTTP"/>* <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>* <enricher doc:name="Message Enricher">* <flow-ref name="assign_state_using_zip" doc:name="get state variable"/>* <enrich target="#[sessionvariable:newState]" source="#[xpath://enrichedPayload/state]"/>* <!-- <enrich target="#[variable:newState]" source="#[xpath://enrichedPayload/state]"/> -->* <enrich target="#[variable:country]" source="#[xpath://enrichedPayload/country']"/>* </enricher>*

Page 4: Message enricher in mule

* <logger doc:name="Logger"/>* <data-mapper:transform config-ref="XML_To_XML" doc:name="XML To XML">* <data-mapper:input-arguments>* <data-mapper:input-argument key="CountryCode">#[flowVars.country]</data-mapper:input-argument>* <data-mapper:input-argument key="State">#[sessionVars.newState]</data-mapper:input-argument>* </data-mapper:input-arguments>* </data-mapper:transform>* </flow>* <sub-flow name="assign_state_using_zip">* <expression-component doc:name="Andhra"><![CDATA[String response="<enrichedPayload>";* if( xpath3("//address/zip").equals("518001")){*   response += "<state>AP</state>";* }* else if(xpath3("//address/zip").equals("500001")){* response += "<state>TS</state>";* }* else{* response += "<state>INVALID STATE</state>";* }*  if( xpath3("//address/country").equalsIgnoreCase("INDIA")){*   response += "<country>+91</country>";* }* else if(xpath3("//address/country").equalsIgnoreCase("UK")){* response += "<state>+44</state>";* }* else{* response += "<state>INVALID Country</state>";* }*  response += "</enrichedPayload>";*  

Page 5: Message enricher in mule

* payload = response;* System.out.println("Enriched Payload is::"+payload);]]></expression-component>* </sub-flow>* <flow name="complexencricherFlow">* <http:listener config-ref="HTTP_Listener_8124" path="/complexenricher" doc:name="HTTP"/>* <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>* <enricher doc:name="Message Enricher" target="#[flowVars.state]" source="#[xpath2://address/state]">* <processor-chain doc:name="Processor Chain">* <http:request config-ref="HTTP_Request_Configuration" path="/state" method="POST" doc:name="HTTP"/>* <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>* </processor-chain>* </enricher>* <data-mapper:transform config-ref="XML_To_XML" doc:name="XML To XML">* <data-mapper:input-arguments>* <data-mapper:input-argument key="State">#[flowVars.state]</data-mapper:input-argument>* </data-mapper:input-arguments>* </data-mapper:transform>* </flow>*  

Page 6: Message enricher in mule

* <flow name="muleencricherFlow">* <http:listener config-ref="HTTP_Listener_8124" path="/state" doc:name="HTTP"/>* <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>* <expression-transformer doc:name="Expression">* <return-argument evaluator="xpath2" expression="/address/zip"/>* </expression-transformer>* <choice doc:name="evaluate zip and assingn a state">* <when expression="#[payload =='518001']">* <set-payload value="&lt;address&gt;&lt;state&gt;AP&lt;/state&gt;&lt;/address&gt;" doc:name="Set Payload"/>* </when>* <when expression="#[payload =='500043']">* <set-payload value="&lt;address&gt;&lt;state&gt;TS&lt;/state&gt;&lt;/address&gt;" doc:name="Set Payload"/>* </when>* <otherwise>* <set-payload value="&lt;address&gt;&lt;state&gt;Andhra&lt;/state&gt;&lt;/address&gt;" doc:name="Set

Payload"/>* </otherwise>* </choice>* </flow>* </mule>

Page 7: Message enricher in mule

*GDS Sashidhar Rao

*Thank You