mule 调用 java 组件作为数组参数

mule invoke java component as array parameter

属性文件:

#torun='GSD11','GSD12' torun='GSD11'

  <flow name="deleteInvoiceFlow" doc:name="deleteInvoiceFlow">
            <http:inbound-endpoint exchange-pattern="request-response" host="${hostname}" port="${port}" path="deleteInvoice" doc:name="HTTP"/>
            <invoke object-ref="client" method="deleteInvoice" methodArguments="${torun}" methodArgumentTypes="java.lang.String" />
     </flow>

  <spring:bean id="client" name="client" class="com.util.DeleteTable"/>  

Java:删除表:

public String deleteInvoice(@Payload String deleteCompany) throws SQLException{

它适用于属性文件中如上所示的属性中的单个参数。但如果我 运行 向以下公司申请

`torun='GSD11','GSD12'

它给出的错误信息为

1 (java.lang.ArrayIndexOutOfBoundsException). Message payload is of type: String

如何启用以数组形式接收参数?

Mule 消息的有效载荷是一个对象。从而允许它处理任何类型的对象。

如果您检查 MuleMessage 界面,您就会看到它。

在您上面的代码中,您将来自入站端点 (http) 的任何内容发送到您的 spring bean,并且您假设它将是一个字符串。

现在,根据您收到的请求类型 (get/post/put/etc),有效负载肯定会在 http 入站端点中发生变化,因此请小心处理。

回到你的问题,如果你确定有效载荷将是一个数组,你可以将你的方法的公司改为那个。如果不是,我会建议您将其更改为反对并验证即将发生的事情并相应地投射。

HTH

Mule 文档说: http://www.mulesoft.org/documentation/display/current/Invoke+Component+Reference

methodArguments="#[1], #[2]"

methodArgumentTypes="java.lang.Float, java.lang.Float"

但我的列表是随机的,它会增长到 100 到 1000,我不想放入 1000 的参数类型。 作为变通解决方案,我在 java 组件中加载 mule-app.propertes 并读取 属性 内容。

public String deleteInvoice(){
      Properties prop = new Properties();
      InputStream input = DeleteTable.class.getClassLoader().getResourceAsStream("mule-app.properties");
      prop.load(input);
      return prop.getProperty("torun");
}