简体   繁体   中英

Mule ESB Java Component 3.8 Doc

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?

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:

  1. Set the Payload instead of the Invocation Property (replace or add it to existing code): eventContext.getMessage().setPayload("Hello World!");
  2. Returns the Invocation Property instead of the Payload : return eventContext.getMessage().getInvocationProperty("myProperty");

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM