users@jersey.java.net

Re: [Jersey] Accessing the response object (in standard JSR311)

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 06 Oct 2009 10:19:45 +0200

On Oct 5, 2009, at 7:23 PM, Jan Algermissen wrote:

>
> Given that HttpContext is a Jersey 'extension' - how would one
> access the response object if not using the ResponseBuilder pattern?
>
> E.g. if I had
>
> public StreamingOutput getResource(
> final @Context HttpContext hc, // Jersey
> specific class
> @PathParam("id") String id
> ) {
> return new StreamingOutput() {
> public void write(OutputStream outputStream) {
> Response resp = hc.getResponse();
> // do something with response, e.g. set headers
>
> PrintWriter out = new PrintWriter(outputStream);
> out.println("Foo");
> out.close();
> } };
> }
>
>
> How could I avoid the Jersey specific class?
>

It is currently not possible. If one needs to do that then a message
body writer can be used. For example you could write your own version
of StreamingOutput and your own message body writer that supports the
setting of headers e.g.

   public MyStreamingOutput {
     write(MultivaluedMap headers, OutputStream out);
   }


> Thanks,
>
> Jan
>
> P.S. Is there actually a better list to use for these kinds of
> questions? Seems so quiet over here...
>

What are you using to monitor the list? (BTW the reason why i CC you
is because you are not a member of the list so i CC just in case you
are not monitoring by other means, also the list is moderated so i
have to approve each email you send, which is why there might be the
occasional delay).

So far this month there have been 87 emails.

See the archive:

   http://markmail.org/search/?q=list%3Anet.java.dev.jersey.users

Paul.