1
votes

I am new to mule and Java and trying to write a generic flow which will transform the payload with the value of the flow variable which I set it at the component level. Below the snippet of my flow. How can I use my expression transformer to be generic. That is it should execute the value stored the flow variable and manipulate the payload.

<flow name="process_incoming__eflow_messagesFlow1" doc:name="process_incoming__eflow_messagesFlow1">
    <vm:inbound-endpoint exchange-pattern="request-response" path="TransformToBod" doc:name="Transfor to BOD VM"/>
    <logger message="message received from BOD VM #[payload]" level="INFO" doc:name="Logger"/>
    <component class="com.efi.radius.components.GetMessageType" doc:name="Java - Get the type of BOD comming into Payload"/>
    <logger message="The BOD class to trasform is #[flowVars.messageType]" level="INFO" doc:name="Logger"/>
    <custom-transformer class="com.efi.radius.transformers.XMLToBODTransformer" doc:name="Java - XML to BOD Transformer">
    </custom-transformer>
    <logger message="The Data Area to map is #[flowVars.messageBODType]" level="INFO" doc:name="Logger"/>
    <logger message="The payload now is #[payload]" level="INFO" doc:name="Logger"/>
    <expression-transformer expression="#[flowVars['messageBODType']]" doc:name="Expression - Extract the Data Area"/>
</flow>

Snippet of GetMessageType.Java where I set the flow variable

    if (payload.indexOf("<ProcessCustomerPartyMaster") != -1) {
        // Set the message type to customer
        eventContext.getMessage().setInvocationProperty("messageType", "com.efi.radius.models.bod.ProcessCustomerPartyMasterType");
        eventContext.getMessage().setInvocationProperty("messageBODType", "#[message.payload.getDataArea().getCustomerPartyMaster().get(0)]");
    }

I have also written a custom transformer where I receive the value of the "messageType" correctly and transform as follows.

Snippet of XMLToBODTransformer.java bodClassName = message.getInvocationProperty("messageType");

This works fine.

If I directly write #message.payload.getDataArea().getCustomerPartyMaster().get(0)]" in the expression transformer it is working as expected but I want to make it generic. Is there any way to do it?

Adding the error log .

The value of #[flowVars.messageBODType] is "#[message.payload.getDataArea().getCustomerPartyMaster().get(0)]" which I am setting in GetMessageType.Java as shown above

Please find the snippet of the console after running. INFO [[iQuoteIntegration].process_iquote_job.stage1.02] (DispatchingLogger.java:197) - The BOD class to trasform is com.efi.radius.models.bod.ProcessCustomerPartyMasterType com.efi.radius.models.bod.ProcessCustomerPartyMasterType INFO [[iQuoteIntegration].process_iquote_job.stage1.02] (DispatchingLogger.java:197) - The Data Area to map is #[message.payload.getDataArea().getCustomerPartyMaster().get(0)] INFO [[iQuoteIntegration].process_iquote_job.stage1.02] (DispatchingLogger.java:197) - The payload now is com.efi.radius.models.bod.ProcessCustomerPartyMasterType@3dcc579c INFO [[iQuoteIntegration].process_iquote_job.stage1.02] (DispatchingLogger.java:197) - The payload after BOD object transformation is #[message.payload.getDataArea().getCustomerPartyMaster().get(0)] INFO [[iQuoteIntegration].process_iquote_job.stage1.02] (DispatchingLogger.java:197) - Initialising: 'connector.VM.mule.default.dispatcher.1280679149'. Object is: VMMessageDispatcher INFO [[iQuoteIntegration].process_iquote_job.stage1.02] (DispatchingLogger.java:197) - Starting: 'connector.VM.mule.default.dispatcher.1280679149'. Object is: VMMessageDispatcher ERROR [[iQuoteIntegration].process_iquote_job.stage1.02] (DispatchingLogger.java:341) -

Message : Failed to find entry point for component, the following resolvers tried but failed: [ ReflectionEntryPointResolver: Found too many possible methods on object "com.efi.radius.transformers.EFlowJobToRadiusJob" that accept parameters "{class java.lang.String}", Methods matched are "[public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String), public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException]" AnnotatedEntryPointResolver: Component: EFlowJobToRadiusJob{this=b72e07f, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='/'}, sourceTypes=[]} doesn't have any annotated methods, skipping. CallableEntryPointResolver: Object "EFlowJobToRadiusJob{this=b72e07f, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='/'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable" MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event ]

Code : MULE_ERROR-321

Exception stack is: 1. Failed to find entry point for component, the following resolvers tried but failed: [ ReflectionEntryPointResolver: Found too many possible methods on object "com.efi.radius.transformers.EFlowJobToRadiusJob" that accept parameters "{class java.lang.String}", Methods matched are "[public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String), public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException]" AnnotatedEntryPointResolver: Component: EFlowJobToRadiusJob{this=b72e07f, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='/'}, sourceTypes=[]} doesn't have any annotated methods, skipping. CallableEntryPointResolver: Object "EFlowJobToRadiusJob{this=b72e07f, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='/'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable" MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event ] (org.mule.model.resolvers.EntryPointNotFoundException)

org.mule.model.resolvers.DefaultEntryPointResolverSet:52 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/model/resolvers/EntryPointNotFoundException.html)

Root Exception stack trace: org.mule.model.resolvers.EntryPointNotFoundException: Failed to find entry point for component, the following resolvers tried but failed: [ ReflectionEntryPointResolver: Found too many possible methods on object "com.efi.radius.transformers.EFlowJobToRadiusJob" that accept parameters "{class java.lang.String}", Methods matched are "[public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String), public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException]" AnnotatedEntryPointResolver: Component: EFlowJobToRadiusJob{this=b72e07f, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='/'}, sourceTypes=[]} doesn't have any annotated methods, skipping. CallableEntryPointResolver: Object "EFlowJobToRadiusJob{this=b72e07f, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='/'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable" MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event ]

1
First of all what is the exception you are getting ?? what is the value of #[flowVars.messageBODType] are you getting in logger ?? put a logger after expression transformer with #[message.payload] and tell me what's the value are you getting ?Anirban Sen Chowdhary
The value of #[flowVars.messageBODType] is "#[message.payload.getDataArea().getCustomerPartyMaster().get(0)]" which I am setting in GetMessageType.Java as shown above.Indranil
@AnirbanSenChowdhary I have added the error log with information you requested. Thank You. Could you please review and respond.Indranil
Yes .. just use eventContext.getMessage().setInvocationProperty("messageBODType", message.payload.getDataArea().getCustomerPartyMaster().get(0)); and don't put the value in #[] .. it will workAnirban Sen Chowdhary
Please... That stacktrace there needs reformatting and a serious trimming to relevant parts.Vogel612

1 Answers

0
votes

What you want to achieve it can be done, at least not in that way. You see, if what you are doing worked nothing would stop someone to send, lets say a MEL expression as payload in an http request and have it execute in your code which will be like MEL injection, if you will.

I would suggest that you narrow down what you want make generic, or store such expression in file and use another value of you message to select which file to have execute.

HTH