2014-04-07 56 views
0

我有一個簡單的Java程序與主要的方法來執行。在執行我需要傳遞一些參數,如下圖所示:傳遞參數到主程序從騾esb

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

運行上面的程序爲:

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

它執行併成功運行。

現在我需要從騾esb運行相同。 這是調用這個並從mule esb執行的最佳方式。

我已經嘗試添加java組件並添加屬性鍵/值,它不起作用。我如何傳遞來自mule的參數? 使用Spring或腳本語言或MEL有沒有更好的方法?

+0

這看起來像[此問題]的副本(http://stackoverflow.com/questions/14769142/how-to-invoke-a-java-組件在-騾) –

回答

1
<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); 
    } 
} 
0

你爲什麼不使用騾標準輸入輸出IN組件採取騾子工作室輸入...例如: - 在騾子流量: -

<?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> 

現在,我們已經在InputProccesser是java類將處理流程中使用<custom-transformer class="InputProccesser" doc:name="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 stdio組件用於在運行mule應用程序後進行輸入