Search in sources :

Example 6 with ZError

use of org.apache.zookeeper.server.jersey.jaxb.ZError in project zookeeper by apache.

the class ZNodeResource method setZNode.

@PUT
@Produces({ MediaType.APPLICATION_JSON, "application/javascript", MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response setZNode(@PathParam("path") String path, @QueryParam("callback") String callback, @DefaultValue("-1") @QueryParam("version") String versionParam, @DefaultValue("base64") @QueryParam("dataformat") String dataformat, @DefaultValue("false") @QueryParam("null") String setNull, @Context UriInfo ui, byte[] data) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);
    int version;
    try {
        version = Integer.parseInt(versionParam);
    } catch (NumberFormatException e) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
    }
    if (setNull.equals("true")) {
        data = null;
    }
    Stat stat = zk.setData(path, data, version);
    ZStat zstat = new ZStat(path, ui.getAbsolutePath().toString(), null, null, stat.getCzxid(), stat.getMzxid(), stat.getCtime(), stat.getMtime(), stat.getVersion(), stat.getCversion(), stat.getAversion(), stat.getEphemeralOwner(), stat.getDataLength(), stat.getNumChildren(), stat.getPzxid());
    return Response.status(Response.Status.OK).entity(new JSONWithPadding(zstat, callback)).build();
}
Also used : JSONWithPadding(com.sun.jersey.api.json.JSONWithPadding) Stat(org.apache.zookeeper.data.Stat) ZStat(org.apache.zookeeper.server.jersey.jaxb.ZStat) WebApplicationException(javax.ws.rs.WebApplicationException) ZStat(org.apache.zookeeper.server.jersey.jaxb.ZStat) ZError(org.apache.zookeeper.server.jersey.jaxb.ZError) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Produces (javax.ws.rs.Produces)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 ZError (org.apache.zookeeper.server.jersey.jaxb.ZError)6 Consumes (javax.ws.rs.Consumes)4 JSONWithPadding (com.sun.jersey.api.json.JSONWithPadding)3 URI (java.net.URI)3 POST (javax.ws.rs.POST)3 PUT (javax.ws.rs.PUT)2 CreateMode (org.apache.zookeeper.CreateMode)2 ZPath (org.apache.zookeeper.server.jersey.jaxb.ZPath)2 IOException (java.io.IOException)1 DELETE (javax.ws.rs.DELETE)1 Stat (org.apache.zookeeper.data.Stat)1 ZSession (org.apache.zookeeper.server.jersey.jaxb.ZSession)1 ZStat (org.apache.zookeeper.server.jersey.jaxb.ZStat)1