Reputation: 1
I am trying to reply the basic Java Component Example from the Official Documentation:
https://docs.mulesoft.com/mule-user-guide/v/3.8/java-component-reference
The IDE is v.6.0.1
I realized that the Java class should extend Callable. This is mainly the big difference with previous versions of MULE. So in my case
package javacomponent;
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
public class helloWorldComponent implements Callable{
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
eventContext.getMessage().setInvocationProperty("myProperty", "Hello World!");
return eventContext.getMessage().getPayload();
}
}
The problem I have is that after running the app and making a http/get to localhost:8081 I can't se the Hello World! message rendered in the browser.
Has something changed in last version? Should I incluse a setPayload element also?
Upvotes: 0
Views: 266
Reputation: 352
The first thing to check is that you are instantiating the Java class correctly. The UI or visual way of configuring the Java object is not clear to me. I found a very simple example of Spring configuration like so:
<spring:bean id="ordersTransform" name="OrdersTransformSingleton" class="org.dlw.transport.OrdersTransformSingleton" scope="singleton" />
And, the Java object component:
Check this first and be sure that you are instantiating your class at runtime. Then add a breakpoint in the callable method you implemented and just see if the application program pointer is getting you in the method. If so, add your message to the payload.
public Object onCall(MuleEventContext eventContext) throws Exception {
// freshen
this.transportObj = null;
this.transportObj = new ArrayList<OrdersValueObject>();
MuleMessage res = eventContext.getMessage();
List<Map> list = (LinkedList) res.getPayload();
...
res.setPayload(transportObj);
return res;
}
Remember to set the payload and return the message.
Upvotes: 0
Reputation: 1277
Referring the code it sets an Invocation Property or Variable, and returns the existing Payload which can be {NullPayload}
because not defined yet. Try to debug and evaluate the Variables tab inside Mule Debugger, You should find a new variable named: myProperty
.
In order to get the basic Hello World text then do one of the following option:
eventContext.getMessage().setPayload("Hello World!");
return eventContext.getMessage().getInvocationProperty("myProperty");
Upvotes: 2