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.
Related
Mule flow will receive multipart/form-data.
In the mule flow at runtime, I can see details of the multipart/form-data as attachments. When mule call the http request step in the flow to forward the multipart/form-data as is, mule seems to be not sending the incoming multipart/form-data.
In the log step prior to the http request,I can see all the attachments.
<flow name="impl-document:/upload">
<logger message="Received attachments: #[message.inboundAttachments.size()]"
level="INFO" doc:name="Attachments Qty" />
<foreach collection="#[message.inboundAttachments]" doc:name="For Each">
<logger
message="Attachment Key: #[key] -Key Value: #[message.payloadAs(java.lang.String)]"
level="INFO" doc:name="Logger" />
</foreach>
<set-payload value="#[null]" doc:name="Set Payload as null" />
<http:request config-ref="HTTP_Request_Configuration"
path="nodes/upload" method="POST" doc:name="call to upload document">
</http:request>
</flow>
When I enhanced the log levels to track the http details, I see the content-length as -1
Content-Length: -1
I tried a few options like setting the content-type as Multipart/form but does not seems to be working. Any thoughts what I am missing in my flow would be really great.
You need to copy the inbound attachments as outbound ones in order for the HTTP request to consider them and generate a multipart request. HTH
I am trying to pass the multiple URI params in the http request as follows:
<http:listener-config name="HTTP_Listener_Configuration"
host="localhost" port="8081" doc:name="HTTP Listener Configuration"
connectionIdleTimeout="40000" />
<http:request-config name="HTTP_Request_Configuration1" protocol="HTTPS" host="" port="443" doc:name="HTTP Request Configuration" connectionIdleTimeout="300000" responseTimeout="50000">
<http:basic-authentication username="user" password="123"/>
</http:request-config>
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/paypal" allowedMethods="GET" doc:name="HTTP" />
<set-variable variableName="config" value="#[{'p1':'3054', 'p2':'child/Lines'}]" doc:name="Variable"/>
<http:request config-ref="HTTP_Request_Configuration1" path="/resources/shipment/{p1}/{p2}" method="GET" doc:name="HTTP">
<http:request-builder>
<http:uri-params expression="#[flowVars.config]"/>
</http:request-builder>
</http:request>
</flow>
But this is giving me error as below:
Response code 404 mapped as failure.
ERROR 2019-01-04 18:46:34,526
[[paypaltest].HTTP_Listener_Configuration.worker.01]
org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Response code 404 mapped as failure.
Payload : org.glassfish.grizzly.utils.BufferInputStream#b473ec2
Element : /testFlow/processors/1 # test:test.xml:29 (HTTP)
Element XML : <http:request config-ref="HTTP_Request_Configuration1" path="/resources/shipments/{p1}/{p2}" method="GET" doc:name="HTTP">
<http:request-builder>
<http:uri-params expression="#[flowVars.config]"></http:uri-params>
</http:request-builder>
</http:request>
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.module.http.internal.request.ResponseValidatorException: Response code 404 mapped as failure.
Please let me know if any help can be provide!
It means that the url doesn't exist. Try to hit the url directly in postman before implementing in Mule. Since you wiped out the host="", I'll pretend it's example.com. My guess is that it's having an issue with p2. If you'd like to send the actual string, you'll need to URL encode the "/", which is %2F
So to test hit https://www.example.com/resources/shipments/3054/child%2FLines, with the Basic Auth for Authorization.
Postman: https://www.getpostman.com/apps
The issue i faced was unique to me, i tried this REST api call from SOAPUI and there it gave me the same error i.e. 404 not found so i compared it with POSTMAN request and found that Authorization header was the missing piece for this.
After adding this to http header it worked perfectly.
Please refer
https://docs.mulesoft.com/connectors/http/http-authentication
here are two solutions :
1. Add preemptive="true" in basic authentication configuration
The pre-emptive option passes the user name and password without waiting for a prompt from the server.
Add Authorization in the http:header value ="Basic dXNlcjoxMjM="
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.
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.
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>