1
votes

Good morning!

I'm using Mule to transform the input into and output from a Web API. I've got the following flow:

<http:inbound-endpoint exchange-pattern="request-response" host="${webapi.host.server}" port="${webapi.host.port}" path="${webapi.getData.host.data.path}" doc:name="Incoming Requet" contentType="text/xml" mimeType="text/xml"/>
<message-properties-transformer doc:name="Message Properties">
    <add-message-property key="Accept" value="application/json"/>
</message-properties-transformer>
<set-payload value="{ SortBy: &quot;LastModificationTimestamp&quot;, FirstResult: 1, ResultsToRetrieve: #[message.inboundProperties[&quot;count&quot;] ==null ? &quot;10&quot; : message.inboundProperties[&quot;count&quot;]] }" doc:name="Set FO Input (JSON)"/>
<http:outbound-endpoint exchange-pattern="request-response" host="${dataSource.host.server}" port="${dataSource.host.port}" method="POST" doc:name="HTTP" contentType="application/json" password="${dataSource.host.password}" path="${dataSource.host.dataSource.path}" user="${dataSourceities.host.user}" responseTimeout="${dataSourceities.host.responseTimeout}"/>
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
<expression-component  doc:name="Expression">message.payload = message.payload.Results</expression-component>
<jdbc-ee:maps-to-xml-transformer doc:name="Maps to XML" mimeType="text/xml"/>
<message-properties-transformer doc:name="Message Properties" scope="outbound">
    <delete-message-property key="Content-Type"/>
    <delete-message-property key="Set-Cookie"/>
</message-properties-transformer>
<message-properties-transformer doc:name="Message Properties" scope="outbound">
    <add-message-property key="Content-Type" value="application/xml"/>
</message-properties-transformer>

The output in Mule Studio is:

INFO  2014-02-05 11:54:08,755 [[sbrowebsite].connector.http.mule.default.receiver.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO  2014-02-05 11:54:08,758 [[sbrowebsite].connector.http.mule.default.receiver.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default response transformer: org.mule.transport.http.transformers.MuleMessageToHttpResponse
INFO  2014-02-05 11:54:08,758 [[sbrowebsite].connector.http.mule.default.receiver.02] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO  2014-02-05 11:54:08,758 [[sbrowebsite].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.http.mule.default.dispatcher.2045317914'. Object is: HttpClientMessageDispatcher
INFO  2014-02-05 11:54:08,760 [[sbrowebsite].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.http.mule.default.dispatcher.2045317914'. Object is: HttpClientMessageDispatcher
INFO  2014-02-05 11:54:08,771 [[sbrowebsite].connector.http.mule.default.receiver.02] org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest: Content-Type not set on outgoing request, defaulting to: text/plain

But! When I invoke Mule using Fiddler, the headers returned by Mule include all of those returned by the outbound call. Specifically, the two Set-Cookie and Content-Type. Obviously, I want the result to be application/xml.

HTTP/1.1 200 OK
Date: Wed, 05 Feb 2014 11:54:13 -0500
Server: Mule EE Core Extensions/3.4.0
Set-Cookie: Some-Cookie-From-the-Original-Web-API=chocolate-chip; Domain=localhost; Path=/
Set-Cookie: Other-Cookie-From-the-Original-Web-API=oatmeal-raisin; Domain=localhost; Path=/; Expires=Fri, 7-Feb-2014 16:54:08 GMT
Content-Type: application/json
X-MULE_SESSION: big-long-string
X-MULE_ENCODING: utf-8
Content-Length: 86952
Connection: close

Question: How do I get the Content-Type to be application/xml in this case? And for extra credit, how do I get those other headers out?

1

1 Answers

0
votes

I fail to reproduce this problem, and you should not need to use the property transformers. I am using Mule Studio 3.5.0 and testing with Postman. If you are using an older Mule version, try to update it and log the Content-Type header / message in Mule. I tested with the following conf:

<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" path="test" doc:name="HTTP"/>
<message-properties-transformer doc:name="Message Properties">
   <add-message-property key="Accept" value="application/json"/>
</message-properties-transformer>
<http:outbound-endpoint exchange-pattern="request-response" host="echo.jsontest.com" port="80" contentType="application/json" path="key/value/one/two" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
<jdbc-ee:maps-to-xml-transformer doc:name="Maps to XML" mimeType="text/xml"/>
<logger message="#[header:OUTBOUND:Content-Type]" level="INFO" doc:name="Logger"/>

The Logger in the end prints out text/xml;charset=ISO-8859-1 and that is what is also returned to Postman.