Hi,
On 29/12/11 00:26, Jeff Wang wrote:
I have a resource and a sub resource...

@Path(/user)
@Service
public UserServiceImpl {

     @Path("{userId}/contact")
     public IContactService getContactService(@PathParam("userId") Long userId);
}

@Service
public ContactServiceImpl {
     @POST
     public Response addContact(Long userId, Contact contact) {
         .... Bunch of code ....
                try {
                        return Response.status(Response.Status.CREATED)
                                        .location(new URI("" + 
contact.getId())).build();
                } catch (URISyntaxException e) {
                        throw new CreateException(e.getMessage());
                }
     }
}

However, the returned URI is:
http://localhost:8080/myApp/6

while a similar Add user returns
http://localhost:8080/myApp/user/1

It seems that the relative URI does not account for the pathing
implicit in a sub resource call?  Should I use URIInfo to build all my
URI location for sub resources/

Looks like so, ResponseBuilder.location() javaDocs do require that the relative URI is resolved against a base URI. It seems a bit unfortunate actually in this case, so you'd need to pass UriInfo to the subresource and use it UriInfo.getAbsolutePathBuilder

Cheers, Sergey

Jeff


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to