Configuring a Mule ObjectToInputStream transformer - mule

The Mule 'Using Transformers' documentation lists many out-of-the-box transformers, among them ObjectToInputStream and ObjectToString:
http://www.mulesoft.org/documentation/display/current/Using+Transformers
For ObjectToString, it can be configured for example like this:
<object-to-string-transformer name="object-to-string" />
but the corresponding does not work for ObjectToInputStream :
<object-to-input-stream-transformer name="object-to-input-stream" />
How can the ObjectToInputStream-transformer be configured, and what is it's default 'name'?
Thanks in advance!

Mule hasn't provided the config tag for this transformer.
But the transformer is already available in the mule basic transformers.
Try it this way.
<custom-transformer class="org.mule.transformer.simple.ObjectToInputStream"></custom-transformer>
Hope this helps.

Related

Calling a flow using Groovy Script in Mule 4

I need to make a call to a flow using groovy script in mule 4. Can someone let me know if they have tried it using Mule 4
It is possible, but I would HIGHLY recommend that you do NOT do it.
You will have to dig deep down into the Mule Java APIs and couple yourself to them and also add a lot of your own error handling etc. and be wary of platform updates and the if the Java API changes.
Personally I would restructure you app to only have 'business logic' in scripts and let Mule do the flow lookups elsewhere.
You can even lookup flows in dataweave.
But here is a rough working example(Note you will have to harden this code yourself):
<flow name="test-flow">
<scheduler>
<scheduling-strategy>
<fixed-frequency frequency="100000"></fixed-frequency>
</scheduling-strategy>
</scheduler>
<set-payload value="bla bla" />
<scripting:execute engine="groovy" doc:name="Toggle flow" doc:id="2eb6f071-bdef-4d3d-926d-2565fcd62d33">
<scripting:code>
import org.mule.runtime.api.message.Message;
import org.mule.runtime.core.api.event.CoreEvent;
import org.mule.runtime.core.api.event.EventContextFactory;
flow=registry.lookupByName("another-flow").get();
thisflow=registry.lookupByName("test-flow").get();
msg = Message.builder().value(payload).build();
event =CoreEvent.builder(EventContextFactory.create(thisflow,
org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.fromSingleComponent("add-location"))).message(msg).build();
result =flow.process(event);
</scripting:code>
</scripting:execute>
</flow>
<flow name="another-flow">
<logger level="ERROR" message="Another Flow #[payload]" />
</flow>
You need to fetch the current flow and the flow you want to call.
Using the Mule APIs - construct a Mule Event, Messgae, payload etc. You will also need to add any attributes you need etc.
Is there any way to call mule "static flow" like When I use the above groovy script and it will call the flow ( its starting the called flow and get the values) and get the values.
Requirement :
Like, Mule Flow A is running independently.
Mule flow B wants to access the Flow A variable with out starting the flow A using groovy or python Script.
Note: Can do with flow reference and lookup but would like to implement using script.

Java Component in Mule does not use project's UTF-8 encoding

I have a java component in Mule that is returning a String. When I print that string from within the java component, it reads as UTF-8 just fine in the console. However, when I return this as the payload, the subsequent logger and all downstream components can no longer read the UTF-8 characters. I've confirmed that my project's encoding setting is set to 'UTF-8'. I've also:
Setting MULE_ENCODING=UTF-8 before and after the Java component, both as an outbound property and invocation property.
Setting the encoding on the message in a mule expression, but that failed message.setEncoding('UTF-8') with an error stating it could not find the method setEncoding()
Using the following in the java component:
eventContext.getMessage().setPayload(myString);
eventContext.getMessage().setEncoding("UTF-8");
return eventContext.getMessage().getPayload();
Switching to a java transformer instead of a component, using the below config on the transformer, explicitly setting encoding to "UTF-8".
<custom-transformer encoding="UTF-8"
class="myDomain.myJavaTransformer" doc:name="Java"/>
I'm not sure what else to try to ensure the payload coming out of the java component/transformer is not interpreted or converted to another encoding...
The output should read: “Outstanding New Environmental Scientist”
The logger currently outputs is “Outstanding New Environmental Scientistâ€. I've corrected this in other parts of the flow by adding encoding=UTF-8 to any VM endpoints, for example. I've also confirmed that this can print correctly in a logger elsewhere in the flow.
There seems to be something happening after the String is returned from within the java class referenced by the java component and the subsequent mule logger...
try <object-to-string-transformer encoding="..." /> right after your java component
I had a problem with encoding too. It was not completely similar to your case but I took this action and it worked for me. (Byte to array using java serialization)
<set-property propertyName="MULE_ENCODING" value="UTF-8" doc:name="Property" />
<byte-array-to-string-transformer encoding="UTF-8" doc:name="Byte Array to String"/>
I used that when message is coming to my flow.
Also there is properties in wrapper and you can set that as well.
How are you reading the RSS feed? If it is using an endpoint, try setting the 'encoding' attribute for that endpoint?

Is there a way to mock non-global filters in a sub-flow using MUnit?

I wanted to know if there was a way to mock a custom-filter that is within a sub-flow using MUnit.
I'm using Mule 3.4.0 and MUnit 3.4.0.M5.
The sample flow looks like the following.
<sub-flow name="a">
<choice>
<when expression="something...">
<custom-filter doc:name="filter a">...</custom-filter>
</when>
<otherwise>
...
</otherwise>
</choice>
</sub-flow>
I've had to create a wrapper flow around the subflow because I get a NullPointerException whenever I try to hit the sub flow directly using the runFlow syntax. However, in doing so, I am unable to mock the custom-filter using the whenMessageProcessor syntax. Please see my attempt below.
whenMessageProcessor("custom-filter"
.withAttributes(attribute("name").ofNamespace("doc").withValue("filter a"))
.thenReturn(muleMessageWithPayload("some response");
This results in the message not being mocked.
There are to issues here mixed up.
You having to wrap you sub-flow is a MUnit/Mule issue as commented here:
How to mock a Java component within Mule Flow using MUnit
The second issue is filter mocking. Short answer is you can not, please check:
https://github.com/mulesoft/munit/issues/108
Conceptually a filter is a shorthanded way of doing a choice (or an if in a normal language). One usually does not mock a choice/if it rather changes a value in a variable or in our case in the mule message payload. That's why the filter MP can not be mocked.
HTH

How can sync two jira instances using either Mule or Mule Studio?

I want to sync two jira instances using using either Mule ESB or Mule Studio (custom connector). Here Mule will act as middleware for two jira instances. If some activity is performed in JIRA-1 ex., issue is created it should be replicated in JIRA-2.
Is this possible using Mule ESB or Mule Studio ?
I am not getting starting point for this. Currently I am looking for Mule Orchestration for this.
Can someone guide me in right direction ?
<jira:config name="Jira_A" doc:name="Jira_for_A" >
</jira:config>
<jira:config name="Jira_B" doc:name="Jira_for_B">
</jira:config>
<flow name="consuming-from-jiraA" doc:name="consuming-from-jiraA">
<poll doc:name="Poll" frequency="1000">
<jira:get-issues-from-jql-search connectionAddress="http://localhost:8080/rpc/soap/jirasoapservice-v2"
connectionPassword="admin" connectionUser="admin"
config-ref="Jira_A" jqlSearch="project = "MULE ESB" AND key = ME-1"
maxNumResults="100" doc:name="Jira_for_A" />
</poll>
<foreach doc:name="For Each">
<jira:create-issue config-ref="Jira_B" doc:name="Jira_for_B"
project="WT" summary="Mule ESB :Jira sync test issue 1 " type="2" connectionAddress="http://192.xxx.x.xx:8091/rpc/soap/jirasoapservice-v2" connectionPassword="admin" connectionUser="admin">
</jira:create-issue>
</foreach>
</flow>
Have you tried the jira-connector with the JQL query syntax?
I have not tried before, but I assume you could use the jira connector within a poll, and query one of your jiras instances to retrieve information you want (ticket) and then hit the other jira instance to reflect it if it doesn't exists.
Try if it works.

How can i setpayload on xml config?

i want to set some message to payload.
i always used filter to set some data to payload.
i think they are some ways to setpayload whith out using filter.
could somebody help me how to setpayload on the mule-config.xml file ?
i tried
<set-payload value="something"/>
but doesn't works .. i am using mule 3.2
thanks!
The set-payload transformer is available starting with Mule 3.3.
For 3.2, the shortest is expression-transformer:
http://www.mulesoft.org/documentation-3.2/display/32X/Expression+Transformer+Reference