invoke custom java class in WSO2 esb - wso2-esb

I need to invoke a custom java class using WSO2 esb. The class takes an input parameter as a string and returns the XmlObject from the method.
How to achieve this using WSO2 and which mediator to use for the same?
regards
Amit Pawar.

You can use custom class mediators to achieve this[1]. Within this mediator you have to call your method and then set the result to the message context as a property and obtain it down the line in the mediation flow.
[1] - https://docs.wso2.org/display/ESB480/Class+Mediator

You can also refer the sample in [1] to have a clear idea
[1] https://docs.wso2.org/display/ESB480/Sample+380:+Writing+your+own+Custom+Mediation+in+Java

Related

how to skip the dynamic arguments when it is empty in payloadFactory wso2 esb as XML

We are using WSO2 ESB, and we are using payloadFactory mediator to transform the message. we have entered into scenario where we need to ignore the payload arguments when it is empty or null. can any one help us achieve this?
You can try using filter mediator wherein you check the arguments in xpath, if arguments exist then you can call payload mediator with all the arguments, else you can call another payload which doesn't contain those arguments.
However according to me the best practice would be to use an xslt mediator where you put all your logic in the xslt, this would make your sequence small in length and more readable.

Accessing Mule Flow's MuleContext in CXF Java class within Flow

I am trying to implement a CXF Server flow as below. I want to synchronously invoke the VM from the Java component (after CXF component). However to synchronously invoke the VM, I need MuleContext (for eg: muleContext.send("vm://some_name", MuleMessage)). I am currently stuck, unable to find a way to access the Mule Flow's MuleContext inside Java component within the Flow.
Any help is highly appreciated..
Mule Flow Structure
Thanks,
Aneesh.
Check out the MuleSoft documentation https://docs.mulesoft.com/mule-user-guide/v/3.8/java-component-reference on writing a Java Component.
If your Java class implements the org.mule.api.lifecycle.Callable interface then you will be able to override the following method,
public Object onCall(MuleEventContext eventContext)
Inside this method you synchronously call the VM like this,
eventContext.sendEvent(message, endpoint)

Synchronous Call in WSO2 ESB in iterator mediator

Is there any way to make synchronous call of all the codes written inside the iterator mediator in esb wso2?
Finally, it is working by doing two things together.
Set sequential="true" in iterator and in call mediator use blocking = "true"
Are you using send mediator? If yes, use call mediator instead, which is synchronous.

Mule parsing Incoming REST request

I have a REST client that is preparing payload in JSON format and invoking a REST service. My job is to create the REST service in Mule. I need some information on how I can map the incoming Payload to a java object so that I can invoke the REST service component class and get the values passed in the JSON object. Does the payload after HTTP inbound endpoint already contain the JSON values sent by the client? In which case a simple JSON to Object mapper would map it as Hashmap?
You will most likely need to create a custom transformer for this use case if you have a special use case.
See: http://www.mulesoft.org/documentation/display/current/Creating+Custom+Transformer+Class
If you get sent JSON you can convert it into a custom class like this:
<json:json-to-object-transformer name="jsonToFruitCollection" returnClass="
org.mule.module.json.transformers.FruitCollection"/>
Alternatively You can also use ObjectMapper and can probably use a bean to map your JSON directly to your Java object in your Java class.
You can also use <json:json-to-object-transformer/> directly after your Http inbound endpoint, parse and get each element value in your Mule flow and store in variables. Then these variables can be passed into your Java class where you can map these to your Java object easily.
Both the approach will work fine

How mule invoke the component?

After go through some guides about Mule, I have a question about the component, as it is said in mule documentation,
A simple POJO (Plain Old Java Object) component that will be invoked
by Mule when a message is received. The class or object instance to be
used can be specified using a child object factory element, or via the
'class' attribute. If the 'class' attribute is used, an object
factory cannot be configured as well. Using the 'class' attribute is
equivilant to using the propotype object factory ('prototype-object'
child element).
in this documentation just said the component will be invoked by Mule when a message is received, but a problem is Mule how to know how many methods the component have, and which method should be invoked? or there must one method in the component and no matter the method name? and also mule how to deal with the parameters the method have?
Alternatively, you can use:
<invoke object-ref="..." method="..." methodArguments="..." />
which is way more convenient than configuring entry point resolvers.
yes, I got the answer, the answer is using mule entry point