Why Mule http inbound endpoint is always GET request. I'm logging type of http method
and it always logs type is GET even I specified method type PUT in http inbound end
point.
<http:inbound-endpoint exchange-pattern="request-response"
path="testPath" doc:name="HTTP"
host="localhost" port="8083"
mimeType="application/json"
method="PUT"/>
<logger level="INFO" message="method type #[message.inboundProperties['http.method']]"
doc:name="Logger"/> <--- It always logs method is GET
It never go into following expression block:
<choice doc:name="Choice">
<when expression="#[message.inboundProperties['http.method']=='PUT']">
I would like to set http method as a "PUT" in http inbound endpoint
The method attribute on http:inbound-endpoint is ineffective: you can put any value there, it won't change anything.
As Ale suggested, it's up to the HTTP client to use whatever method you want to receive on Mule's side.
Related
I've upgraded from Mule 3.3.x to 3.6.x and since the old http endpoint is deprecated in 3.6.x I wanted to migrate to the new HTTP connector.
Here is the original code for calling a webservice and healthcheck
Webservice
<http:outbound-endpoint connector-ref="NoSessionConnector"
address="${testmigrationapp.endpoint.url}"
responseTimeout="${testmigrationapp.endpoint.timeout}" keep-alive="true"
responseTransformer-refs="errorHandler">
<jms:transaction action="ALWAYS_JOIN"/>
Healthcheck
<http:inbound-endpoint exchange-pattern="request-response" address="${testmigrationapp.healthcheck.address}" doc:name="HTTP"/>
How would I implement this using the new HTTP connector?
Thanks
An HTTP outbound endpoint would translate to an HTTP request. You will need to define a request-config specifying the host, port and persistent connections (because of the keep-alive=true). Then you can replace the outbound endpoint with a request element specifying the URL path and the response timeout. For example:
<http:request-config name="persistentRequestConfig" usePersistentConnections="true" host="example.com" port="80" />
<flow name="persistent">
<http:request config-ref="persistentRequestConfig" path="/" responseTimeout="30" />
</flow>
An HTTP inbound endpoint would translate to an HTTP listener. You will need to define a listener-config specifying the host and port. Then you can replace the inbound endpoint for a listener element specifying the URL path. For example:
<http:listener-config name="listenerConfig" host="0.0.0.0" port="8081"/>
<flow name="testFlow">
<http:listener config-ref="listenerConfig" path="/"/>
<echo-component/>
</flow>
For more details you can checkout our docs regarding the migration.
I have an api developed and want to consume this api in a mule flow.
But when I test from chrome:postman I am getting the below error.
Message payload is of type: BufferInputStream
So I tried to log the message and below I got
org.glassfish.grizzly.utils.BufferInputStream#e2ed077
So basically my requirement is how can I pass json payload to my api. Below is my code snippet.
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8083" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8082" doc:name="HTTP Request Configuration">
<http:basic-authentication username="sa" password="sa"/>
</http:request-config>
<flow name="get-response-container-storeFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/testapi" doc:name="HTTP"/>
<logger message="******************Executed Test_Container_Store_API*******************#[payload]" level="INFO" doc:name="Logger"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/apie" method="POST" sendBodyMode="NEVER" doc:name="HTTP">
</http:request>
You can resolve the first "error" with the logger by addding a <object-to-string-transformer/> as the first message processor after your http:inbound (or more importantly, before your logger).
If you want to include the body in the request you should remove the sendBodyMode="NEVER" attribute from your request.
From the MuleSoft docs:
By default, the methods GET, HEAD and OPTIONS sends HTTP requests with an empty body, and the payload of the Mule message won’t be used at all. The rest of the methods sends the message payload as the body of the request. If you need to change this default behavior, you can specify the sendBodyMode attribute in the request, with one of the following possible values:
AUTO (default): The behavior depends on the method. Body is not sent for GET, OPTIONS and HEAD, and it is sent otherwise.
ALWAYS: The body is always sent.
NEVER: The body is never sent.
This means since you have this attribute set to never your payload will never be included as the request-body.
How to add Query parameter in mule HTTP Outbound Endpoint.
Without passing in path.
Thank You.
You can add the parameters in the outbound connector itself. you have the option to pass the hard coded data as well as MEL expressions are also allowed.
<http:request config-ref="HTTP_Request_Configuration" path="/post" method="POST" doc:name="outbound">
<http:request-builder>
<http:query-param paramName="q1" value="#[payload.input1]"/>
</http:request-builder>
</http:request>
Let's suppose you need to send the following url to Outbound endpoint which contains the following :- Query Parameter :-
http://localhost:8083/mule/?Item1=abc&Item2=efg
So,now as you said you don't need to pass the Query Parameter in url..
So in that case you can do the following :-
You can set the Query Parameter in Outbound Property using set-property just before the Outbound Endpoint as follow :-
<set-property propertyName="Item1" value="abc" doc:name="Property"/>
<set-property propertyName="Item2" value="efg" doc:name="Property"/>
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8083/mule/" doc:name="HTTP"/>
And you can simply pass http://localhost:8083/mule/ in Outbound endpoint address and the Query Parameter will be passed to external flow as an Outbound properties with message payload
Note: This is only incase of old HTTP outbound endpoint (Mule 3.5 or older), where query param are treated as outbbond properties
Hi I am working with Mule Any Point platform i am using composite source which is listening from HTTP and JMS both. I want to identify the incoming call coming from HTTP or JMS and i want to print using the logger. How to do that ?
Try the following way of using logger inside your endpoints.
<composite-source doc:name="Composite Source">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP">
<logger message="Request coming from HTTP endpoint."></logger>
<set-variable value="HTTP" variableName="myVar"></set-variable>
</http:inbound-endpoint>
<jms:inbound-endpoint doc:name="JMS" queue="in">
<logger message="Request coming from JMS endpoint."></logger>
<set-variable value="JMS" variableName="myVar"></set-variable>
</jms:inbound-endpoint>
</composite-source>
In the flow when you have to chekc a condition, you can use the flow variable "myVar" to check whether the message came from HTTP or JMS endpoint.
Hope this helps.
1st ESB App: HTTP Inbound Endpoint(request-response) -> javaComponent1 -> http outbound endpoint(request-response) -> JavaComponent2.
2nd ESB app: HTTP Inbound Endpoint(request-response) -> javacomponent3
In my case HTTP Inbound Endpoint(request-response) of 2nd ESB app sends the response back to the http outbound endpoint(request-response) of 1st ESB App.
My problem and query: HTTP Inbound Endpoint(request-response) of 2nd ESB app should send a java object as payload of the request that is being sent back to the http outbound endpoint(request-response) of 1st ESB App. The JavaComponent2 should be able to read the object received by the http outbound endpoint(request-response) of 1st ESB App and process it further.
How should I send my Java object from the http endpoint of the second app to the http outbound endpoint of the first app? I cannot use serialization here.
You can use object to bytearray transformer before sending the object from the 2nd Mule app . Then you use bytearray to Object transformer after the http outbound endpoint in the 1st mule app, while you are receiving the response from the 2nd mule app
First App
<flow name="test_serializableFlow1" doc:name="test_serializableFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" method="POST" doc:name="HTTP"/>
<logger message="Before transformer #[payload]" level="INFO" doc:name="Logger"/>
<byte-array-to-object-transformer doc:name="Byte Array to Object"/>
<logger message="After transformer #[payload]" level="INFO" doc:name="Logger"/>
</flow>
Second app
<flow name="ssFlow1" doc:name="ssFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<component class="Test" doc:name="Java"/>
<object-to-byte-array-transformer doc:name="Object to Byte Array"/>
</flow>