users@jersey.java.net

Re: [Jersey] Content-Disposition

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 22 Jan 2009 14:44:41 +0100

On Jan 22, 2009, at 2:36 PM, amsmota_at_gmail.com wrote:

> Hello again.
>
> I have a situation here where I have to set a Content-Disposition
> header in my response and I was hoping that I can do that at a
> annotation, or configuration, level.
>
> @GET
> @Path("/reports/{name}")
> @Produces("application/pdf")
> @SOMEANNOTATION(""content-disposition","attachment;
> filename={name}.pdf"
> byte[] executePdf(@PathParam("name")String name)
>
> Would that be possible?
>
> Of course I can do it programatically in my HttpConector, but that
> will break the "abstractioness" of my infrastructure...
>

You can use the Response [1] builder:

   @GET
   @Path("/reports/{name}")
   @Produces("application/pdf")
   public byte[] executePdf(@PathParam("name")String name) {
     byte[] stuff = ...
     return Response.ok(stuff).header("Content-Disposition": "....");
   }


An alternative is to use the new resource-specific filter framework i
have recently integrated. However, i have not sent any email about
that yet because there is currently an issue with the pushing of built
artifacts to the maven repo so developers would have to build the
source to try it out.

Paul.

[1] https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/core/Response.html
      https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/core/Response.ResponseBuilder.html