Mule throttling on a backend service - activemq

I have a back end service that I need to throttle access to. I'm trying to use the approach described here: http://blogs.mulesoft.org/synchronous-and-asynchronous-throttling-2/
I started with a simple pass through flow that receives a SOAP request and forwards it. When I hit this using the SOAPUI utility, I get the expected response in a second or two.
<http:connector name="httpConnector" doc:name="HTTP\HTTPS">
<receiver-threading-profile maxThreadsActive="1" maxBufferSize="100" />
</http:connector>
<jms:activemq-connector name="amqConnector" brokerURL="tcp://localhost:61616" specification="1.1" doc:name="AMQ" />
<flow name="Flow1" processingStrategy="synchronous" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8088" path="test" doc:name="HTTP"
mimeType="text/xml" encoding="UTF-8" connector-ref="httpConnector"/>
<http:outbound-endpoint
address="http://dnbdirect-api.dnb.com/DnBAPI-11"
exchange-pattern="request-response" doc:name="HTTP" mimeType="text/xml"/>
</flow>
If I then move the outbound call to a separate flow and add in the request-reply block, the behavior changes. I get no response back (nor do I get the "After queue" message from the logger) and SOAPUI eventually times out.
<http:connector name="httpConnector" doc:name="HTTP\HTTPS">
<receiver-threading-profile maxThreadsActive="1" maxBufferSize="100" />
</http:connector>
<jms:activemq-connector name="amqConnector" brokerURL="tcp://localhost:61616" specification="1.1" doc:name="AMQ" />
<flow name="Flow1" processingStrategy="synchronous" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8088" path="test" doc:name="HTTP"
mimeType="text/xml" encoding="UTF-8" connector-ref="httpConnector"/>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="AMQ_SCHEDULED_DELAY" value="5000"/>
</message-properties-transformer>
<logger message="Before queue" level="INFO"/>
<request-reply>
<jms:outbound-endpoint queue="request" connector-ref="amqConnector"></jms:outbound-endpoint>
<jms:inbound-endpoint queue="response" connector-ref="amqConnector"></jms:inbound-endpoint>
</request-reply>
<logger message="After queue" level="INFO"/>
</flow>
<flow name="flow2" doc:name="Flow2">
<jms:inbound-endpoint queue="request" connector-ref="amqConnector" doc:name="JMS"/>
<http:outbound-endpoint
address="http://dnbdirect-api.dnb.com/DnBAPI-11"
exchange-pattern="request-response" doc:name="HTTP" mimeType="text/xml" />
</flow>
The throttling behavior works as I see the delays if I pull out the call to the back end service. But I can't get it to work with the service call there.
What am I missing?

I found that the message's payload will be "ArrayList" after "request-reply".
so i add a java component to split it, then the result will be corrected.
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage message = eventContext.getMessage();
//int groupSize = message.getCorrelationGroupSize();
//System.out.println("############# correlationGroupSize: " + groupSize);
Object payload = message.getPayload();
if (payload != null && payload instanceof ArrayList) {
//message.setPayload(((ArrayList)payload).get(0));
return ((ArrayList)payload).get(0);
}
return message.getPayload();
}
the completed flow is:
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="AMQ_SCHEDULED_DELAY" value="10000"/>
</message-properties-transformer>
<request-reply storePrefix="mainFlow">
<jms:outbound-endpoint queue="request" connector-ref="amqConnector" doc:name="JMS"></jms:outbound-endpoint>
<jms:inbound-endpoint queue="response" connector-ref="amqConnector" doc:name="JMS"></jms:inbound-endpoint>
</request-reply>
<component class="com.neusoft.fx.JmsMessageTransformer" doc:name="Java"/>
<message-properties-transformer doc:name="Set Content Type">
<delete-message-property key="Content-type" />
<add-message-property key="Content-Type" value="text/xml"/>
</message-properties-transformer>
<logger message="----- LOGGER ----- after #[groovy:message.toString()]" level="INFO" doc:name="Logger" />
</flow>

Try adding the following before the HTTP outbound endpoint in flow2:
<copy-properties propertyName="MULE_*"/>

Related

Counter not work properly while using collection splitter mule esb

I read data from salesforce and split it using collection splitter. I want to aggregate all data into single list. First I count all records and I set that counter with MULE_CORRELATION_GROUP_SIZE. But my counter gives me wrong count..And my data didn't aggregate..
How can I solve this problem
Is my following flow right?
Following is my code
<flow name="davesalesforceFlow1Tmp" doc:name="davesalesforceFlow1Tmp">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" doc:name="HTTP" path="test" contentType="text/plain" />
<sfdc:query config-ref="salesforce" doc:name="Salesforce" query="My query"/>
<collection-splitter doc:name="Collection Splitter"/>
<set-session-variable variableName="cnt"
value="#[org.mule.util.StringUtils.countMatches(message.payload, '\n') + org.mule.util.StringUtils.countMatches(message.payload, ',') - 1]" doc:name="Session Variable"/>
<set-property propertyName="MULE_CORRELATION_GROUP_SIZE"
value="#[sessionVars.cnt]" doc:name="Property"/>
<collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/>
I also tried following code But in output got only single record
<flow name="davesalesforceFlow1Tmp" doc:name="davesalesforceFlow1Tmp">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" doc:name="HTTP" path="test" contentType="text/plain" />
<sfdc:query config-ref="salesforce" doc:name="Salesforce" query="My query"/>
<collection-splitter doc:name="Collection Splitter"/>
<set-property propertyName="MULE_CORRELATION_GROUP_SIZE"
value="#[message.outboundProperties['MULE_CORRELATION_SEQUENCE']]" doc:name="Property"/>
<collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/>
<logger message="MY PAYLOAD IS #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</flow>
If you use the collection splitter and aggregator together theres no need to keep track of the count or anything.
Mule will take care of this via the MULE_CORRELATION_* header behind the scenes.
Only if you are dong for complex splits and aggregates may you need to modify these headers yourself.
<logger level="INFO" message="size before: #[payload.size()]" />
<collection-splitter />
<logger level="INFO" message="Individual item: #[payload]" />
<collection-aggregator />
<logger level="INFO" message="size after: #[payload.size()]" />

Mule ESB: Not able to control the flows from flow1 to flow 2

I have a ServiceFlow and a FileFlow. As soon as the ServiceFlow (Flow1) is triggered, FileFlow (Flow2) should take all the files and process them.
Making the initial state as stopped in Flow2 works only for the first time until Mule server started i.e., for the first triggered execution. Once the flow reaches the first trigger, if I try to keep some files in file:inbound-endpoint it starts processing the files.
But my scenario is based on each trigger only, so the second file has to pick the file. Please help me how to control this in Flow2.
I'm using the below code
<flow name="serviceFlow" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8081" doc:name="HTTP" contentType="text/xml"
mimeType="text/xml" />
<set-payload value="'Started Processing'" doc:name="Set Payload" />
<async doc:name="Async">
<expression-component doc:name="Expression">
app.registry.FileFlow.start();
</expression-component>
</async>
</flow>
<flow name="FileFlow" doc:name="Flow2" initialState="stopped" >
<file:inbound-endpoint responseTimeout="10000" doc:name="File" path="C:\Users\Desktop\IN"/>
<batch:execute name="businessBatch1" doc:name="Batch Execute"/>
</flow>
Using Mule version: 3.5.1
What I can suggest you is to put a <expression-component doc:name="Expression">app.registry.FileFlow.stop();</expression-component> at the end of second flow so after the second flow is executed it will again make it's initial state "stopped" so that you can trigger the first flow again without fear since the flow2 is stopped.
<flow name="serviceFlow" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8081" doc:name="HTTP" contentType="text/xml"
mimeType="text/xml" />
<set-payload value="'Started Processing'" doc:name="Set Payload" />
<async doc:name="Async">
<expression-component doc:name="Expression">
app.registry.FileFlow.start();
</expression-component>
</async>
</flow>
<flow name="FileFlow" doc:name="Flow2" initialState="stopped" >
<file:inbound-endpoint responseTimeout="10000" doc:name="File" path="C:\Users\Desktop\IN"/>
<batch:execute name="businessBatch1" doc:name="Batch Execute"/>
<expression-component doc:name="Expression">
app.registry.FileFlow.stop();
</expression-component>
</flow>

request-reply router is not working

I am stuck up with a problem with the request-reply router in mule. I am using the mule release 3.4.0. The request-reply is used in a fork-join pattern , i followed this article on the blog site http://blogs.mulesoft.org/aggregation-with-mule-fork-and-join-pattern/.
<request-reply>
<all enableCorrelation="ALWAYS">
<vm:outbound-endpoint path="PathA"/>
<vm:outbound-endpoint path="PathB"/>
</all>
<vm:inbound-endpoint path="FinalResponse">
<message-properties-transformer>
<add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="2" />
</message-properties-transformer>
<collection-aggregator />
</vm:inbound-endpoint>
</request-reply>
The issue that i face is the processor placed after the request-reply is not reached.In mule i see 2 responses been sent to the FinalResponse vm endpoint. I tried placing my own custom aggregator in place of the collection-aggregator. But this is not reached. I am not sure how i can debug this issue. Please note that i have 2 such request-reply routers in two flows. Can someone help on this.
Adding the mule configuration. For abbrevity attaching only the parent flow and one of the child flow
ParentFlow
<flow name="ParentFlow" doc:name="ParentFlow" tracking:enable-default-events="true">
<file:inbound-endpoint path="${SourceFilePath}"
connector-ref="ParentFlowInboundConnector"
responseTimeout="10000" tracking:enable-default-events="true">
<file:filename-regex-filter pattern="${REGEX}" caseSensitive="false"/>
</file:inbound-endpoint>
<object-to-string-transformer doc:name="Object to String"/>
<message-properties-transformer
doc:name="Message Properties">
<add-message-property key="Source_System" value="XXX" />
<add-message-property key="publisherName" value="YYY" />
<add-message-property key="FlowName" value="ZZZ"/>
</message-properties-transformer>
<!-- This would store the message in the db -->
<wire-tap>
<vm:outbound-endpoint path="PERSITENCE.OUT"/>
</wire-tap>
<request-reply>
<all doc:name="Move the message to all endpoints" enableCorrelation="ALWAYS">
<vm:outbound-endpoint path="PathA"/>
<vm:outbound-endpoint path="PathB"/>
<vm:outbound-endpoint path="PathC"/>
<vm:outbound-endpoint path="PathD"/>
</all>
<vm:inbound-endpoint path="Response">
<message-properties-transformer>
<add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="4" />
</message-properties-transformer>
<collection-aggregator failOnTimeout="false" doc:name="Collection Aggregator" />
</vm:inbound-endpoint>
</request-reply>
<component class="ProcessorA" />
<component class="ProcessorB" />
<exception-strategy ref="Exception Strategy" doc:name="Reference Exception Strategy"/>
</flow>
Child Flow
<flow name="PathA" doc:name="PathA">
<vm:inbound-endpoint path="PathA" >
<vm:transaction action="ALWAYS_BEGIN"/>
</vm:inbound-endpoint>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="originalFilename_processing" value="#[message.inboundProperties.originalFilename]" />
</message-properties-transformer>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="directory" value="#[message.inboundProperties.directory]" />
</message-properties-transformer>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="Destination_System" value="XXX" />
</message-properties-transformer>
<file:outbound-endpoint path="${OutPathA}" connector-ref="FileConnector_1"
tracking:enable-default-events="true"/>
<!--Send email alerts -->
<all doc:name="All" >
<processor-chain>
<message-property-filter pattern="turnOffEmail=false" caseSensitive="true" doc:name="Message Property"/>
<custom-transformer class="com.XXX.YYY.ZZZ.VelocityTemplateResolver" doc:name="Java">
<spring:property name="flowName" value="PPPP"/>
</custom-transformer>
<smtp:outbound-endpoint host="${SMTP_HOSTNAME}" port="${SMTP_PORT}" user="${SMTP_USERNAME}" password="${SMTP_PASSWORD}" to="${TO_ADDRESS}" from="${FROM_ADDRESS}" subject="${MAIL_SUBJECT}" cc="${MAIL_CC_ADDRESS}" bcc="${MAIL_BCC_ADDRESS}" responseTimeout="10000" transformer-refs="emailVelocityMessageTransformer" tracking:enable-default-events="true"/>
</processor-chain>
<processor-chain>
<message-property-filter pattern="turnOffEmail=false" caseSensitive="true" doc:name="Message Property"/>
<custom-transformer class="com.XXX.YYY.ZZZ.VelocityTemplateResolver" doc:name="Java">
<spring:property name="flowName" value="FlowName"/>
</custom-transformer>
<smtp:outbound-endpoint host="${SMTP_HOSTNAME}" port="${SMTP_PORT}" user="${SMTP_USERNAME}" password="${SMTP_PASSWORD}" to="${MAIL_TO_ADDRESS}" from="${MAIL_FROM_ADDRESS}" subject="${MAIL_SUBJECT}" cc="${MAIL_CC_ADDRESS}" bcc="${BCC_ADDRESS}" responseTimeout="10000" transformer-refs="emailVelocityMessageTransformer" tracking:enable-default-events="true"/>
</processor-chain>
<processor-chain>
<message-property-filter pattern="turnOffEmail=false" caseSensitive="true" doc:name="Message Property"/>
<custom-transformer class="com.XXX.YYY.ZZZ.VelocityTemplateResolver" doc:name="Java">
<spring:property name="flowName" value="AAAA"/>
</custom-transformer>
<smtp:outbound-endpoint host="${SMTP_HOSTNAME}" port="${SMTP_PORT}" user="${SMTP_USERNAME}" password="${SMTP_PASSWORD}" to="${MAIL_TO_ADDRESS}" from="${MAIL_FROM_ADDRESS}" subject="${MAIL_SUBJECT}" cc="${MAIL_CC_ADDRESS}" bcc="${MAIL_BCC_ADDRESS}" responseTimeout="10000" transformer-refs="emailVelocityMessageTransformer" tracking:enable-default-events="true"/>
</processor-chain>
</all>
<rollback-exception-strategy doc:name="Rollback Exception Strategy" maxRedeliveryAttempts="${MAX_REDELIVERY_ATTEMPTS}" enableNotifications="false">
<logger message="==Rollback log ===" level="INFO" doc:name="Logger"/>
</rollback-exception-strategy>
</flow>
The most likely cause of the the problem is correlation ID.
You might want to inspect the correlation ID of the messages sent out to Path A and Path B. The message received on FinalResponse VM inbound endpoint needs to have the same correlation ID, otherwise it won't be accepted as a response to the messages previously sent. In other words the request-reply will NOT accept just anything in the inbound-endpoint but just the message matching the correlation ID of the posted on outbound-endpoint with the request-reply router.
You can set the custom correlation ID using this --
<set-property propertyName="MULE_CORRELATION_ID" value="some-correlation-id" />

Issue with mule vmconnector to receive from more than 20 one-way inbound endpoints

I am having the following problem concerning asynchronous (or one-way) vm inbound endpoints. In the tests below, it seems that the number of one-way inbound endpoints is limited to 20 per vmconnector. My question is: Is there a setting on the vmconnector or a way programmatically to configure the vmconnector to remove this limitation?
I am using Mule 3.3.1 CE.
Thanks.
test1 (will fail to reach secondFlow unless the 21nd endpoint uses vmConn2):
<mule ..>
<stdio:connector name="stdioConn" messageDelayTime="1000" promptMessage="prompt >"/>
<vm:connector name="vmConn"/>
<vm:connector name="vmConn2"/>
<flow name="FirstFlow">
<stdio:inbound-endpoint system="IN" connector-ref="stdioConn"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="path21" connector-ref="vmConn"/>
</flow>
<flow name="SecondFlow">
<composite-source doc:name="Composite Source">
<vm:inbound-endpoint exchange-pattern="one-way" path="path1" connector-ref="vmConn"/>
<vm:inbound-endpoint exchange-pattern="one-way" path="path2" connector-ref="vmConn"/>
<vm:inbound-endpoint exchange-pattern="one-way" path="path3" connector-ref="vmConn"/>
....
<vm:inbound-endpoint exchange-pattern="one-way" path="path20" connector-ref="vmConn"/>
<vm:inbound-endpoint exchange-pattern="one-way" path="path21" connector-ref="vmConn"/>
</composite-source>
<logger message="MESSAGE RECEIVED!" level="INFO" doc:name="Logger"/>
</flow>
test2 (same test with 21 flows):
<flow name="Flow1" >
<stdio:inbound-endpoint system="IN" connector-ref="stdioConn"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="path21" connector-ref="vmConn" />
</flow>
<flow name="Flow2">
<vm:inbound-endpoint exchange-pattern="one-way" path="path1" connector-ref="vmConn" doc:name="VM" />
<logger message="MESSAGE RECEIVED!" level="INFO" doc:name="Logger" />
</flow>
<flow name="Flow3">
<vm:inbound-endpoint exchange-pattern="one-way" path="path2" connector-ref="vmConn" doc:name="VM" />
<logger message="MESSAGE RECEIVED!" level="INFO" doc:name="Logger" />
</flow>
...
<flow name="Flow21">
<vm:inbound-endpoint exchange-pattern="one-way" path="path20" connector-ref="vmConn" doc:name="VM" />
<logger message="MESSAGE RECEIVED!" level="INFO" doc:name="Logger" />
</flow>
<flow name="Flow22">
<vm:inbound-endpoint exchange-pattern="one-way" path="path21" connector-ref="vmConn" doc:name="VM" />
<logger message="MESSAGE RECEIVED!" level="INFO" doc:name="Logger" />
</flow>
Any vm connector has a thread pool of message receivers. Once the receiver are exhausted new vm inbound endpoint want be able to process messages.
To address it you should increase the number of message receivers configuring threading profiles properly

Authentication interfers with enricher in Mule 3.3

I'm currently writing a rather simple mule-flow that uses basic authentication
<custom-transformer class="com.org.HttpRequestToMyRequest" name="HttpRequestToMyRequest" doc:name="Java"/>
<flow name="Input_Flow" doc:name="Input_Flow">
<http:inbound-endpoint exchange-pattern="request-response" host="http://12.23.34.45" port="1234" path="/foo">
<mule-ss:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>
<flow-ref name="Sorting_Flow" doc:name="Sorting flow"/>
</flow>
<sub-flow name="Sorting_Flow" doc:name="Sorting_Flow">
<transformer ref="HttpRequestToMyRequest" doc:name="Transform Http Request to POJO with interesting methods"/>
<enricher target="#[variable:authorized]">
<http:outbound-endpoint exchange-pattern="request-response" host="12.34.45.56" port="1234" path="foo/bar" method="GET" disableTransportTransformer="true"
responseTransformer-refs="ObjectToString" doc:name="Authorization Service"/>
</enricher>
<choice doc:name="Choice">
<when expression="header:INVOCATION:authorized=true">
<processor-chain>
<component class="com.org.MyClass"/>
<transformer ref="MyObjToString"/>
<http:response-builder status="200" contentType="text/xml" doc:name="HTTP Response Builder"/>
</processor-chain>
</when>
<when SOMETHING ELSE>
DO SOMETHING ELSE
</when>
</choice>
</sub-flow>
If I remove the http-security-filter then this flow works as expected and the payload in the MuleMessage is of the type MyRequest returned by the HttpRequestToMyRequest transformer. But once i add the security-filter the enricher changes my payload from the expected type to a byte[]. If i convert the byte[] to a String then it turns out to be the instancename of MyRequest (com.org.MyRequest#15ae9009).
Any help or ideas would be appreciated.
Edit
Just to be clear. Here are three flow xml fragments where two behave well and the last one has the strange behaviour i don't understand.
This flow, where I've commented out the security-filter on the inbound endpoint, works as expected and the ClassNameLogger statements prints out, in order, String, MyRequest, MyRequest.
<custom-transformer class="com.org.HttpRequestToMyRequest" name="HttpRequestToMyRequest" doc:name="Java"/>
<custom-transformer class="com.org.ClassNameLogger" name="ClassNameLogger" doc:name="Java"/>
<flow name="Input_Flow" doc:name="Input_Flow">
<http:inbound-endpoint exchange-pattern="request-response" host="http://12.23.34.45" port="1234" path="/foo">
<!-- <mule-ss:http-security-filter realm="mule-realm"/> -->
</http:inbound-endpoint>
<flow-ref name="Sorting_Flow" doc:name="Sorting flow"/>
</flow>
<sub-flow name="Sorting_Flow" doc:name="Sorting_Flow">
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<transformer ref="HttpRequestToMyRequest" doc:name="Transform Http Request to POJO with interesting methods"/>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<enricher target="#[variable:authorized]">
<http:outbound-endpoint exchange-pattern="request-response" host="12.34.45.56" port="1234" path="foo/bar" method="GET" disableTransportTransformer="true"
responseTransformer-refs="ObjectToString" doc:name="Authorization Service"/>
</enricher>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<choice doc:name="Choice">
<when expression="header:INVOCATION:authorized=true">
<processor-chain>
<component class="com.org.MyClass"/>
<transformer ref="MyObjToString"/>
<http:response-builder status="200" contentType="text/xml" doc:name="HTTP Response Builder"/>
</processor-chain>
</when>
<when SOMETHING ELSE>
DO SOMETHING ELSE
</when>
</choice>
</sub-flow>
This flow, where I've commented out the enricher, works as expected, aside from the fact that it doesn't enter the choise since the variable set by the enricher is not defined. The ClassNameLogger statements prints out, in order, String, MyRequest, MyRequest.
<custom-transformer class="com.org.HttpRequestToMyRequest" name="HttpRequestToMyRequest" doc:name="Java"/>
<custom-transformer class="com.org.ClassNameLogger" name="ClassNameLogger" doc:name="Java"/>
<flow name="Input_Flow" doc:name="Input_Flow">
<http:inbound-endpoint exchange-pattern="request-response" host="http://12.23.34.45" port="1234" path="/foo">
<mule-ss:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>
<flow-ref name="Sorting_Flow" doc:name="Sorting flow"/>
</flow>
<sub-flow name="Sorting_Flow" doc:name="Sorting_Flow">
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<transformer ref="HttpRequestToMyRequest" doc:name="Transform Http Request to POJO with interesting methods"/>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<!-- <enricher target="#[variable:authorized]">
<http:outbound-endpoint exchange-pattern="request-response" host="12.34.45.56" port="1234" path="foo/bar" method="GET" disableTransportTransformer="true"
responseTransformer-refs="ObjectToString" doc:name="Authorization Service"/>
</enricher> -->
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<choice doc:name="Choice">
<when expression="header:INVOCATION:authorized=true">
<processor-chain>
<component class="com.org.MyClass"/>
<transformer ref="MyObjToString"/>
<http:response-builder status="200" contentType="text/xml" doc:name="HTTP Response Builder"/>
</processor-chain>
</when>
<when SOMETHING ELSE>
DO SOMETHING ELSE
</when>
</choice>
</sub-flow>
This flow, where I have both the enricher and the security-filter in place, doesn't work as expected and the ClassNameLogger statements prints out, in order, String, MyRequest, byte[].
<custom-transformer class="com.org.HttpRequestToMyRequest" name="HttpRequestToMyRequest" doc:name="Java"/>
<custom-transformer class="com.org.ClassNameLogger" name="ClassNameLogger" doc:name="Java"/>
<flow name="Input_Flow" doc:name="Input_Flow">
<http:inbound-endpoint exchange-pattern="request-response" host="http://12.23.34.45" port="1234" path="/foo">
<mule-ss:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>
<flow-ref name="Sorting_Flow" doc:name="Sorting flow"/>
</flow>
<sub-flow name="Sorting_Flow" doc:name="Sorting_Flow">
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<transformer ref="HttpRequestToMyRequest" doc:name="Transform Http Request to POJO with interesting methods"/>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<enricher target="#[variable:authorized]">
<http:outbound-endpoint exchange-pattern="request-response" host="12.34.45.56" port="1234" path="foo/bar" method="GET" disableTransportTransformer="true"
responseTransformer-refs="ObjectToString" doc:name="Authorization Service"/>
</enricher>
<transformer ref="ClassNameLogger" doc:name="Logs The Class Name of MuleMessage payload"/>
<choice doc:name="Choice">
<when expression="header:INVOCATION:authorized=true">
<processor-chain>
<component class="com.org.MyClass"/>
<transformer ref="MyObjToString"/>
<http:response-builder status="200" contentType="text/xml" doc:name="HTTP Response Builder"/>
</processor-chain>
</when>
<when SOMETHING ELSE>
DO SOMETHING ELSE
</when>
</choice>
</sub-flow>
Edit 2
The code in the HttpRequestToMyRequest transformer
public class HttpRequestToMyRequest extends AbstractMessageTransformer{
#Override
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
if("/foo".equals(message.getInboundProperty("http.request.path")){
return new MyFooRequest();
}
if("/bar".equals(message.getInboundParameter("http.request.path")){
return new MyBarRequest();
}
else return new MyEmptyRequest();
}
}
Edit 3
Apparently this was something Mule 3.3 specific. Once I upgraded to 3.4 everything started working as expected.
With Mule 3.4, I notice no difference of payload type with or without the http-security-filter element.
It is either a java.lang.String if the request is an HTTP GET or java.io.InputStream if it is a POST or PUT.
Since you are on 3.3, you are possibly hitting a bug that is gone in 3.4, since I don't have any issue. If that is the case, finding a workaround for the issue on 3.3 would be hairy: upgrading to 3.4 is the path forward.