users@jersey.java.net

Re: [Jersey] Accessing the Request's InputStream

From: J Irving <j_at_lollyshouse.net>
Date: Fri, 17 Apr 2009 18:02:05 -0400

Hi Christian

According to the jax-rs 1.0 spec, section 3.3.2.1, you should be able
to get access to the entire body of the request via an entity
parameter:

---------------8<--------------
The value of a non-annotated parameter, called the entity parameter,
is mapped from the request entity body. Conversion between an entity
body and a Java type is the responsibility of an entity provider, see
section 4.2.

Resource methods MUST NOT have more than one parameter that is not
annotated with one of the above-listed annotations.
--------------8<----------------

Section 4.2.4 indicates that the implementation MUST include an entity
provider for InputStream, so in theory you should be able to do this:

   @POST
   public void post(InputStream is) {
       // etc
   }

I haven't actually tested this yet. Let me know if it works (or doesn't) :)

HTH
cheers, J

On Fri, Apr 17, 2009 at 17:39, Christian Schneider
<christian.schneider_at_itanius.com> wrote:
> Hello,
>
> I'm in the process of migrating a legacy REST-like web application towards a
> full REST-style app. Thereby I'd like to introduce Jersey as the RESTful
> framework. Unfortunately the legacy app handled a few form POSTs not using
> named form parameters, instead it simply received the posted data (a few
> KBytes long String) as the InputStream fetched via request.getInputStream().
>
> I can't address the POSTed data using the @FormParam annotation since I
> can't name that parameter. Is there any way to fetch the raw InputStream for
> legacy purposes? Using "@Context with a Request type" doesn't seem to do the
> job. Personally I believe that no JSR-311 compatible framework can provide
> access to the underlying stream since when these frameworks invoke the
> user's code the request parsing has already happened and the stream was
> emptied by parsing it into params and all that stuff.
>
> Am I right with this assumption or is there still some way to access the
> request's InputStream in Jersey?
>
> thx + Kind Regards,
> Chris
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>