1
votes

I'm new in MULE ESB, I have this code and i'm trying sending a http request using http:request with the following format:

"http: //www.host.com/api/commentThreads?key=val&part=val2&..."

    <file:inbound-endpoint  connector-ref="fileConnector" path="C:/tmp/input" 
                            doc:name="Reader File Configuration" responseTimeout="10000" 
                            encoding="UTF-8" mimeType="text/plain"
                            pollingFrequency="20000">
        <file:filename-wildcard-filter pattern="*.json"/>
    </file:inbound-endpoint>

    <json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>

    <logger level="INFO" message="#[payload]" doc:name="Logger" />

    <http:request config-ref="HTTP_Request_Configuration" path="/commentThreads" method="GET" port="443" doc:name="HTTP Request">
        <http:request-builder>
            <http:query-param paramName="key" value="#[message.payload.key]"/>
            <http:query-param paramName="allThreadsRelatedToChannelId" value="#[message.payload.allThreadsRelatedToChannelId]"/>
            <http:query-param paramName="part" value="#[message.payload.part]"/>
        </http:request-builder>
    </http:request>

But I'm having this error:

  • Message : Error sendinbut g HTTP request. Message payload is of type: LinkedHashMap
  • Code : MULE_ERROR--2

Exception stack is:

  1. null (java.util.concurrent.TimeoutException) org.glassfish.grizzly.impl.SafeFutureImpl$Sync:357 (null)
  2. Error sending HTTP request. Message payload is of type: LinkedHashMap (org.mule.api.MessagingException)
    org.mule.module.http.internal.request.DefaultHttpRequester:190 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)

The question is how can I do to make a http request with that format using the map?

According to documents

https://www.mulesoft.org/documentation/display/current/HTTP+Request+Connector#HTTPRequestConnector-HTTPRequestBody

The Mule Message payload is converted into a byte array and sent as the HTTP Request's body. This behavior is carried out always, except in the following scenarios:

The Mule Message's Payload is a Map of keys and values

Generate the Request Body with Content-Type:application/x-form-urlencoded

Whenever the message payload is a Map, the connector automatically generates an HTTP request with the header Content-Type:application/x-www-form-urlencoded. The keys and values of the map in the payload are converted into form parameter keys and values in the body of the HTTP request.

I suppose the map is converter automatically for the request. Correct me if I'm wrong

2

2 Answers

2
votes

It was necessary to make a transformation before the

<json: json-to-object-transformer returnClass = "java.util.Map" doc: name = "JSON to Object" />

It is corrected by putting

<byte-array-to-string-transformer doc: name = "Byte Array to String" />
0
votes

The error you're getting actually is not because your request has something wrong (or at least is not failing at that stage) but that your app is not being able to connect to the http server you're trying to send the request to. You can infer this by the exception you're getting java.util.concurrent.TimeoutException.

In order to troubleshoot please verify the host name and port are typed correctly.