use of com.sun.jersey.api.client.WebResource.Builder in project zookeeper by apache.
the class SessionTest method createSession.
private ZSession createSession(String expire) {
WebResource wr = sessionsr.queryParam("op", "create").queryParam("expire", expire);
Builder b = wr.accept(MediaType.APPLICATION_JSON);
ClientResponse cr = b.post(ClientResponse.class, null);
Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());
return cr.getEntity(ZSession.class);
}
use of com.sun.jersey.api.client.WebResource.Builder in project zookeeper by apache.
the class SessionTest method testSendHeartbeat.
@Test
public void testSendHeartbeat() throws InterruptedException {
ZSession session = createSession("2");
Thread.sleep(1000);
WebResource wr = sessionsr.path(session.id);
Builder b = wr.accept(MediaType.APPLICATION_JSON);
ClientResponse cr = b.put(ClientResponse.class, null);
Assert.assertEquals(ClientResponse.Status.OK, cr.getClientResponseStatus());
Thread.sleep(1500);
Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
Thread.sleep(1000);
Assert.assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
}
use of com.sun.jersey.api.client.WebResource.Builder in project zookeeper by apache.
the class CreateTest method testCreate.
@Test
public void testCreate() throws Exception {
WebResource wr = znodesr.path(path).queryParam("dataformat", encoding).queryParam("name", name);
if (data == null) {
wr = wr.queryParam("null", "true");
}
if (sequence) {
wr = wr.queryParam("sequence", "true");
}
Builder builder = wr.accept(accept);
ClientResponse cr;
if (data == null) {
cr = builder.post(ClientResponse.class);
} else {
cr = builder.post(ClientResponse.class, data);
}
Assert.assertEquals(expectedStatus, cr.getClientResponseStatus());
if (expectedPath == null) {
return;
}
ZPath zpath = cr.getEntity(ZPath.class);
if (sequence) {
Assert.assertTrue(zpath.path.startsWith(expectedPath.path));
Assert.assertTrue(zpath.uri.startsWith(znodesr.path(path).toString()));
} else {
Assert.assertEquals(expectedPath, zpath);
Assert.assertEquals(znodesr.path(path).toString(), zpath.uri);
}
// use out-of-band method to verify
byte[] data = zk.getData(zpath.path, false, new Stat());
if (data == null && this.data == null) {
return;
} else if (data == null || this.data == null) {
Assert.assertEquals(data, this.data);
} else {
Assert.assertTrue(new String(data) + " == " + new String(this.data), Arrays.equals(data, this.data));
}
}
use of com.sun.jersey.api.client.WebResource.Builder in project neo4j-documentation by neo4j.
the class RestRequest method builder.
private Builder builder(String path, final MediaType accept) {
WebResource resource = client.resource(uri(pathOrAbsolute(path)));
Builder builder = resource.accept(accept);
if (!headers.isEmpty()) {
for (Map.Entry<String, String> header : headers.entrySet()) {
builder = builder.header(header.getKey(), header.getValue());
}
}
return builder;
}
use of com.sun.jersey.api.client.WebResource.Builder in project neo4j by neo4j.
the class RestRequest method builder.
private Builder builder(String path, final MediaType accept) {
WebResource resource = client.resource(uri(pathOrAbsolute(path)));
Builder builder = resource.accept(accept);
if (!headers.isEmpty()) {
for (Map.Entry<String, String> header : headers.entrySet()) {
builder = builder.header(header.getKey(), header.getValue());
}
}
return builder;
}
Aggregations