users@jersey.java.net

Re: [Jersey] MultivaluedMap

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 10 Oct 2008 10:01:54 +0200

HI Alex,

Are you writing unit tests for your MessageBodyWriter implementation?

A multivalued map is created when you build a response and return it
from a resource method:

   return Response.ok(file).type("application/xml").
      header("Content-Disposition", "attachment; filename=ws_xml.xml").
      build();

The Response class has a method [1] to obtain the multivalued map for
the response headers.


Note that you can also modify and add http headers in a
MessageBodyWriter because the map of response headers is passed in as
a parameter. The headers will be committed when the first byte that is
written to the output stream.

Paul.

[1] https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/core/Response.html
#getMetadata()


On Oct 10, 2008, at 6:18 AM, alex hendry wrote:

> Hi all,
>
> I am using Jersey to create some web services. I have a class that
> implements MessageBodyWriter and I need to create a multivaluedMap
> so I can add a header as follows to pass to the writeTo method.
>
> MultivaluedMap<java.lang.String,java.lang.Object> httpHeaders
>
> httpHeaders.add("Content-Disposition", "attachment;
> filename=test.xml");
>
> How ever in the api under multivaluedMap there is nothing listed
> that implements multivaluedMap that I can instantiate.
>
> I have looked at the UriInfo class getPathParameterc method and the
> HttpHeaders getRequestHeaders method that return a MultivaluedMap
> but I am unsure of how to use them.
>
> Any help would be much appreciated.
>
> Cheers,
>
> Alex
>
> Make the switch to the world's best email. Get Yahoo!7 Mail.