Skip to content

Instantly share code, notes, and snippets.

@fganora
Created October 22, 2016 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fganora/d6df61ebb0fb490b8822ba86d7fe1d54 to your computer and use it in GitHub Desktop.
Save fganora/d6df61ebb0fb490b8822ba86d7fe1d54 to your computer and use it in GitHub Desktop.
Mule: example register object into Mule registry and access it
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<global-property name="registryKey" value="myValuableString" doc:name="Global Property"/>
<flow name="registerObjectFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/registerobject" allowedMethods="GET" doc:name="HTTP"/>
<set-variable variableName="value" value="#[message.inboundProperties.'http.query.params'.value]" doc:name="Set myString value"/>
<scripting:component doc:name="Register object">
<scripting:script engine="Groovy">
<![CDATA[muleContext.getRegistry().registerObject("${registryKey}", new String(flowVars.value))]]>
</scripting:script>
</scripting:component>
<set-payload value="#['Registered ${registryKey} = ' + flowVars.value]" doc:name="Set Payload"/>
</flow>
<flow name="lookupObjectFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/lookupobject" allowedMethods="GET" doc:name="HTTP"/>
<scripting:component doc:name="Lookup object">
<scripting:script engine="Groovy"><![CDATA[payload = muleContext.getRegistry().get("${registryKey}")]]></scripting:script>
</scripting:component>
<logger message="Value of ${registryKey} = #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment