See comments inline,

On 24/07/12 22:29, Sergey Beryozkin wrote:
On 24/07/12 21:58, bcarlson wrote:
Well, I found the issue, using RESTClient... the Content-Type of the
response
was "text". Not "text/plain" or something valid, just the word "text".

So, the next question is, how can I force WebClient to ignore this issue?

At the moment, the best workaround is to register a custom CXF in
interceptor on the client side, which would replace 'text' with
'text/plain', for example,

public class ReplaceContentTypeInterceptor extends
AbstractPhaseInterceptor<Message> {
public ReplaceContentTypeInterceptor() {
this(Phase.READ);
}

public void handleMessage(Message message) throws Fault {
message.put(Message.CONTENT_TYPE, "text/plain");
}

I'm adding a test and the example code above is not working, the following will do:

Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
headers.put(Message.CONTENT_TYPE, Collections.singletonList("text/plain"));

}

WebClient needs to be created directly with JAXRSClientFactoryBean:

JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
bean.getInInterceptors().add(new ReplaceContentTypeInterceptor());
bean.createWebClient();


Actually, you can avoid going to the bean-centric code,
WebClient wc = WebClient.create(address);
WebClient.getConfig(wc).getInInterceptors().add(new ReplaceContentTypeInterceptor());

will do too.

I've also added an "org.apache.cxf.jaxrs.mediaTypeCheck.strict" boolean property, disabled by default. It's only effective at the moment at the server side, due to the fact WebClient calculates the response media types after the inbound chain has completed - which may need to be reviewed,

Cheers, Sergey

that should do it.
In meantime I'll relax the check, the strict mode will be optionally
enabled, but by default a lax mode will be in action, where a '*'
subtype will be added to values like '*' or 'text', etc. Technically,
'text' is wrong, but the code has to be more tolerable by default

Cheers, Sergey

-Ben



--
View this message in context:
http://cxf.547215.n5.nabble.com/Media-type-separator-is-missing-how-to-troubleshoot-tp5711524p5711547.html

Sent from the cxf-user mailing list archive at Nabble.com.


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to