users@jersey.java.net

[Jersey] Mutil Consumes issue

From: tracy.b.hu <tracy.b.hu_at_gmail.com>
Date: Thu, 15 Nov 2012 19:10:32 +0800

Hi Dear,

First of all, sorry for my poor english. I will try to express my questions as possible as i can.

As we all know, we can define customizable Provider to deal with different Produces and Consumes. Such as, we expect to produces application/json. So we can define a provider class like this.

@Provider @Singleton
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public class JacksonEntityProvider extends JacksonJsonProvider {
.......
}

Also can be like that,
@Provider @Singleton
@Produces({ "application/json", "application/xml"})
@Consumes({ "application/json", "application/xml"})
public class JacksonEntityProvider extends JacksonJsonProvider {
.......
}

It works ok if request Content-Type like "application/json", "application/json; charset=utf8". But if the request Content-Type like "application/json; text/html; charset=UTF-8 ", it will throw a javax.ws.rs.WebApplicationException. Why? I have read Jersey source code, and found Jersey use "/" to seperate first media type from Content-Type, and use "=" to seperate others. That's why the "Caused by: java.text.ParseException: Expected separator '=' instead of '/'" exception occured. I know the second Content-Type is a bad one, but it's belong to request that out of my control.

I just wanna know, is there any way to deal with these requests by using Jersey? It's really made me down, any body can help me. Thanks advanced.




Thanks,
Henry Hu