users@jersey.java.net

Re: [Jersey] Content-Disposition

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 22 Jan 2009 15:13:16 +0100

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

> No can do. I have control over the interfaces, that I can annotate
> as I want, but not over the implementations. The implementations
> should be completly unaware of the infrastructure (Jersey +
> SpringIntegration).
>

Note that what i pointed to is JAX-RS specific. But in any case i
think i understand the constraints you are working with.


> Probably a "resource-specific filter" will work, if it filters not
> only the request but the response as well. However a much elegant
> solution will be a
>
> @ResponseHeaders("content-disposition","attachment;
> filename={name}.pdf", ....)
>
> That way my resource implementation can "intercept" that and add it
> to the ResponseBuilder.
>

See the classes

   com.sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory
    
com
.sun.jersey.server.impl.container.filter.AnnotationResourceFilterFactory

the javadoc in:

   com.sun.jersey.api.container.filter.

will help guide. You should be able to use UriInfo, injected into the
resource filter factory, to get the path parameter "name". My guess is
you might be able to reuse UriTemplate for the content disposition
value, but since it is not a URI you might run into issues.

Paul.

> Hmmm, I think I'll try this myself.
>
> Thanks for your very quick response :)
>
> On Jan 22, 2009 1:44pm, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> >
> >
> > 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
> >
> >
> >
> >
> ---------------------------------------------------------------------
> >
> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> >
> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >
> >
> >