users@jersey.java.net

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

From: Jan Algermissen <algermissen1971_at_mac.com>
Date: Wed, 07 Oct 2009 00:48:21 +0200

Paul, Marc,

thanks for all the in-depth answers!


> If you just need to set some headers and can do so outside the
> context of the StreamingOutput#write method then this should work:
>
> public StreamingOutput getResource(
> @PathParam("id") String id
> ) {
>
> StreamingOutput strOut = new StreamingOutput() {
> public void write(OutputStream outputStream) {
> PrintWriter out = new PrintWriter(outputStream);
> out.println("Foo");
> out.close();
> } };
> return Response.ok(strOut).header(a,b).header(c,d).build();
> }
>

Hmmm - I guess I can just implement StreamingOutput and do this:

> public Response getResource(
> @PathParam("id") String id
> ) {
>
> MyDomainObjectStreamer domainStreamer = new
> MyDomainObjectStreamer(-my special params go here-);

> return Response.ok(domainStreamer).header(a,b).header(c,d).build();
> }


Thanks!!

Jan



> Marc.