variable from parameter @PUT in web service correct?
Is this correct?
I want to get variable from @PUT method parameter in REST web service.
But I get the variable "Null" , how to get parameter?
Could anyone tell me?
@PUT
@Produces("application/html")
public Response postContainer(@PathParam("objecturi")String path){
mongoDAOImpl impl=new mongoDAOImpl();
Mongo mongo=impl.getConnection("127.0.0.1","27017");
DB db=impl.getDataBase(mongo,"public");
DBCollection coll=impl.getColl(db,"public");
mongoDTO dto=new mongoDTO();
dto.setParentpath("/home/public/liren");
dto.setUserName("liren");
dto.setPassWord("liren"开发者_StackOverflow中文版);
dto.setFileName(path);
dto.setAbsolutepath(dto.getParentpath()+"/"+dto.getFileName());
boolean bool;
try{
file= new filemethods();
bool=file.createcontainers(coll, dto, path);
if(bool==true){
return Response.status(Response.Status.OK).build();
}else {
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
}catch(Exception ex){
return Response.status(Response.Status.BAD_REQUEST).tag("Container create error"+ex.toString()).build();
}
Is your method parameter an http parameter like /uri?objecturi=/some/path? Then you have to use @QueryParam("objecturi") instead of @PathParam("objecturi").
What do you have in your @Path
annotation?
Basically if you want your code to work, you must have something like @Path("/url/{objecturi}")
For HTTP PUT-method you need to use form parameters with "application/x-www-form-urlencoded" MIME-type of your HTTP Header and @QueryParam annotation.
@PUT
@Produces("application/html")
@Consumes("application/x-www-form-urlencoded")
public Response postContainer(@QueryParam("objecturi")String path){
...
}
Hope this helps.
精彩评论