How update camel property value? - properties

I have a property in my route.I want to change value of this property in choice/when. How can I do this in my route?
<route>
<setProperty propertyName="UpdateORInsert">
<constant>INSERT</constant>
</setProperty>
<choice>
<when>
------Change value of UpdateORInsert-------
</when>
</choice>
</route>

It can be done using simple component in your route inside `when`:
<route>
<setProperty propertyName="UpdateORInsert">
<constant>INSERT</constant>
</setProperty>
<choice>
<when>
<simple>${Yourspecificcondition}</simple>
<setProperty propertyName="UpdateORInsert">
<constant>UPDATE</constant>
</setProperty>
</when>
</choice>
</route>

Related

Unable to post a file to http endpoint inside a choice in mule

Here's the my mule app xml config
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:test="http://www.mulesoft.org/schema/mule/test"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/3.6/mule-test.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.6/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.6/mule-vm.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.6/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.6/mule-file.xsd">
<object-to-string-transformer name="httptoobj" />
<file:connector name="input"/>
<http:http-response-to-object-transformer
name="httptostring" />
<configuration>
<expression-language autoResolveVariables="false">
<import class="com.xyz.alertcampaign.appworkflow.CampaignStatus" />
</expression-language>
</configuration>
<flow name="polling" doc:name="polling" processingStrategy="synchronous">
<quartz:inbound-endpoint repeatInterval="3000"
startDelay="3000" jobName="couchbasePoller" doc:name="Quartz">
<quartz:event-generator-job stateful="true" />
</quartz:inbound-endpoint>
<component doc:name="Java">
<singleton-object
class="com.xyz.alertcampaign.appworkflow.CouchbasePoller" />
</component>
<vm:outbound-endpoint exchange-pattern="one-way"
path="oozieQueue" doc:name="Trigger workflow" />
</flow>
<flow name="oozie-workflow-manager" doc:name="oozie-workflow-manager">
<vm:inbound-endpoint exchange-pattern="one-way"
path="oozieQueue" doc:name="VM" />
<foreach collection="#[payload.items()]" counterVariableName="counter">
<choice doc:name="Choice">
<when expression="#[payload.status == CampaignStatus.NOT_STARTED]">
<file:inbound-endpoint address="file://#[payload.fileName]" connector-ref="input"/>
<http:outbound-endpoint exchange-pattern="request-response"
address="http://localhost:8080/oozie/v1/jobs"
responseTransformer-refs="httptoobj" method="POST" doc:name="HTTP"
contentType="application/xml;charset=UTF-8" />
<choice doc:name="Choice">
<when expression="#[message.inboundProperties['http.status'] == 201]">
<component doc:name="Java">
<singleton-object
class="com.xyz.alertcampaign.appworkflow.JobUpdater" />
</component>
</when>
<otherwise>
<logger level="ERROR" message="Error occurred on creating Job in OOzie " />
</otherwise>
</choice>
</when>
<when
expression="#[payload.status == CampaignStatus.UPDATED || payload.status == CampaignStatus.EXPIRED]">
<logger level="ERROR" message="#[payload.status]" />
<http:outbound-endpoint exchange-pattern="request-response"
method="PUT"
address="http://localhost:8080/oozie/v1/job/#[payload.jobId]?action=kill"
responseTransformer-refs="httptoobj" doc:name="HTTP" />
<choice doc:name="Choice">
<when expression="#[message.inboundProperties['http.status'] == 200]">
<component doc:name="Java">
<singleton-object
class="com.xyz.alertcampaign.appworkflow.JobUpdater" />
</component>
</when>
<otherwise>
<logger level="ERROR" message="Error occurred on killing Job in OOzie " />
</otherwise>
</choice>
</when>
</choice>
</foreach>
</flow>
</mule>
Getting following exception (stack):
Exception when loading mule' xml:
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'file:inbound-endpoint'. One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}' is expected.
Why am I not allowed to post a file to http inside choice router?
You can only use a file:inbound-endpoint at the beginning of a flow. If you're trying to retrieve a file mid-flow, then consider using the Mule Requestor module. This allows you to request a resource (i.e. a file) at any point in a flow.
The problem is that it's an inbound endpoint so you are adding a message source in the middle of a flow. What you should do is define another flow that starts with that file inbound endpoint (with all that logic) and use a flow reference element in the choice to it.
For more details check out the doc.
Additionaly I think there is another problem where the inbound endpoint does not allow dynamic inputs. I solved it via MuleRequester

NullPayload vs null check

According to the following ticket: https://www.mulesoft.org/jira/browse/MULE-6427 For NullPayload I should be able to use :
<when expression="#[payload == null]">
but that doesn't work. It fails. I am using Mule 3.5.1
Here is an example flow:
<flow name="testNull">
<poll frequency="10000">
<logger />
</poll>
<set-payload value="#[org.mule.transport.NullPayload.getInstance()]" />
<choice>
<when expression="#[payload == null]">
<logger level="ERROR" message="NullPayload is same as null" />
</when>
<otherwise>
<logger level="ERROR" message="Doesnt work" />
</otherwise>
</choice>
</flow>
This will always print 'Doesn't work'. However message.payload == null works. Whats the difference between "payload" and "message.payload"?
There seems to be an issue with the #[payload] alias. Use the real thing and it will work: #[message.payload].

Compound MEL statement has problems

I need to read values from a configuration file and I keep running into issues with an embedded MEL statement; chased multiple dead ends and am out of ideas. I distilled it down to a fairly simple example using a session variable.
Thank you,
- Don
The below code fails with:
Message : [Error: Missing left node]
[Near : {... message.payload.contains(#[sessionVars['valueToMatch']]) ....}]
<set-session-variable variableName="valueToMatch" value="Now we are engaged in a great civil war" />
<choice doc:name="Choice">
<when expression="#[message.payload.contains(#[sessionVars['valueToMatch']])]">
<set-session-variable variableName="success" value="true" />
</when>
<otherwise>
<set-session-variable variableName="success" value="false" />
</otherwise>
</choice>
Whereas the following code works:
<choice doc:name="Choice">
<when expression="#[message.payload.contains('Now we are engaged in a great civil war')]">
<set-session-variable variableName="success" value="true" />
</when>
<otherwise>
<set-session-variable variableName="success" value="false" />
</otherwise>
</choice>
My guess is that the problem is that you are putting an expression delimited inside of an expression, try this:
"#[message.payload.contains(sessionVars['valueToMatch'])]"
instead of this
"#[message.payload.contains(#[sessionVars['valueToMatch']])]"
Try this #[message.payload contains valueToMatch] ... It will work perfectly and simple:-
<set-session-variable variableName="valueToMatch" value="Now we are engaged in a great civil war" />
<choice doc:name="Choice">
<when expression="#[message.payload contains valueToMatch]">
<set-session-variable variableName="success" value="true" />
</when>
<otherwise>
<set-session-variable variableName="success" value="false" />
</otherwise>
</choice>

Mule tag namespace unbound

I searched a bit through this site and found this link . My issue is i am calling another flow inside the flow and when i get the response from another flow i just to need check for a message property(i used a filter). However, when i come to set-payload tag i get error that namespace associated with element "set-payload" is not bound.
<flow name = "XXXX">
<set-session-variable variableName="originalMessage" value="#[message.payload]" />
<choice>
<when>
<custom-filter class="xxxx" />
<flow ref="YYYY" />
</when>
<otherwise>
<flow ref="errorHandler" />
</otherwise>
</choice>
<choice>
<when><customer-filter="another filter to check response from the flow YYYY" />
<!-- error occurs below -->
<set-payload value="#[sessionVars['originalMessage']]" doc:name="Set Payload" />
<!-- do stuff -->
</flow>

Why is Mule payload getting lost in <catch-exception-strategy> for java.net.ConnectException

I'm testing my Mule(3.3.1) flow which sends a web service call to external vendor. My aim is to catch java.net.ConnectException and apply appropriate XSLT to original payload and send it to caller.
But the payload received in <catch-exception-strategy> is of type org.apache.commons.httpclient.methods.PostMethod#12b13004 and not original XML. Tried using <objexct-to-string-transformer> but didn't help.
Any suggestions how to retrieve the original payload in catch block?
Part of mule-config.xml is below:
<flow name="orderRequirementsToVendor">
<jms:inbound-endpoint queue="order.vendor" />
<set-property propertyName="SOAPAction" value="http://vendor.com/services/InterfacePoint/Call" />
<cxf:proxy-client payload="body" enableMuleSoapHeaders="false">
<cxf:inInterceptors>
<spring:bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
</cxf:inInterceptors>
<cxf:outInterceptors>
<spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
</cxf:outInterceptors>
</cxf:proxy-client>
<outbound-endpoint address="${vendor.ws.url}" mimeType="text/xml" connector-ref="https.connector" />
<byte-array-to-string-transformer />
<choice-exception-strategy>
<catch-exception-strategy when="#[exception.causedBy(java.net.ConnectException)]">
<logger message="#[exception.causeException]" level="ERROR" />
<object-to-string-transformer/>
<transformer ref="vendorConnectExceptionTransformer" />
</catch-exception-strategy>
<catch-exception-strategy>
<logger message="#[exception.causeException]" level="ERROR" />
<transformer ref="generalErrorTransformer" />
</catch-exception-strategy>
</choice-exception-strategy>
</flow>
Store the original payload in a flow variable right after jms:inbound-endpoint with
<set-variable variableName="originalPayload" value="#[message.payload]" />
Access it back in your exception strategy with a MEL expression like: #[flowVars.originalPayload].