简体   繁体   中英

mule esb outbound https invalid content-type

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.

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM