users@jersey.java.net

Re: [Jersey] Accessing the Request's InputStream

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Fri, 17 Apr 2009 15:02:56 -0700

Christian Schneider 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?
>
I haven't tried it yet, but the JAX-RS spec (Section 4.2.4) implies that
you can just declare a method of type InputStream as a parameter, and
the JAX-RS implementation will use a provider to give you an input
stream for the request entity.

    public Response processLegacyInputData(InputStream stream) {
        ...
    }
> thx + Kind Regards,
> Chris
>
Craig