how to send same payload to multiple component in mule? - java

I have a problem where one mule component transform the payload object into some other value. Ex: Suppose my payload contain student object.
Initial value of Student name=a;
My first mule component change student name to x;
Student s=new Student();
s.setName("x");
My second mule component receive name as X from payload. But I want original value as 'a'.
I tried checking original payload of mule but that value is also changed..
<flow .....
<component> </component> // 1st component
<component></component> //2nd component
</flow>
I want same payload(original) (Student object with name a) in both the component..how can I do that?
I have checked original payload and that has been transformed..
Thanks

You can use <all> to send same payload to different components like
<flow .....
<all>
<component> </component> // 1st component
<component></component> //2nd component
</all>
</flow>
or, a different way to approach same thing is to store the original payload in a variable and then replace the payload with the previous one like:
<set-variable variableName="originalPayload" value="#[message.payload]" />
and then,
<set-payload value="#[flowVars.originalPayload]"/>

Mule also use scatter gather component, which sends the payload to multiple endpoints in parallel. This component has been introduced from Mule 3.5.0 ..
example :
<scatter-gather doc:name="Scatter-Gather" timeout="6000">
<flow-ref name="flightBroker1" />
<flow-ref name="flightBroker2" />
<flow-ref name="flightBroker3" />
</scatter-gather>
Here is the reference :- https://developer.mulesoft.com/docs/display/current/Scatter-Gather

Related

How to use method with parameters in Camel XML DSL?

I've got a problem with using method with parameters in Camel XML DSL.
What I've done is something like this:
I've created below bean before my camelContext
<bean id="properties" class="java.util.Properties"/>
The thing I would like to do is using method 'put' from HashTable, which extends Properties.
When I call a method without parameter it's working perfectly fine.
<method ref="properties" method="NAME OF METHOD THAT HAS NO PARAMETERS">
or
<bean ref="properties" method="SAME AS ABOVE"/>
Method that I'm trying to use:
public synchronized V put(K key, V value)
But when I'm trying to use something like the code below I would like to assign some parameters
I've tried a lot of possibilities, maybe it's impossible or my knowledge of syntax is poor:
<method ref="properties" method="put" argument="key_el" arugment="val_el"/>
<method ref="properties" method="put" value="key_el" value="val_el"/>
<method ref="properties" method="put?keyEl&valEl"/>
<method ref="properties" method="put">
<argument id="key" value="someKey" type="java.lang.String"/>
<argument id="value" value="someValue" type="java.lang.String"/>
</method>
There's plenty more that I've tired, some of them are just not worth of showing. I read from people apache and camel documentation, that there's possibility to make it somehow but there was no example of doing that in XML DSL.
Thanks in advance for any hints and help.
You can call beans method with arguments using method="put('key', 'value')". You can also use simple syntax there if you need values from the Exchange like body, headers or exchange properties `method="put('bodyValue', ${body})"``
This approach also works with simple language. Say if you have object stored in to message header you can call it's methods using ${headers.helloBean.hello('Tim')}
<bean id="ExampleProperties" class="java.util.Properties" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="testRoute">
<from uri="direct:testRoute" />
<bean ref="ExampleProperties" method="put('bodyValue', ${body})" />
<setBody>
<simple>${bean:ExampleProperties?method=get('bodyValue')}</simple>
</setBody>
<log message="Body value: ${body}" />
</route>
</camelContext>
Be careful when storing values to beans instead of using body, headers or exchange properties as beans persist between exchanges.

How to read all the tags present inside entry tag based on tag name and store its value in a hashmap using java

Here is the xml code in which I want to get value based on tag name which are present under entry tag and store it in hashmap as a key value pair
<entry xmlns="http://www.w3.org/2005/Atom">
<title>Isra쭩쳳 doden drie Palestijnse aanvallers</title>
<updated>2016-02-17T17:13:11.477Z</updated>
<rights>This material may not be published</rights>
<content type="text/plain" xml:lang="nl">Isra쭩쳳 doden drie Palestijnse aanvallers</content>
<apcm:ContentMetadata xmlns:apcm="http://ap.org/schemas/03/2005/apcm">
<apcm:Priority Numeric="4" Legacy="r" />
<apcm:ConsumerReady>TRUE</apcm:ConsumerReady>
<apcm:ByLine>Paul Gabel</apcm:ByLine>
<apcm:HeadLine>Isra쭩쳳 doden drie Palestijnse aanvallers</apcm:HeadLine>
<apcm:OriginalHeadLine>Isra쭩쳳 doden drie Palestijnse aanvallers</apcm:OriginalHeadLine>
<apcm:Keywords>Westoever</apcm:Keywords>
<apcm:Cycle>BC</apcm:Cycle>
<apcm:Selector>-----</apcm:Selector>
<apcm:SlugLine>Westoever 2016/02/17 22:43:58</apcm:SlugLine>
<apcm:MediaType>Text</apcm:MediaType>
<apcm:SubjectClassification System="Editorial" Authority="AP Category Code" Value="DUT" Id="DUT" />
<apcm:Property Name="EntitlementMatch" Id="urn:publicid:ap.org:product:45147" Value="All Text for Elasticsearch" />
<apcm:Property Name="SequenceNumber" Value="InSequence" Id="236167493" />
<apcm:FirstCreated>2016-02-14T15:43:48Z</apcm:FirstCreated>
</apcm:ContentMetadata>
<apnm:NewsManagement xmlns:apnm="http://ap.org/schemas/03/2005/apnm">
<apnm:ManagementId>urn:publicid:ap.org:f02232ade7f4394d95337af4b9200c47</apnm:ManagementId>
<apnm:ManagementSequenceNumber>0</apnm:ManagementSequenceNumber>
</apnm:NewsManagement>
</entry>
Use JaxB. Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML schemas and Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications.
example

Mule db component Input payload from another db query

I need a basic Mule flow in order to select rows from one database, transform the payload and call a procedure in another database. I don't want to use DataMapper component, I would like to use Java Transformer instead.
My XML flow:
<set-variable variableName="currentOrder" value="#[payload.increment_id]" doc:name="Variable"/>
<db:select config-ref="MySQL_Configuration" doc:name="GET ORDER">
<db:parameterized-query><![CDATA[select id from sales where id=#[currentOrder]]]></db:parameterized-query>
</db:select>
<custom-transformer class="com.mycompany.transformers.TargerProc" doc:name="Java"/>
<db:stored-procedure config-ref="Oracle_Configuration" doc:name="PROC1">
<db:parameterized-query><![CDATA[call proc1(:P1,:P2)]]></db:parameterized-query>
<db:in-param name="P1" type="NUMERIC" value="#[payload.id]"/>
<db:out-param name="P2" type="NUMERIC" value=""/>
</db:stored-procedure>
First problem:
Message payload is of type: CaseInsensitiveHashMap
Could someone shed some light on this? I think it is really simple to achieve this.
Thanks in advance!
Try this <db:parameterized-query>{ call proc1(:P1,:P2) }</db:parameterized-query> :-
<set-variable variableName="currentOrder" value="#[payload.increment_id]" doc:name="Variable"/>
<db:select config-ref="MySQL_Configuration" doc:name="GET ORDER">
<db:parameterized-query><![CDATA[select id from sales where id=#[currentOrder]]]></db:parameterized-query>
</db:select>
<custom-transformer class="com.mycompany.transformers.TargerProc" doc:name="Java"/>
<db:stored-procedure config-ref="Oracle_Configuration" doc:name="PROC1">
<db:parameterized-query>{ call proc1(:P1,:P2) }</db:parameterized-query>
<db:in-param name="P1" type="NUMERIC" value="#[payload.id]"/>
<db:out-param name="P2" type="NUMERIC" value=""/>
</db:stored-procedure>

MULE ESB -> SOAP mapping - Easy Method don't work

Hi all I'm new in Mule so please go easy on me. First of all I will show you example on SOAP UI:
Here is WSDL FILE: wsdl file
Its pretty easy. I want to make exacly the same mule flow (no input data etc - payload set in code). The problem is that I simple even can't start. I read tutorial:
http://www.mulesoft.org/documentation/display/current/XML-only+SOAP+Web+Service+Example
But still I can't do dataMappings like here. Any idea what I'm doing wrong my whole flow isn't big ... now its look like this:
<flow doc:name="PostRequest" name="PostRequest">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="getPostRequest" doc:name="HTTP" />
<cxf:jaxws-client operation="PostRequest" doc:name="SOAP"
enableMuleSoapHeaders="true" clientClass="pl.execon.integration.axpppk.ws.client.XISGateway"
port="XISGatewaySoap" />
<http:outbound-endpoint address="http://localhost:8889/Service/XISGateway.asmx" />
<object-to-string-transformer doc:name="Object to String" />
</flow>
I want to use PostRequest ... Any advices ? Tutorials that can help ? Problem is that I need to make this envelope modification:
<soap:Body>
<m:PostRequest>
<m:_requestCode>Test</m:_requestCode>
<m:GetGasCustTable>
<m:XMLDocumentTime>2014-07-21T12:24:50</m:XMLDocumentTime>
<m:CustAccount>00043280</m:CustAccount>
</m:GetGasCustTable>
</m:PostRequest>
</soap:Body>
And I Simply don't know how
If want to use post and map a webservice just use pattern this is a working code for post method:
<pattern:web-service-proxy name="webserviseName">
<inbound-endpoint address="http://localhost:8081/localUWant" exchange-pattern="request-response"/>
<outbound-endpoint address="http://localhost:8889/Service/XISGateway.asmx" exchange-pattern="request-response"/>
</pattern:web-service-proxy>
As simple as that.
this is the documentation: http://www.mulesoft.org/documentation/display/current/Using+Mule+Configuration+Patterns

JAXB marshall class with only one attribute without intermediate element

I have the following class:
class A {
Map<String, String> mapping;
public A() {...}
private Map<String, String> getMapping() {...};
private void setMapping(Map<String, String> mapping) { ... };
}
I need to be able to serialize/deserialize this class in XML with the following representation:
<a>
<entry key="foo" value="bar"/>
<entry key="xbaz" value="xklux"/>
</a>
We use jaxb-intros to configure JAXB for these classes, and I have the following configuration:
<Class name="A">
<XmlRootElement name="a"/>
<Method name="getMapping">
<XmlElement name="mapping"/>
<XmlJavaTypeAdapter value="MappingAdapter"/>
</XmlMethod>
</Class>
Which works but produces:
<a>
<mapping>
<entry key="test" value="a"/>
<entry key="mdx.foo" value="bar"/>
</mapping>
</a>
My question is: how do I get rid of this awful mapping element?
I tried removing the XmlElement element in my JAXB configuration but then I end up with
<a/>
JAXB is not even calling the adapter code.
My second attemps is with another adapter, AAdapter (supposed to handle directly the A object), that I suppose would be configurable this way:
<Class name="A">
<XmlRootElement name="a"/>
<XmlJavaTypeAdapter value="AAdapter"/>
</Class>
But then its marshal() method is not called, and I have no error message from JAXB (which might be due to our JAXB configuration which is another story). And I get the following output:
<a/>
The AAdapter should directly produce the entry elements if it was called.
I saw multiple related posts on how to remove intermediate markup for sub attributes but they seem to be different to my problem since here I want to remove the element for a direct attribute.
So how can I call an adapter for an attribute without putting its result in an element? Or how do I call an adapter directly on the class to serialize?
Thanks in advance for your answers.
Edit: based on this JAXB ticket this seem impossible by design, but if anyone has a workaround it would be great.

Categories