简体   繁体   English

Mule ESB Java组件3.8文档

[英]Mule ESB Java Component 3.8 Doc

I am trying to reply the basic Java Component Example from the Official Documentation: 我试图从官方文档中回复基本的Java组件示例:

https://docs.mulesoft.com/mule-user-guide/v/3.8/java-component-reference https://docs.mulesoft.com/mule-user-guide/v/3.8/java-component-reference

The IDE is v.6.0.1 IDE是v.6.0.1

I realized that the Java class should extend Callable. 我意识到Java类应该扩展Callable。 This is mainly the big difference with previous versions of MULE. 这主要是与以前版本的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! 我的问题是,运行该应用程序并向本地主机创建一个http / get:8081后,我无法识别Hello World! message rendered in the browser. 在浏览器中呈现的消息。

Has something changed in last version? 在上一个版本中有什么变化吗? Should I incluse a setPayload element also? 我也应该包含setPayload元素吗?

Referring the code it sets an Invocation Property or Variable , and returns the existing Payload which can be {NullPayload} because not defined yet. 引用代码后,它会设置一个Invocation属性Variable ,并返回现有的有效载荷 ,该载荷可以是{NullPayload}因为尚未定义。 Try to debug and evaluate the Variables tab inside Mule Debugger , You should find a new variable named: myProperty . 尝试调试和评估Mule Debugger中的“ 变量”选项卡,您应该找到一个名为myProperty的新变量。

In order to get the basic Hello World text then do one of the following option: 为了获得基本的Hello World文本,请执行以下任一操作:

  1. Set the Payload instead of the Invocation Property (replace or add it to existing code): eventContext.getMessage().setPayload("Hello World!"); 设置有效载荷而不是Invocation属性 (将其替换或添加到现有代码中): eventContext.getMessage().setPayload("Hello World!");
  2. Returns the Invocation Property instead of the Payload : return eventContext.getMessage().getInvocationProperty("myProperty"); 返回Invocation属性而不是Payloadreturn eventContext.getMessage().getInvocationProperty("myProperty");

The first thing to check is that you are instantiating the Java class correctly. 首先要检查的是您正确地实例化了Java类。 The UI or visual way of configuring the Java object is not clear to me. 我不知道配置Java对象的UI或可视方式。 I found a very simple example of Spring configuration like so: 我发现了一个非常简单的Spring配置示例,如下所示:

    <spring:bean id="ordersTransform" name="OrdersTransformSingleton" class="org.dlw.transport.OrdersTransformSingleton" scope="singleton" />

And, the Java object component: 并且,Java对象组件:

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. 记住设置有效载荷并返回消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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