request.raw_post returns nil on Glassfish v3

We’ve recently moved some rails applications from Glassfish V2 (using warble) to Glassfish V3 running natively.  For the most part, this has been remarkably painless and things have “just worked”.

Code related to processing REST web services has not just worked and took quite a bit of investigation to fix so I’m documenting it here.

We process REST calls in rails by calling request.raw_post() on a POST or PUT request to return the XML payload and then doing some processing on it.  In Glassfish V2 and every other ruby implementation I tried, this just works fine.  In Glassfish V3, raw_post() was sometimes returning nil rather than the actual content of the http request.

After much investigation, we determined that if the incoming POST or PUT has a content type of “text/xml” then raw_post() will return the correct content.  If it has a different content type then raw_post() will return nil.  In our case we weren’t explicitly setting the content type and so it was failing.

Advertisement

2 Responses to request.raw_post returns nil on Glassfish v3

  1. How would you fix this if the content type is being sent in via an external vendor POST?

  2. It completely depends what technology you’re using to generate your POST. There’s always some way to set the Content-Type header.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s