如何将Java HashMap传递给自定义Mule连接器?

时间:2014-03-11 02:37:33

标签: java mule connector devkit

现在连接器代码如下所示:

// myConnector class
/**
 * Process item
 *
 * {@sample.xml ../../../doc/my-connector.xml.sample myConnector:process}
 *
 * @param binary
 *          the item to process
 * @param stuff
 *          key value pairs for processing
 *
 * @return the status as a string
 *
 * @throws NullPointerException
 *          when one of the parameters are null
 */
@Processor
public String process (  @Payload final byte[] binary,
                        final HashMap<String,String> stuff)
        throws NullPointerException {...}


// myConnector.sample
<!-- BEGIN_INCLUDE(myConnector:process) -->
    <myConnector:process>
            <myConnector:stuff>
                <item1>data1</item1>
                <item2>data2</item2>
            </myConnector:stuff>
    </myConnector:process>
<!-- END_INCLUDE(myConnector:process) —>

我有一个HashMap存储在我的Mule流程中的会话头中(#[header:session:myHashMap]),但我无法弄清楚如何将它发送到连接器。

---更新---

如果我更改连接器示例和连接器元素以匹配我在构建连接器时出错。

// myConnector.sample
<!-- BEGIN_INCLUDE(myConnector:process) -->
    <myConnector:process stuff="#[stuff]"/>
<!-- END_INCLUDE(myConnector:process) —>

// my mule flow
<flow>
    <myConnector:process stuff="#[sessionVars.myHashMap]"/>
</flow>

// the error
[ERROR] Error validating example: cvc-complex-type.3.2.2: Attribute 'stuff' is not allowed to appear in element 'myConnector:process'. Failing example: <myConnector:process stuff="#[stuff]"/>
[ERROR] error on execute: An error ocurred while the DevKit was generating Java code. Check the logs for further details.

1 个答案:

答案 0 :(得分:2)

怎么样:

<myConnector:process>
  <myConnector:stuff ref="#[sessionVars['myHashMap']]" />
</myConnector:process>