Getting org.mule.api.expression.ExpressionRuntimeException on running below snippet in Mule
I have stored value in var1 and var2 as [message.inboundProperties.'http.query.params'.value1] and [message.inboundProperties.'http.query.params'.value2] respectively.
I'm trying to return sum of the parameters passed.
import java.lang.Integer;
int firstValue = Integer.pareseint(flowVars.var1);
int secondValue =Integer.pareseint(flowVars.var2);
int result = firstValue + secondValue;
payload = result
UPDATE: I've resolved the error but now it is concatenating the inputs not adding them. Other operators like *, /, -, etc work fine.
You can try using Mule Expression as: #[2 + 4]
You can try it in the following way using java transformer component. It's working for me.
Below is the main mule xml config file
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="tryoutFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/bill" allowedMethods="GET" doc:name="HTTP"/>
<set-variable variableName="var1" value="#[message.inboundProperties.'http.query.params'.value1]" doc:name="var1"/>
<set-variable variableName="var2" value="#[message.inboundProperties.'http.query.params'.value2]" doc:name="var2"/>
<custom-transformer class="org.mule.transformar.Addition" returnClass="java.lang.Integer doc:name="Java">
</custom-transformer>
</flow>
</mule>
And below are the java class which java transformer component use to transform your message. Remember put the java class under src/main/java folder.
org.mule.transformar.Addition
package org.mule.transformar;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.api.transport.PropertyScope;
import org.mule.transformer.AbstractMessageTransformer;
public class Addition extends AbstractMessageTransformer{
#Override
public Integer transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
// TODO Auto-generated method stub
Integer i1 = Integer.parseInt(message.getProperty("var1", PropertyScope.INVOCATION));
Integer i2 = Integer.parseInt(message.getProperty("var2", PropertyScope.INVOCATION));
Integer returnVal = i1 + i2;
return returnVal;
}
}
You have done everything right, but few Syntax error like Integer.pareseint instead of Integer.parseInt ...
Please refer the following flow to make it work in a easy way:-
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<set-variable doc:name="Variable" value="#[message.inboundProperties.'http.query.params'.value1]" variableName="var1"/>
<set-variable doc:name="Variable" value="#[message.inboundProperties.'http.query.params'.value2]" variableName="var2"/>
<expression-component doc:name="Expression"><![CDATA[
import java.lang.Integer;
int firstValue = Integer.parseInt(flowVars.var1);
int secondValue = Integer.parseInt(flowVars.var2);
int result = firstValue + secondValue;
payload = result]]></expression-component>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#['Total '+message.payload]" level="INFO" doc:name="Logger"/>
</flow>
The url to test is :- http://localhost:8081/test/?value1=12&value2=100
Related
I created a simple flow which creates a list of names transforms it. The transformer throws an IllegalArgumentException to break the flow. Unfortunately, the failureExpression does not work even though an exception is thrown. It doesn't match any exceptions. I have included the flow and the transformer.
Here is my configuration:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/scripting
http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm
http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<spring:beans>
<spring:bean name="transf" class="com.until.sucessful.tests.StringAppenderTransformer" />
<spring:bean id="objectStore" class="org.mule.util.store.SimpleMemoryObjectStore" />
</spring:beans>
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" />
<flow name="untilsuccessfultestsFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/mytest" doc:name="HTTP" />
<splitter expression="#[xpath3('//Names')]" doc:name="Splitter" />
<until-successful maxRetries="5" millisBetweenRetries="5000" doc:name="Until Successful" objectStore-ref="objectStore" failureExpression="#[exception is java.lang.IllegalArgumentException)]">
<vm:outbound-endpoint path="process-vm" exchange-pattern="request-response" />
</until-successful>
<logger level="INFO" message="After the scoped processor :: #[payload]" doc:name="Logger" />
</flow>
<flow name="processorFlow">
<vm:inbound-endpoint path="process-vm" exchange-pattern="request-response" />
<logger level="INFO" message="Before component #[payload]" doc:name="Logger" />
<transformer ref="transf" />
</flow>
</mule>
Here is my Transformer
public class StringAppenderTransformer extends AbstractTransformer {
#Override
protected Object doTransform(Object src, String enc) throws TransformerException {
String payload = (String) src;
List<String> results = new ArrayList<>();
System.out.println("Upon entry in transformer payload is :: " + payload);
System.out.println("About to return from transformer payload is :: " + payload.split("\\s+"));
int i = 1;
for (String args : payload.split("\\s+")) {
System.out.println("" + i + " " + args);
i++;
if (args != null && args.trim().equals("")) {
results.add(args);
} else {
throw new IllegalArgumentException("Break the Flow!!!!!!");
}
}
return results;
}
}
According to documentation :
https://docs.mulesoft.com/mule-user-guide/v/3.5/until-successful-scope
failureExpression
Specifies an expression that, when it evaluated to true, determines
that the processing of one route was a failure. If no expression is
provided, only an exception will be treated as a processing failure.
So 2 options, remove that expression or be sure that the MEL return true. #[exception.causeMatches("java.lang.IllegalArgumentException")]
I have mule flow look like below
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8111" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="api.bonanza.com" port="443" doc:name="HTTP Request Configuration" protocol="HTTPS"/>
<flow name="bonanza_fetchtoken_ceFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/add" allowedMethods="GET,POST" doc:name="HTTP" />
<flow-ref name="bonanza_addfixedpriceitemSub_Flow" doc:name="bonanza_addfixedpriceitemSub_Flow"/>
</flow>
<sub-flow name="bonanza_addfixedpriceitemSub_Flow">
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="X-BONANZLE-API-DEV-NAME" value="t******I"/>
<add-message-property key="X-BONANZLE-API-CERT-NAME" value="l*****F"/>
</message-properties-transformer>
<set-property propertyName="Content-Type" value="application/x-www-form-urlencoded" doc:name="Property"/>
<set-property propertyName="Accept" value="application/json" doc:name="Property"/>
<set-variable variableName="sim" value="{requesterCredentials:{bonanzleAuthToken:nWn1a9l3NT}}" doc:name="Variable"/>
<scripting:transformer returnClass="java.util.Map" doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[import groovy.json.JsonBuilder
m = [addFixedPriceItemRequest:'{requesterCredentials:{bonanzleAuthToken:n*****T}}']
builder = new JsonBuilder()
builder(m)
]]></scripting:script>
</scripting:transformer>
<logger message="payload :#[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/api_requests/secure_request" method="POST" followRedirects="true" parseResponse="false" doc:name="HTTP">
<http:success-status-code-validator values="0..599"/>
</http:request>
<logger message="resp :#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</sub-flow>
</mule>
I am able to receiving successful response from API using postman tool. I try to simulate same thing using above ESB mule flow. But API throws me an error as like below. Hence i have used requestb.in to compare the requests going from esb mule and postman tool. i found differences in the HTTP headers alone.
RAW body from postman to requestb.in -
addFixedPriceItemRequest={requesterCredentials:{bonanzleAuthToken:nW*****NT}}
RAW Body from ESB mule to requestb.in
addFixedPriceItemRequest=%7BrequesterCredentials%3A%7BbonanzleAuthToken%3AnW****NT%7D%7D
It seems that i have to serialize the json content before sending as content type - application/x-www-form-urlencoded. I found this info in this mule doc
How can i serialize json payload in groovy and sending as map payload?
API Error Response
{
"ack": "Failure",
"version": "1.0beta",
"timestamp": "2016-03-15T07:18:11.000Z",
"errorMessage": {
"message": "Cannot determine what type of request you are making. Often this can be the result of data that has not been escaped before being passed to the API. If you are passing data with quotation marks or other special characters, you should translate it to JSON, then escape it, before sending it over the API."
}
}
Please let me know for any additional info. Thanks in advance!
The flow got worked by adding key value pair in query parms in the http component. The flowVariable requestpayload has json string. So my Mule http component looks like below.
<http:request config-ref="HTTP_Request_Configuration" path="/api_requests/secure_request" method="POST" followRedirects="true" parseResponse="false" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="addFixedPriceItemRequest" value="#[flowVars.requestpayload]"/>
</http:request-builder>
<http:success-status-code-validator values="0..599"/>
</http:request>
I have the following flow, that accepts a JSON object from http, then
converts the JSON object to a standard Object, and then performs
a CHOICE on the object.
Below is the flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:json="http://www.mulesoft.org/schema/mule/json" version="EE-3.5.0" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/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/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<json:object-to-json-transformer name="Object_to_JSON" doc:name="Object to JSON"/>
<flow doc:name="HelloWorldFlow1" name="HelloWorldFlow1">
<http:inbound-endpoint doc:description="This endpoint receives an HTTP message." doc:name="HTTP" exchange-pattern="request-response" host="localhost" port="8081" contentType="application/json"/>
<json:json-to-object-transformer doc:name="JSON to Object"/>
<choice doc:name="Choice-Determine-Route" tracking:enable-default-events="true">
<when expression="#[payload.uid == 'ABC']">
<set-payload value="#['When ABC case']" doc:name="Set Payload"/>
</when>
<otherwise>
<set-payload value="#['Default case, payload: ' + payload + ', payload.uid: ' + payload.uid]" doc:name="Set Payload"/>
</otherwise>
</choice>
</flow>
</mule>
Below is the test of the flow
C:\curl>type input2.txt
{ "uid" : "ABC" }
C:\curl>curl -H "Content-Type: application/json" -i -d #input2.txt http://localh
ost:8081
Content-Type: application/json
Default case, payload: {"uid":"ABC"}, payload.uid: null
So even though my input2.txt contained:
{ "uid" : "ABC" }
I could not get the following expression to trigger successfully
#[payload.uid == 'ABC']
Now notice the Set Payload expression
#['Default case, payload: ' + payload + ', payload.uid: ' + payload.uid]
... and what it reported:
Default case, payload: {"uid":"ABC"}, payload.uid: null
So it does not seem to recognize payload.uid
How should I reference this in MEL ?
Thanks
Because you haven't defined the returnClass attribute,it will by default return an instance of org.mule.module.json.JsonData - http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/module/json/JsonData.html
So in that case you need to use:
when expression="#[payload.get('UID') == 'ABC']"
If instead you set the transformer to return a map or an object with a uid field you can navigate it using the . notation you tried.
So to make your expression work use:
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
I need to send multiple response from a mule flow one to a http endpoint which would be JSON and another to an SMTP endpoint where the recipient receives a custom email. If I use a transformer to transform the json respone which is default both endpoints receive the same custom email format. So how can I send the default JSON response to the http endpoint and the Custom Transformer generated email to the smtp endpoint below is my flow and Custom Transformer
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:smtps="http://www.mulesoft.org/schema/mule/smtps" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:email="http://www.mulesoft.org/schema/mule/email" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/smtps http://www.mulesoft.org/schema/mule/smtps/current/mule-smtps.xsd">
<data-mapper:config name="json2_to_json" transformationGraphPath="json2_to_json.grf" doc:name="json_to_json"/>
<flow name="jirarestFlow3" doc:name="jirarestFlow3">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="6767" doc:name="HTTP" contentType="application/json"/>
<logger message="This is from hari #[message.payload]" level="DEBUG" doc:name="Logger"/>
<data-mapper:transform config-ref="json2_to_json" doc:name="JSON To JSON"/>
<logger level="DEBUG" doc:name="Logger" message="This is from Data Mapper #[json:fields/priority/id]"/>
<set-variable variableName="myPayload" value="#[json:fields/reporter/emailAddress]" doc:name="tmpPayload"/>
<logger message="MyPayload is #[myPayload]" level="DEBUG" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="9999" path="rest/api/2/issue/" method="POST" user="" password="" contentType="application/json" doc:name="HTTP"/>
<response>
<!--set-variable variableName="responsePayload" value="#[message.payload]" doc:name="respPayload"/-->
<!--http:response-builder doc:name="HTTP Response Builder" contentType="text/plain" status="200"/-->
<!--expression-transformer doc:name="Expression" /-->
<custom-transformer class="org.hhmi.transformer.EmailBodyTransformer" doc:name="Java"/>
<smtps:outbound-endpoint host="smtp.gmail.com" port="465" user="pandalai" password="soapui67" to="#[myPayload]" from="pandalai#gmail.com" subject="Jira Ticket" responseTimeout="10000" mimeType="text/plain" doc:name="SMTP">
<email:string-to-email-transformer doc:name="Email to String"/>
</smtps:outbound-endpoint>
</response>
</flow>
</mule>
Custom Transformer
package org.xxx.transformer;
import org.apache.log4j.Logger;
import org.xxx.dto.JsonBean;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
public class EmailBodyTransformer extends AbstractMessageTransformer {
public static Logger logger = Logger.getLogger(EmailBodyTransformer.class);
#Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
// TODO Auto-generated method stub
StringBuffer html = new StringBuffer();
Map<String,String> map = new HashMap<String,String>();
ObjectMapper mapper = new ObjectMapper();
JsonBean jBean = new JsonBean();
try {
logger.debug("EmailBodyTransformer payload "
+ message.getPayloadAsString());
logger.debug("EmailBodyTransformer class " + message.getClass());
map = mapper.readValue(message.getPayloadAsString(),
new TypeReference<HashMap<String,String>>(){});
jBean.setId(map.get("id"));
jBean.setKey(map.get("key"));
jBean.setSelf(map.get("self"));
System.out.println("EmailBodyTransformer id from map: "+ jBean.getId());
System.out.println("EmailBodyTransformer map: "+ map);
/* html.append("");
html.append("");
html.append("");
html.append("Dear ").append(jBean.getId()).append(" ");
html.append("Thank you for your order. Your transaction reference is: <strong>");
html.append(jBean.getKey()).append("</strong>");
html.append("");*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return message;
//return html;
}
}
The <response></response> tags mean, that whatever you put there will be put into your http:inbound-endpoint response. Since smtp is asynchronous, it will be ignored in the response phase, and the block will return whatever it gets from your custom transformer.
The solution is to move the contents inside the <response></response> block into an <async></async> block, so your custom transformer will not interfere with the http response. Inside the <response></response> block you will need just an <object-to-string-transformer> to transform your http:outbound-endpoint into a string.
EDIT:
Move the <object-to-string-transformer> after the http:outbound-endpoint and change your transformer to take String, not input stream. Otherwise the input stream gets closed once either of the two readers reads it. You will not need the <response></response> after this.
Your requirement is exactly what mule-requester-module is based on:
http://java.dzone.com/articles/introducing-mule-requester
example project: https://github.com/mulesoft/mule-module-requester
This module allows you to asynchronously do two things.
Hope this helps
Short: I want to post a couple of parameters (like user=admin, key=12345678) using the POST method to a PHP page (like localhost/post-debug.php). The script would read the $_POST values and do whatever.
My questions are:
1. How can I get the example below to work?
2. How can I create the Map Payload with POST parameters from a JSON encoded payload and send it to the PHP script?
Below is an isolated case I am trying to get running (the parameters are "read" from the HTTP endpoint). I am calling directly from the browser the following URL:
http://localhost:8081/httpPost?user=admin&key=12345678
The underlying XML:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/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/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<flow name="httpPostTestFlow1" doc:name="httpPostTestFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="httpPost" doc:name="HTTP"/>
<http:body-to-parameter-map-transformer doc:name="Body to Parameter Map"/>
<echo-component doc:name="Echo"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost/post-debug.php" port="80" contentType="application/x-www-form-urlencoded" doc:name="HTTP" />
</flow>
</mule>
I am using MuleStudio 1.3.2, Mule ESB v.3.3.
I've reviewed many similar questions but none got me on the right track.
Here is the solution for question 2 (answering question 1 won't help):
<flow name="httpPostTestFlow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8081" path="httpPost" />
<json:json-to-object-transformer
returnClass="java.util.Map" />
<http:outbound-endpoint exchange-pattern="request-response"
host="localhost" port="80" path="post-debug.php" method="POST"
contentType="application/x-www-form-urlencoded" />
<copy-properties propertyName="*" />
</flow>
I've used the following to check it works fine:
curl -H "Content-Type: application/json" -d '{"param1":"value1","param2":"value2"}' http://localhost:8081/httpPost
Note that I use copy-properties to propagate all the response headers from the PHP script invocation back to the original caller. Remove it if you don't care.
Have you tried configuring your outbound endpoint like this:
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="80" path="post-debug.php" contentType="application/x-www-form-urlencoded" doc:name="HTTP" method="POST"/>
Questions a little old, but just hit the same problem. I never could get the "body-to-parameter-map-transformer" to work, so I threw in a custom java component. It parses a URLEncoded param string into a HashMap. Set your vars based on that.
import java.util.HashMap;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
public class ParseParams {
public static HashMap<String, String> jsonToMap(String t) throws JSONException {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject jObject = new JSONObject(t);
Iterator<?> keys = jObject.keys();
while( keys.hasNext() ){
String key = (String)keys.next();
String value = jObject.getString(key);
map.put(key, value);
}
return map;
}
}