I have a simple Camel TypeConverter that converts my Java objects to JSON and returns that JSON as an InputStream. This is for transmitting instances of my Java objects over HTTP.
This works fine, but the problem is that I also want the converter to also set the Content-Type on the Exchange so that any subsequent HTTP response objects will pick up that changed content-type (e.g. I want the HTTP content-type to be set to 'Content-Type: application/json; format=MyObjectFormat'). But the problem is that my TypeConverter is invoked *after* the HTTP response object has already had it's response-code and content-type set from the Exchange. So even though my TypeConverter does receive the Exchange as a parameter (and so I can easily set the appropriate Content-Type header on that Exchange instance), it's *too late* to affect the content-type of the actual HTTP response that is sent on the wire. The relevant method is 'void doWriteResponse(...)' in class 'org.apache.camel.component.http.DefaultHttpBinding'. It's clear to see it setting the response-code, then the content-type, and *then* setting the response body via type converters if needed (i.e. the call to 'doWriteDirectResponse()'). It would seem trivial to move the call to write the response body *before* setting the response-code and content-type from the Exchange (thereby allowing the type converter to alter them as needed). I know I can manually set the content-type in my Camel route, but that's clunky and it seems so much neater for the converter to be able to set the Content-Type header to match the conversion it's applying, since they are so tightly inter-related. But maybe I'm missing something here...? Cheers, Pat. -- View this message in context: http://camel.465427.n5.nabble.com/Can-should-a-TypeConverter-set-the-Content-Type-tp5756013.html Sent from the Camel - Users mailing list archive at Nabble.com.