users@jersey.java.net

Re: invalid media type

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 25 Jan 2008 12:51:04 +0100

Hi Guilhem,

A media type of just 'matrix' is not a valid media type.

The BNF of a media type is [1]:

     media-type = type "/" subtype *( ";" parameter )
     type = token
     subtype = token

Where token is:

     token = 1*<any CHAR except CTLs or separators>

A media type of "application/matrix" is a valid media type.

What is happening is Jersey is validating the response, in this case the
Content-Type header set in the response of your HTTP method. I am
guessing you have done something like this:

    return Response.ok(entity, "matrix").build();

The aim is to try and catch errors before they propagate to the client.

BUT! we need to produce a better error message and throw the exception
closer to the source of the error, an issue is logged [2].

Paul.

[1] http://greenbytes.de/tech/webdav/rfc2616.html#media.types
[2] https://jersey.dev.java.net/issues/show_bug.cgi?id=35

legal wrote:
> hi!
>
> I don't understand why i'm getting an Invalid media type: matrix.
> does this apen when the matrix is malformed? or it contains utf-8
> character (I have some problem with that)?
>
> here is the stack trace provided by tomcat and I don't see where it is
> throw in my code :
>
>
> java.lang.IllegalArgumentException: Invalid media type: matrix
> javax.ws.rs.core.MediaType.parse(MediaType.java:60)
> com.sun.ws.rest.impl.model.HttpHelper.getContentType(HttpHelper.java:80)
> com.sun.ws.rest.impl.uri.rules.HttpMethodRule.verifyResponse(HttpMethodRule.java:196)
>
> com.sun.ws.rest.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:109)
>
> com.sun.ws.rest.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:55)
>
> com.sun.ws.rest.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:83)
>
> com.sun.ws.rest.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:49)
>
> com.sun.ws.rest.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:246)
>
> com.sun.ws.rest.spi.container.servlet.ServletContainer.service(ServletContainer.java:123)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>
> cause mère
>
> java.text.ParseException: End of header
> com.sun.ws.rest.impl.http.header.reader.HttpHeaderReaderImpl.getNextCharacter(HttpHeaderReaderImpl.java:175)
>
> com.sun.ws.rest.impl.http.header.reader.HttpHeaderReaderImpl.next(HttpHeaderReaderImpl.java:142)
>
> com.sun.ws.rest.impl.http.header.reader.HttpHeaderReader.nextSeparator(HttpHeaderReader.java:80)
>
> com.sun.ws.rest.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:66)
>
> com.sun.ws.rest.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:37)
>
> javax.ws.rs.core.MediaType.parse(MediaType.java:58)
> com.sun.ws.rest.impl.model.HttpHelper.getContentType(HttpHelper.java:80)
> com.sun.ws.rest.impl.uri.rules.HttpMethodRule.verifyResponse(HttpMethodRule.java:196)
>
> com.sun.ws.rest.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:109)
>
> com.sun.ws.rest.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:55)
>
> com.sun.ws.rest.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:83)
>
> com.sun.ws.rest.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:49)
>
> com.sun.ws.rest.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:246)
>
> com.sun.ws.rest.spi.container.servlet.ServletContainer.service(ServletContainer.java:123)
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> invalid media type
>
> Guilhem Legal
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109