use of org.apache.zookeeper.server.jersey.jaxb.ZChildren in project zookeeper by apache.
the class ZNodeResource method getZNodeList.
private Response getZNodeList(boolean json, String path, String callback, String view, String dataformat, UriInfo ui) throws InterruptedException, KeeperException {
ensurePathNotNull(path);
if (view.equals("children")) {
List<String> children = new ArrayList<String>();
for (String child : zk.getChildren(path, false)) {
children.add(child);
}
Object child;
String childTemplate = ui.getAbsolutePath().toString();
if (!childTemplate.endsWith("/")) {
childTemplate += "/";
}
childTemplate += "{child}";
if (json) {
child = new ZChildrenJSON(path, ui.getAbsolutePath().toString(), childTemplate, children);
} else {
child = new ZChildren(path, ui.getAbsolutePath().toString(), childTemplate, children);
}
return Response.status(Response.Status.OK).entity(new JSONWithPadding(child, callback)).build();
} else {
Stat stat = new Stat();
byte[] data = zk.getData(path, false, stat);
byte[] data64;
String dataUtf8;
if (data == null) {
data64 = null;
dataUtf8 = null;
} else if (!dataformat.equals("utf8")) {
data64 = data;
dataUtf8 = null;
} else {
data64 = null;
dataUtf8 = new String(data);
}
ZStat zstat = new ZStat(path, ui.getAbsolutePath().toString(), data64, dataUtf8, 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();
}
}
use of org.apache.zookeeper.server.jersey.jaxb.ZChildren in project zookeeper by apache.
the class GetChildrenTest method testGetChildren.
@Test
public void testGetChildren() throws Exception {
if (expectedChildren != null) {
for (String child : expectedChildren) {
zk.create(expectedPath + "/" + child, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
}
ClientResponse cr = znodesr.path(path).queryParam("view", "children").accept(accept).get(ClientResponse.class);
Assert.assertEquals(expectedStatus, cr.getClientResponseStatus());
if (expectedChildren == null) {
return;
}
if (accept.equals(MediaType.APPLICATION_JSON)) {
ZChildrenJSON zchildren = cr.getEntity(ZChildrenJSON.class);
Collections.sort(expectedChildren);
Collections.sort(zchildren.children);
Assert.assertEquals(expectedChildren, zchildren.children);
Assert.assertEquals(znodesr.path(path).toString(), zchildren.uri);
Assert.assertEquals(znodesr.path(path).toString() + "/{child}", zchildren.child_uri_template);
} else if (accept.equals(MediaType.APPLICATION_XML)) {
ZChildren zchildren = cr.getEntity(ZChildren.class);
Collections.sort(expectedChildren);
Collections.sort(zchildren.children);
Assert.assertEquals(expectedChildren, zchildren.children);
Assert.assertEquals(znodesr.path(path).toString(), zchildren.uri);
Assert.assertEquals(znodesr.path(path).toString() + "/{child}", zchildren.child_uri_template);
} else {
Assert.fail("unknown accept type");
}
}
Aggregations