In my Jersey Rest Service i tried to create an entity tag with:
String content = 12sdfs-345dsdfsdf-231yscysd;
String createdContent = create(content);
return Response.created(createdUri).entity(createdContent).build();
like its written in the jersey documentation. But createdContent is null. Whats wrong?
The full code is:
@POST
@Consumes("application/x-www-form-urlencoded")
public Response postObject(@FormParam("number") int number) {
ObjectDTO c = new ObjectDTO();;
c.setNumber(number);
String generatedId = generateID();
c.setId(generatedId);
c.setOwner(sec.getUserPrincipal().getName());
return postAndGetResponse(c);
}
private Response postAndGetResponse(ObjectDTO object) {
Response res;
System.out.println(object);
if(ObjectDAO.instance.getObjectDao().containsKey(object.getId())) {
res = Response.serverError().status(409).build();
} else {
System.out.println(object);
System.out.println(object.getId());
String createdContent = create(object.getId());
System.out.println(createdContent);
res = Response.created(uriInfo.getAbsolutePath()).entity(createdContent).build();
ObjectDAO.instance.getObjectDao().put(object.getId(), object);
}
return res;
}
edit:
http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e188
chapter 2.5
To create an entity tag simply call
new EntityTag(string). But what are you trying to achieve in the code above? The entity tag should be attached to the header, not to the body.