I'm not sure this is working very well yet.
– From my config file –
Global settings:
############
<http:connector name="myHTTP-Connector"
enableCookies="true" />
<message-properties-transformer name="delete-content-type-header" >
<delete-message-property key="Content-type" />
</message-properties-transformer>
<message-properties-transformer name="add-xml-content-type-header" >
<add-message-property key="Content-Type"
value="text/xml" />
</message-properties-transformer>
<!--
This transformer removes the "cookies:" header, which eliminates this error message in the logs:
org.apache.commons.httpclient.cookie.CookieSpec: Invalid cookie state: domain not specified
-->
<message-properties-transformer name="delete-cookies" >
<delete-message-property key="cookies" />
</message-properties-transformer>
###########################
The outbound endpoint that works:
###########################
<http://outbound-endpoint connector-ref="myHTTP-Connector"
address="http://my.server:9424"
method="POST"
transformer-refs="myPayload-To-XML delete-content-type-header add-xml-content-type-header delete-cookies"
responseTransformer-refs="parse_HTTP_Response"
remoteSync="true"
remoteSyncTimeout="10000" />
###########################
What the working output looks like:
###########################
$ netcat -l -p 9424
POST / HTTP/1.1
Content-Type: text/xml
X-MULE_CORRELATION_ID: a40fa210-cb90-11dd-bde1-bf0c7a580702
X-MULE_ENCODING: UTF-8
X-MULE_ENDPOINT: http://my.server:9424/
X-MULE_ORIGINATING_ENDPOINT: myServiceName
X-MULE_REMOTE_CLIENT_ADDRESS: /some.ip:54117
X-Cnection: close
http.method: POST
http.request: /
http.version: HTTP/1.1
method: POST
User-Agent: Jakarta Commons-HttpClient/3.1
Host: my.server:9424
Content-Length: 647
<?xml version="1.0" encoding="UTF-8"?> <!-- my xml -->
#################################
The outbound endpoint that doesn't work:
#################################
<http://outbound-endpoint connector-ref="myHTTP-Connector"
address="http://my.server:9424"
method="POST"
contentType="text/xml"
transformer-refs="myPayload-To-XML delete-cookies"
responseTransformer-refs="parse_HTTP_Response"
remoteSync="true"
remoteSyncTimeout="10000" />
###########################
What the broken output looks like:
###########################
$ netcat -l -p 9424
POST / HTTP/1.1
Content-Type: text/xml
Content-type: application/x-www-form-urlencoded
X-MULE_CORRELATION_ID: 459e952a-cb91-11dd-a9f1-cd2b2d1efe63
X-MULE_ENCODING: UTF-8
X-MULE_ENDPOINT: http://my.server:9424/
X-MULE_ORIGINATING_ENDPOINT: myServiceName
X-MULE_REMOTE_CLIENT_ADDRESS: /some.ip:54657
X-Cnection: close
http.method: POST
http.request: /
http.version: HTTP/1.1
method: POST
User-Agent: Jakarta Commons-HttpClient/3.1
Host: my.server:9424
Content-Length: 647
<?xml version="1.0" encoding="UTF-8"?> <!-- my xml -->
##################
As near as I can tell, the only difference between the two is the extra "Content-type" header.
For some reason, this breaks the remote service I'm using. (Which I have no control over nor visibility into.)
Things definitely appear better. The contentType attribute definitely sets a Content-Type header.
However it seems to add or leave an apparently unnecessary header, which is confusing the particular application I'm hitting.
I'll continue to use the header modifying transformers for now and not really worry about it too much. However I wanted to point out that the behaviour isn't exactly what was expected...
Hmm. Thinking about this a little more, Maybe that "Content-type: application---" header is getting set on the message at the INBOUND http endpoint (for my service). The header sticks around after a few transformations and some component processing, and ends up going out with the outbound HTTP endpoint. When I explicitly delete it, all is ok. The outbound endpoint isn't adding any extra headers, it is just passing along what was already there.
Yep, that was it. I installed the delete-content-type-header on my inbound endpoint, and it was no longer there on my outbound-endpoint.
So is that still a bug? Yes, I think so. You really should only have one content-type header. If you explicitly set it on the endpoint, it should wipe out any existing ones.
There was some funny bean parsing going on here. Now fixed: http://fisheye.codehaus.org/changelog/mule/?cs=13442