在我的 Jersey Rest Service 中,我尝试创建一个实体标签:
String content = 12sdfs-345dsdfsdf-231yscysd;
String createdContent = create(content);
return Response.created(createdUri).entity(createdContent).build();
就像它写在球衣文档中一样。但是createdContent
是null
。怎么了?
完整的代码是:
@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;
}
编辑:
http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e188
第 2.5 章