HTTP入站端点从HTTP出站端点转发HTTP标头

时间:2014-02-05 17:02:43

标签: mule

早上好!

我正在使用Mule将输入转换为Web API并从Web API输出。我有以下流程:

<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>

Mule Studio中的输出是:

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

但是!当我使用Fiddler调用Mule时,Mule返回的标头包括出站调用返回的所有标头。具体来说,两个Set-Cookie和Content-Type。显然,我希望结果为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

问题:在这种情况下,如何将Content-Type作为application / xml?为了额外的功劳,我如何获得其他标题?

1 个答案:

答案 0 :(得分:0)

我无法重现此问题,您不需要使用属性转换器。我正在使用Mule Studio 3.5.0并使用Postman进行测试。如果您使用的是较旧的Mule版本,请尝试更新它并在Mule中记录Content-Type标题/消息。我测试了下面的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"/>

最后的记录器打印出text/xml;charset=ISO-8859-1,这也是返回给邮差的。