(Bug?) entity for "" receives null mediaType when deployed on Tomcat

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

(Bug?) entity for "" receives null mediaType when deployed on Tomcat

Richard Hoberman
Hi

If I make a request using an empty string:

Request request = new Request(Method.POST, "http://localhost:8080/...");
request.getClientInfo().getAcceptedMediaTypes().add(new
Preference<MediaType>(MediaType.APPLICATION_JSON));
request.setEntity("", MediaType.APPLICATION_JSON);

my accept method will receive an entity with a null mediaType:

public void acceptRepresentation(Representation entity)    throws
ResourceException {
   
        MediaType mediaType = entity.getMediaType(); // will be null
     
        ....
}

Simply adding a space to the string (i.e. " ") results in the correct
media type.  This behaviour occurs when I deploy the application on
Tomcat, but not when run in standalone mode.

I've attached a bare-bones Tomcat webapp demonstrating this behaviour
and a test case showing that it does not occur when run in standalone mode.

From what I can make out, when the entity is "", getRequestHeaders is
returning 0 parameters at line 173 of  HttpServerCall (revision 3882)
but it is not clear to me where the underlying requestHeaders field is
being populated (or not being).
 
Regards

Richard Hoberman

emptyString.zip (24K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: (Bug?) entity for "" receives null mediaType when deployed on Tomcat

Rob Heittman
Thanks, Richard!  Can you share a Tomcat version number?  This sounds like the same issue we've been seeing in GWT hosted mode, and I've been trying to figure out where this is triggered in the Tomcat codebase so maybe we can work around it better.  GWT's embedded version is special enough and old enough that I'm never quite sure if I'm looking at Google's code or Apache Group's.

On Mon, Nov 17, 2008 at 4:49 AM, Richard Hoberman <[hidden email]> wrote:
Hi

If I make a request using an empty string:

Request request = new Request(Method.POST, "http://localhost:8080/...");
request.getClientInfo().getAcceptedMediaTypes().add(new
Preference<MediaType>(MediaType.APPLICATION_JSON));
request.setEntity("", MediaType.APPLICATION_JSON);

my accept method will receive an entity with a null mediaType:

public void acceptRepresentation(Representation entity)    throws
ResourceException {

       MediaType mediaType = entity.getMediaType(); // will be null

       ....
}

Simply adding a space to the string (i.e. " ") results in the correct
media type.  This behaviour occurs when I deploy the application on
Tomcat, but not when run in standalone mode.

I've attached a bare-bones Tomcat webapp demonstrating this behaviour
and a test case showing that it does not occur when run in standalone mode.

From what I can make out, when the entity is "", getRequestHeaders is
returning 0 parameters at line 173 of  HttpServerCall (revision 3882)
but it is not clear to me where the underlying requestHeaders field is
being populated (or not being).

Regards

Richard Hoberman

Reply | Threaded
Open this post in threaded view
|

Re: (Bug?) entity for "" receives null mediaType when deployed on Tomcat

Richard Hoberman
Hi Rob

I tested this against Tomcat-5.5.27.  The problem is also affecting code
running on 5.5.25.

Cheers

Richard

Rob Heittman wrote:
> Thanks, Richard!  Can you share a Tomcat version number?  This sounds
> like the same issue we've been seeing in GWT hosted mode, and I've
> been trying to figure out where this is triggered in the Tomcat
> codebase so maybe we can work around it better.  GWT's embedded
> version is special enough and old enough that I'm never quite sure if
> I'm looking at Google's code or Apache Group's.

Reply | Threaded
Open this post in threaded view
|

Re: (Bug?) entity for "" receives null mediaType when deployed on Tomcat

Rob Heittman
Thanks ...  Tomcat trunk didn't seem to have the same issue when I quick compiled it -- I'll start looking at 5.5.27 tag.  If you have counter evidence that shows trunk or 6.x with the same issue, let me know.

On Mon, Nov 17, 2008 at 8:10 AM, Richard Hoberman <[hidden email]> wrote:
Hi Rob

I tested this against Tomcat-5.5.27.  The problem is also affecting code
running on 5.5.25.

Cheers

Richard

Rob Heittman wrote:
> Thanks, Richard!  Can you share a Tomcat version number?  This sounds
> like the same issue we've been seeing in GWT hosted mode, and I've
> been trying to figure out where this is triggered in the Tomcat
> codebase so maybe we can work around it better.  GWT's embedded
> version is special enough and old enough that I'm never quite sure if
> I'm looking at Google's code or Apache Group's.