I've written a little test like you and it works too. The problem
happens when I use spring in the resource. I should have miss something,
I need to investigate more
thanks,
Jean.
Paul Sandoz wrote:
> The code at the end of the email runs without error for me.
>
> Paul.
>
> import com.sun.jersey.api.client.Client;
> import com.sun.jersey.api.client.WebResource;
> import com.sun.jersey.api.container.httpserver.HttpServerFactory;
> import com.sun.net.httpserver.HttpServer;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.ProduceMime;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.HttpHeaders;
>
> public class Main {
> @Path("/")
> public static class R {
>
> @ProduceMime({"application/xml", "application/json"})
> @GET
> public String get(@Context HttpHeaders h) {
> return h.getAcceptableMediaTypes().get(0).toString();
> }
> }
>
> public static void client() throws Exception {
> Client c = Client.create();
> WebResource r = c.resource("http://localhost:9999/");
>
> assertEquals("application/json",
> r.accept("application/json").get(String.class));
> assertEquals("application/xml",
> r.accept("application/xml").get(String.class));
> assertEquals("application/json",
> r.accept("application/xml;q=0.8", "application/json").get(String.class));
> assertEquals("application/xml", r.accept("application/xml",
> "application/json;q=0.8").get(String.class));
> }
>
> public static void assertEquals(Object o1, Object o2) {
> if (!o1.equals(o2)) throw new RuntimeException();
> }
>
> public static void main(String[] args) throws Exception {
> HttpServer s =
> HttpServerFactory.create("http://localhost:9999/");
> s.start();
>
> try {
> client();
> } finally {
> s.stop(0);
> }
> }
> }
>
> Paul Sandoz wrote:
>> Can you provide an example for me to verify against?
>>
>> Thanks
>> Paul.
>>
>> Jean Aurambault wrote:
>>> Hi,
>>>
>>> I try to use the 0.8 version.
>>> Do you have noticed any problem with Accept header? In my case, it
>>> sounds like Accept header stays at application/xml even if you send
>>> another type defined in the resource (eg. application/json).
>>>
>>> @Context
>>> private HttpHeaders httpHeaders;
>>>
>>> I use httpHeaders.getAcceptableMediaTypes().get(0) to get the first
>>> Acceptable type.
>>> Do I miss something?
>>>
>>> Jean.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>