<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" contentType="application/x-www-form-urlencoded" path="getDetails" />
<object-to-string-transformer doc:name="Object to String"/>
<logger message=" Logging ...... #[message:payload]" level="INFO" doc:name="Logger"/>
i invoke thru chrome rest client
http://localhost:8081/getDetails
METHOD : post
below is json data
{
"id": "1",
"firstName": "xyz",
"lastName": "abc",
"address":"xy"
}
whatever json data i passed , i just want to print for processing . but
In logging it shows null payload
any suggesstion are welcome
I tested your scenario with the following :-
<flow name="Flow1" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" contentType="application/x-www-form-urlencoded" path="getDetails" />
<object-to-string-transformer doc:name="Object to String"/>
<logger message=" Logging ...... #[message:payload]" level="INFO" doc:name="Logger"/>
</flow>
And I got it in the log as bellow :-
You have probably posted in the same question in another thread too.
Please read comments in mule post json data to mule endpoint url
After http:inBound you need to convert it to json using object to string transformer
Related
I have a flow where I am trying to load a HTML page if successfully login or fails. Flow is working but while doing POST job on browser side it's not redirecting to the loginSuccessful.html or login/loginFailure.html.
<flow name="GetLoginPage">
<http:listener config-ref="HTTP_Listener_Configuration" path="/login" allowedMethods="GET" doc:name="HTTP"/>
<parse-template location="login/index.html" doc:name="Parse Template"/>
</flow>
<flow name="Dologin">
<http:listener config-ref="HTTP_Listener_Configuration" path="/login" allowedMethods="POST" doc:name="HTTP"/>
<logger message="trying to login!!!!!!!!!!!" level="INFO" doc:name="Logger"/>
<choice doc:name="Choice">
<when expression="#[payload.username == "mule" and payload.password == "mule"]">
<logger message="login successfully!!!!!!!!!!!" level="INFO" doc:name="Logger"/>
<parse-template location="login/loginSuccessful.html" doc:name="Parse Template"/>
</when>
<otherwise>
<logger message="login failed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" level="INFO" doc:name="Logger"/>
<parse-template location="login/loginFailure.html" doc:name="Parse Template"/>
</otherwise>
</choice>
</flow>
I took the liberty of creating my own payload in JSON and added the payload values from above:
{
"name": "mule",
"password": "mule"
}
Then, added a data transformer from JSON to Java, then I mildly adjusted your conditional test to eliminate the encoded quotes and replaced them with single quotes:
payload.username == 'mule' and payload.password == 'mule'
And the choice router correctly to pick up my test files with the parse template.
I want to check if a URI parameter exists in the URL using Mule 3.8.3 and also need to make sure that inboundProperties is not empty either when using the Choice component in Anypoint Studio 6.2 and Mule 3.8.3.
I have tried:
#[message.inboundProperties.'http.uri.params'.code != empty]
#[org.mule.util.StringUtils.isNotEmpty(message.inboundProperties.'http.uri.params'.code)]
For both I get
org.mule.api.expression.ExpressionRuntimeException: Execution of the
expression
"org.mule.util.StringUtils.isNotEmpty(message.inboundProperties.'http.query.params'.code)"
failed.
Is there any other way to try?
There are two "Expression" in palate.
1.Expression-transformer
Example : <expression-transformer expression="#[message.inboundProperties.'http.uri.params'.param != empty]" doc:name="Expression"/>
2.Expression-component
Example : <expression-component doc:name="Expression"/>
Make sure you use "Expression-transformer" as shown below
Try below flow in Anypoint Studio.It works for me.
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8082" basePath="/testapi" doc:name="HTTP Listener Configuration"/>
<flow name="uri">
<http:listener path="uri/{param}/resource" config-ref="HTTP_Listener_Configuration" doc:name="HTTP"/>
<expression-transformer expression="#[message.inboundProperties.'http.uri.params'.param != empty]" doc:name="Expression"/>
<object-to-string-transformer doc:name="Object to String"/>
<set-payload value="#[payload]" doc:name="Set Payload"/>
</flow>
Test above with below url in your browser
http://localhost:8082/testapi/uri/testUriParam/resource
This could be used with Choice component component as well.
Try below code :
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8082" basePath="/testapi" doc:name="HTTP Listener Configuration"/>
<flow name="uri">
<http:listener path="uri/{param}/resource" config-ref="HTTP_Listener_Configuration" doc:name="HTTP"/>
<choice doc:name="Choice">
<when expression="#[message.inboundProperties.'http.uri.params'.param != empty]">
<logger message="Found URI Param" level="INFO" doc:name="Logger"/>
<set-payload value="Found URI Param" doc:name="Set Payload"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger" message="URI Param not found"/>
<set-payload value="URI Param not found" doc:name="Set Payload"/>
</otherwise>
</choice>
</flow>
I am using an until successful scope for my outbound endpoint. Am getting a proper response but when it comes out of until successful am getting boolean value my flow is given below
<flow name="testFlow1" doc:name="testFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="test" doc:name="HTTP"/>
<until-successful maxRetries="5" failureExpression="#[message.inboundProperties['http.status'] != 200]" synchronous="true" doc:name="Until Successful">
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="www.example.com" doc:name="HTTP"/>
</until-successful>
<logger message="`From outbound #[payload]`" level="INFO" doc:name="Logger"/>
</flow>
</mule>
But am getting output in logger as
From outbound true
Hi there not sure what could be happening but here is a example run in 3.6.0 and it works properly:
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9090" doc:name="HTTP Listener Configuration"/>
<spring:beans>
<spring:bean id="objectStore" class="org.mule.util.store.SimpleMemoryObjectStore"/>
</spring:beans>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="9090" doc:name="HTTP Request Configuration"/>
<flow name="zzzFlow1" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-payload value="#['laleros']" doc:name="Set Payload"/>
<logger message="*************************** #[payload]" level="INFO" doc:name="Logger"/>
<until-successful maxRetries="5" doc:name="Until Successful" synchronous="true">
<http:request config-ref="HTTP_Request_Configuration" path="/t" method="POST" doc:name="HTTP"/>
</until-successful>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="*************************** #[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="tFlow1" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/t" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
Here is the output I'm getting:
*******************************************************************************************************
* - - + APPLICATION + - - * - - + DOMAIN + - - * - - + STATUS + - - *
*******************************************************************************************************
* zzz * default * DEPLOYED *
*******************************************************************************************************
INFO 2015-02-23 14:10:17,540 [[zzz].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: *************************** laleros
INFO 2015-02-23 14:10:17,593 [[zzz].HTTP_Listener_Configuration.worker.02] org.mule.api.processor.LoggerMessageProcessor: laleros
INFO 2015-02-23 14:10:17,670 [[zzz].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: *************************** laleros
And just FYI, I reckon you need the transformer after the the http request to serialise the response for it usually returns the stream as payload.
HIH
your definition of until-successful scope requires additional configuration need to be done.
give glance over the below link
UntilSuccessful component to poll http endpoint till condition is met
When i make a call to to soap web service using the soap component in Mule. The message properties context is lost. I understand a Mule enricher component can be used but not sure on the usage. Below you will find my test mule code
<spring:beans>
<spring:bean id="myWebServiceImpl" class="com.xxx.xxx.service.MyWebServiceImpl">
</spring:bean>
</spring:beans>
<custom-transformer class="com.xxx.xxx.service.TestTransformer" name="Java" doc:name="Java"/>
<flow name="testwebserviceFlow1" doc:name="testwebserviceFlow1">
<file:inbound-endpoint path="c:\landing" responseTimeout="10000" doc:name="File"/>
<object-to-string-transformer doc:name="Object to String"/>
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:28081/MyWebService" responseTimeout="100000" doc:name="HTTP" >
<cxf:jaxws-client operation="helloWorld" serviceClass="com.xxx.xxx.service.MyWebService" enableMuleSoapHeaders="true" doc:name="SOAP"/>
</http:outbound-endpoint>
<transformer ref="Java" doc:name="Transformer Reference"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
<flow name="MyWebServiceFlow" doc:name="MyWebServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:28081/MyWebService?wsdl" doc:name="HTTP" responseTimeout="100000">
<cxf:jaxws-service serviceClass="com.xxx.xxx.service.MyWebService" doc:name="SOAP"/>
</http:inbound-endpoint>
<component doc:name="MyWebService">
<spring-object bean="myWebServiceImpl"/>
</component>
</flow>
Yes, you can use an enricher to preserve your original message and put the return value of the web service into a variable. It works like this:
<enricher source="#[payload]" target="#[variable:myVal]">
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:28081/MyWebService" responseTimeout="100000" doc:name="HTTP" >
<cxf:jaxws-client operation="helloWorld" serviceClass="com.xxx.xxx.service.MyWebService" enableMuleSoapHeaders="true" doc:name="SOAP"/>
</http:outbound-endpoint>
</enricher>
You can then later access the variable like this:
<logger message="#[variable:myVal]" level="INFO"/>
If you just want to call the web service and ignore any return values, you can also do that asynchronously by putting the http outbound inside <async></async> tags instead of the enricher.
Is there a way to send the JSON response to another server as a request asynchronously (for example to monitor, etc...)
here is my mule flow
<flow name="loggingFlow1" doc:name="loggingFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="${source.http.host}" port="${source.http.port}" doc:name="HTTP" responseTimeout="10000" />
<http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://${dest.http.host}:${dest.http.port}#[header:INBOUND:http.request]" contentType="application/json" doc:name="HTTP_GET" responseTimeout="10000" />
<async processingStrategy="Asynchronous_Processing_Strategy" doc:name="Async">
<http:outbound-endpoint exchange-pattern="one-way" address="http://localhost:8080/Monitor/response" doc:name="HTTP"/>
</async>
</flow>
For any reason, it seems the InputStream produced by the first http:outbound-endpoint is read more than once.
Serializing this InputStream to a String with an object-to-string-transformer or a byte[] with an object-to-byte-array-transformer is the best option, the echo-component is a legacy one that is not very much used anymore.