簡體   English   中英

從Mule esb向主程序傳遞參數

[英]passing arguments to main program from mule esb

我有一個簡單的java程序,可以執行main方法。 執行時,我需要傳遞一些參數,如下所示:

class Main{
    public static void main(String[] args) {
        initializeBaseClass();
}

以下列方式運行以上程序:

java -classpath C;/test/sample.jar -mainClass com.test.SampleTest

它執行並成功運行。

現在我需要從Mule esb運行相同的命令。 這是調用此代碼並從mule esb執行的最佳方法。

我嘗試添加Java組件並添加屬性鍵/值,但它不起作用。 如何從pass子傳遞參數? 通過使用Spring或腳本語言或MEL,還有更好的方法嗎?

    <spring:beans>
        <spring:bean id="transmission" class="com.test.InvokeMain"/>
    </spring:beans>
    <flow name="test" ...
       <set-payload value="-mainclass com.test.Abcd -driver org.hsqldb.jdbc.JDBCDriver/>
       <invoke object-ref="transmission" method="invoke" methodArgumentTypes="java.lang.String" methodArguments="#[payload]" name="transmissionAPI"/>
    </flow>

主要類別是:

import com.test.Main;
public class InvokeTransmission {

    public void invoke(String params){
        String[] res = params.split("\\s+");
        Main.main(res);
    }
}

為什么不使用Mule stdio IN組件在Mule Studio中進行輸入...例如:-在Mule flow中:-

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio" xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="EE-3.4.2" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/current/mule-stdio.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <stdio:connector name="stdio" messageDelayTime="1000" promptMessage="Enter a parameter :" doc:name="STDIO" validateConnections="true"></stdio:connector>


    <flow name="InputFlow" doc:name="InputFlow"> 
        <stdio:inbound-endpoint system="IN" responseTimeout="10000" connector-ref="stdio" doc:name="STDIO"></stdio:inbound-endpoint>  
       <custom-transformer class="InputProccesser" doc:name="Java"/> 
       <logger message="Payload is :- #[message.payload]" level="INFO" doc:name="Logger"/>  

    </flow>

</mule>

現在我們在流程中使用了<custom-transformer class="InputProccesser" doc:name="Java"/> ,其中InputProccesser是將處理輸入消息的Java類。

現在,您創建一個名為InputProccesser的Java類:

import java.util.List;
import java.util.Map;

import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;

public class InputProccesser extends AbstractMessageTransformer {

   @Override
   public Object transformMessage(MuleMessage message, String outputEncoding)
               throws TransformerException {

       String mes=(String) message.getPayload();
       int input=0;  
       try
       {       
        input =  Integer.parseInt(mes);

      System.out.println(" Your input variable is "+input);

       return input;
       }

       catch(NumberFormatException nFE) 
          { 

           System.out.println("Please enter a number");
     return input;
         }


   }

}

現在,您可以根據需要修改java類以處理輸入消息,並且可以在運行mule應用程序后使用Mule stdio組件進行輸入

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM