java - 在 Mule 应用程序中使用参数

标签 java spring properties mule

我为 Mule 流程编写了一个自定义 Java 组件。我关注了these instructions并实现了 Callable 接口(interface)。另外,我需要通过属性配置我的 mule 应用程序,因此我遵循了 here 中描述的方法。 .

我的问题是我无法从组件的 Java 代码中检索属性值,即从 onCall() 方法中检索属性值。我需要的是一种简单的方法,通过配置将一些参数传递给我的自定义 Mule 组件。

最佳答案

在以下示例中,属性名称在 abc.properties 中配置。在流程中它被设置为流程变量并在java组件中访问。

这是流程

<context:property-placeholder location="abc.properties"/>

<flow name="EchoFlow" doc:name="EchoFlow">
    <http:inbound-endpoint exchange-pattern="request-response"
        host="localhost" port="8084" doc:name="HTTP"
        doc:description="Process HTTP requests or responses." />
    <set-variable value="${name.from.config}" variableName="name"
        doc:name="Variable" />
    <component class="TestComponent" doc:name="Java"/>
    <logger doc:name="Logger" level="INFO" message="#[name]" />
</flow>

这是组件

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import org.mule.api.transport.PropertyScope;

public class TestComponent implements Callable {

    @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
        // This is how you access a property
        String httpMethod = eventContext.getMessage().getProperty("http.method", PropertyScope.INBOUND);
        System.out.println("The value of property name is >>>" + httpMethod);

        // This is how you access flow variable
        String name = eventContext.getMessage().getInvocationProperty("name");
        System.out.println("The value of property name is >>>" + name);
        return name + " > " + httpMethod;
    }

}

关于java - 在 Mule 应用程序中使用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21386783/

相关文章:

java - 尝试使用java包时出现命令行错误

java - Spring Security OpenID - UserDetailsS​​ervice,AuthenticationUserDetailsS​​ervice

spring - 用spring在tomcat上集群

java - 在 Spring Boot Controller 中反序列化枚举忽略大小写

C# - 属性说明

java - 为什么 Maven 失败并出现 SurefireExecutionException : > Cannot set option parallel with value

java - 在 Google Web Toolkit 中使用 jquery 插件?

java - Spring 批处理 :How it works in distributed environemnt

arrays - 按对象 INT 快速过滤对象数组!属性(property)

bash - 如何使用模板使用 bash 创建 .ini 文件