java - 如何将 Java HashMap 传递到自定义 Mule 连接器?

标签 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) —>

我在 Mule 流中的 session header 中存储了一个 HashMap (#[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.

最佳答案

关于:

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

关于java - 如何将 Java HashMap 传递到自定义 Mule 连接器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22315374/

相关文章:

拆分后的 Mule 消息属性在一个字段中显示拆分消息的所有属性值

web-services - Apache CXF 与 Apache Camel

amazon-s3 - S3 连接器与 Kafka 连接,将数据从本地流式传输到云端

azure - 如何处理在每个 API 调用中使用 header 身份验证的自定义连接器?

java - 检索序列化的 JFrame 以在 MySql 中上传

java - Java 中的父目录

java - 存储和访问 Java 应用程序数据的最佳方法

基于 Header 属性的 Mule 选择节点表达式

java - 更改 Lotus Notes 中的 "from"字段

Tomcat 8.5.51 - secretRequired ="false"的问题