0
votes

I am using Mule 3.4.0 and am making a flow that calls some RESTful API endpoints on a JIRA server using an HTTPS outbound endpoint. I am having a problem because Mule is for some reason sending a Content-Type header value that causes an exception in JIRA. It looks like, judging from the JIRA stack trace, that Mule is sending this:

application/json, application/json;charset=UTF-8

JIRA is using Jersey and Jersey is unable to parse that Content-Type value. Here is a portion of the stack trace returned by JIRA:

Caused by: java.lang.IllegalArgumentException: Error parsing media type 'application/json, application/json;charset=UTF-8' at com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:79) at com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:53) at javax.ws.rs.core.MediaType.valueOf(MediaType.java:119) at com.sun.jersey.server.impl.model.HttpHelper.getContentType(HttpHelper.java:89) ... 157 more Caused by: java.text.ParseException: Expected separator ';' instead of ',' at com.sun.jersey.core.header.reader.HttpHeaderReader.nextSeparator(HttpHeaderReader.java:117) at com.sun.jersey.core.header.reader.HttpHeaderReader.readParameters(HttpHeaderReader.java:239) at com.sun.jersey.core.impl.provider.header.MediaTypeProvider.valueOf(MediaTypeProvider.java:97) at com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:77)

I would like to be able to force a specific Content-Type value to be sent, but I can't figure out how to do that. It seems like Mule automatically builds the Content-Type value based on a combination of factors:

http://www.mulesoft.org/documentation/display/current/HTTP+Transport+Reference

If the endpoint has encoding set explicitly, use that Otherwise, take it from the message's property Content-Type If none of these is set, use the Mule Context's configuration default. For Content-Type, send the message's property Content-Type but with the actual encoding set.

So I think it's using the inbound property Content-Type, but since that's an inbound property I don't think I can modify/delete that in the flow. My attempts to modify/delete the Content-Type property have been ineffective. I can only modify/delete the outbound Content-Type property, which doesn't seem to help with my outbound HTTP request.

Any info on how to control the Content-Type value or fix it or something would be appreciated.

1
What type of payload receives the service? (xml or json). You can set the content type, for example: <set-property propertyName="Content-Type" value="text/xml" doc:name="Property" /> show the flow to help. - Julio Cejas
Thanks for your question. My flow setup is bit complicated. I'm going to have a cron job that hits a flow with an HTTP inbound endpoint. This flow will generate events that it will publish to an outbound VM endpoint. A second flow has the inbound VM endpoint to receive the events, and this second flow is the one making the POSTs to JIRA's API using HTTPS outbound endpoints. If I set the Content-Type property like that before the HTTPS outbound endpoint, should that cause that Content-Type value to be the one that request uses? I think I tried that and it didn't work but I can try it again. - sdouglass
This error usually occurs when the Content-Type is invalid. I recommend using POSTMAN Rest Client to validate REST service. - Julio Cejas
I found a solution, though I still don't understand why the problem was happening. See my answer below. Thanks for your comments. - sdouglass

1 Answers

0
votes

I spent some more time using debugging and breakpoints and discovered that, after the first HTTPS outbound endpoint, a "Content-Type" variable (NOT an inbound or outbound property) was being set, to "application/json". I have no idea why that was happening. I didn't see anything in the docs about that, either for HTTP Transport or HTTP Endpoint. If anybody can point out documentation around what is going on there that would be great.

As an experiment, before my next HTTPS outbound endpoint, I added a Variable transformer to delete the "Content-Type" variable. That fixed the problem!

So it seems like Mule was for some reason combining the "Content-Type" variable with the Content-Type value that I was specifying in the HTTP outbound endpoint, resulting in "application/json, application/json; charset=UTF-8".

I wound up having to put this after every HTTPS outbound endpoint to keep deleting the variable: