简体   繁体   中英

How to invoke Java Mule component with enum value as method parameter?

I am working currently on an API that is exposed by Mule ESB 3.5.0 (non-EE). This API accepts a XML file with accounts to be imported via HTTP and puts this task definition into a RabbitMQ queue. Another Mule flow is responsible for taking items from the queue one-at-a-time (thanks to processingStrategy="synchronous" ) and feeding them to the platform core. The queue is required as the core is able to process one-file-at-a-time.

The setup above is up & running smoothly. What I would like to achieve now, is to enable our customers to troubleshoot the integration by exposing an HTTPS endpoint, where import statuses will be available (identified by some GUID and SHA1 of the request).

I created a simple POJO component that handles the logic of adding the status updates, the method signature being:

void addStatus(final String guid, final String status)

I managed to invoke the method above by defining the bean as

<bean id="importStatusComponent" class="com.example.ImportStatusComponent" />

and invoking the java-component in the Mule flow with:

    <invoke object-ref="importStatusComponent" method="addStatus"
            methodArguments="#[flowVars.guid], Import started"
            methodArgumentTypes="java.lang.String, java.lang.String" />

As we would like to expose this to customers and allow them to implement some programmatic checking of the status, I decided to change the status type to an enum-based dictionary ImportStatusEnum .

Unfortunately, I am unable to fed enum into MEL that goes into <invoke methodArgument=""> tag attribute.

Examples of what I have tried:

1) Arguments as two separate MEL expressions.

<configuration>
    <expression-language>
        <import class="com.example.ImportStatusEnum" />
    </expression-language>
</configuration>

<invoke object-ref="importStatusComponent" method="addStatus"
        methodArguments="#[flowVars.guid], #[ImportStatusEnum.STARTED]"
        methodArgumentTypes="java.lang.String, com.example.ImportStatusEnum" />

2) Arguments as a single MEL expression.

<configuration>
    <expression-language>
        <import class="com.example.ImportStatusEnum" />
    </expression-language>
</configuration>

<invoke object-ref="importStatusComponent" method="addStatus"
        methodArguments="#[flowVars.guid, ImportStatusEnum.STARTED]"
        methodArgumentTypes="java.lang.String, com.example.ImportStatusEnum" />

3) Fully qualified class names instead of imports (not shown here).

How to pass an enum value as method argument to invoke component in Mule? Any help will be highly appreciated :)

这个会奏效

<invoke object-ref="importStatusComponent" method="addStatus" methodArguments="#[flowVars.guid], #[com.example.ImportStatusEnum.STARTED]" methodArgumentTypes="java.lang.String, com.example.ImportStatusEnum" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM