本文介绍了Mule Studio-将设置变量传递给Java Transformer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ule子流,其中一部分需要传递两个有效载荷"对象-一个有效载荷是客户",另一个有效载荷是商店".

I've got a flow in mule, and part of it requires two "payload" objects to be passed - one payload is Customer, and the other is Store.

该流的当前有效负载已设置为Store,并且可以正确地传递到我的Java转换器类中.

The current payload of the flow is set to the Store, and that works correctly being passed into my Java transformer class.

我已经使用Variable(将变量名设置为Customer)来保存客户有效负载,并且正在使用Java Transformer的property字段来尝试将其传递.

I've used Variable (set variable name to Customer) to save my customer payload and am using the property field of my Java Transformer to try and pass that through.

当前,它以字符串形式传递给我的Java类-而不是它应该引用的变量.

Currently it is passing it through to my Java class as a string - rather than the variable it's supposed to be referencing.

我在变压器中填写了属性字段,如下所示:名称:客户值:#[变量:客户]参考:

I've filled out the property field in the transformer as: Name: Customer Value: #[variable:Customer] Reference:

任何帮助将不胜感激.我正在使用Mule Studio 3.4版

Any help would be much appreciated. I am using Mule Studio version 3.4

下面的代码摘录

M子xml

<flow name="query_dos_getStoreStatus" doc:name="query_dos_getStoreStatus">
    <choice doc:name="Choice">
        <when expression="#[payload.getCustomer()!=null]">
            <set-variable variableName="Customer" value="#[payload]" doc:name="Save Customer"/>
            <custom-transformer class="ServiceDetailsResponseToStores" doc:name="ServiceDetailsResponseStores"/>
            <custom-transformer class="UpdateIdentifyCustomerResponseForStoreStatus" doc:name="Update Customer for Store status">
                <spring:property name="Customer" ref="#[variable:Customer]"/>
            </custom-transformer>
            <remove-variable variableName="GetCustomerDetailsResponse" doc:name="Remove Customer variable"/>
        </when>
    </choice>
</flow>

Java类

import org.mule.transformer.AbstractTransformer;
import org.mule.transformer.types.DataTypeFactory;

public class UpdateIdentifyCustomerResponseForStoreStatus extends
  AbstractTransformer{

  public UpdateIdentifyCustomerResponseForStoreStatus()
  {
        super();

        this.registerSourceType(DataTypeFactory.create(Store.class));
        this.setReturnDataType(DataTypeFactory.create(IdentifyCustomerResponseEnvelope.class));
  }

  protected Object _customer;
  public Object getCustomer()
  {
        return this._customer;
  }
  public void setCustomer(Object _customer)
  {
        this._customer = _customer;
  }

  public Object doTransform(Object payload, String outputEncoding)
  {
        if(payload instanceof Store && _customer instanceof IdentifyCustomerResponseEnvelope)
        {
              Store store = (Store)payload;
              IdentifyCustomerResponseEnvelope customer = (IdentifyCustomerResponseEnvelope)_customer;

              //changes to customer

              return customer;
        }

        return this._customer;
  }
}

推荐答案

我个人认为,当您使用变形金刚时,应该转换有效载荷,而无需额外的数据.尝试使用接收两个参数的方法创建POJO.然后您可以使用invoke进行调用

Personally I think that when you use a Transformer you should transform your Payload with no need of extra data. Try creating a POJO with a method that receives two arguments. Then you can use invoke to call it

<invoke object-ref="yourBean" method="yourMethod" methodArguments="#[payload],#[flowVars['Customer']]"/>

这篇关于Mule Studio-将设置变量传递给Java Transformer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:29