users@jersey.java.net

Re: [Jersey] problem to return/get? location during tests with jersey-test-framework-grizzly

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 20 May 2010 14:06:55 +0200

On May 20, 2010, at 12:41 PM, Frédéric Bouquet wrote:

> Hello list,
>
> I have a problem with my project.
> I have a resource which, when created answers the location in headers
> like it (myId contains the id of the created resource) :
>
> URI uri = URI.create(uriInfo.getAbsolutePath().toString() + "/" +
> myId);
> response = Response.created(uri).build();
>

> (If there's a better way to build the URI, I'm open to it :))
> It works when I deploy it with embedded-glassfish.
>

URI uri = uriInfo.getAbsolutePathBuilder().path(myId).build();

>

>
> When I want to unit test it with the test framework (grizzly).
> I post the resource like it :
>
> ClientResponse cr = webResource.header("Content-Type",
> "text/xml").post(ClientResponse.class, "<myxml... />");
>

ClientResponse cr = webResource.type("text/
xml").post(ClientResponse.class, ...);

> Then, I want to get back this resource using the header Location. I
> tryed to get :
> - cr.getLocation()
> - cr.getHeaders().getFirst("Location")
> But both return null.
>
> How can I GET the resource created and pointed by the header
> Location ?
>

The Location header should not be null if your resource method is
returning the Response instance you present above. Are you sure your
resource method is functioning correctly?

Can you enable server-side logging to see if the response contains the
location header?

See:

https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html

Paul.

>
> I use jersey 1.2.
> I deploy with maven-embedded-glassfish-plugin (1.2)
> I test with jersey-test-framework-grizzly (1.2). I have a bug with
> jersey-test-framework-embedded-glassfish and maybe maven (the same
> perhabs I've seen in the mailing list and bookstore example)
>
> The architecture is like it :
> - post http://domain.dln:port/project/resources : creates a resource
> - get http://domain.dln:port/project/resources/{id} : gets the
> resource with id {id}
>
> Thank you for your help,
>
> Fred
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>