users@jersey.java.net

Re: [Jersey] Accessing the Request's InputStream

From: Bryon Jacob <bryon_at_jacobtx.net>
Date: Fri, 17 Apr 2009 17:10:22 -0500

Assuming that you plan to consume the entire contents of the stream
into a String in memory anyways, why not just treat the request body
as a String?

@POST
@Path("/whatever")
public void postAString(String value) {
        System.out.println("the contents of the POST were : " + value);
}

Most of the examples you'll see assume that the request body is XML or
JSON or some such structured format, and so a Marshaller of some sort
is used to marshal it - but if you just want the String, you can just
do this.

I think you can also do this with an InputStream as well - but if
you're going to treat it as a String eventually anyways, that might be
the simpler solution.

good luck!

  - Bryon


On Apr 17, 2009, at 4:39 PM, 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?
>
> 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
>