Search in sources :

Example 11 with Builder

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);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource)

Example 12 with Builder

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));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource) ZSession(org.apache.zookeeper.server.jersey.jaxb.ZSession) Test(org.junit.Test)

Example 13 with Builder

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));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Stat(org.apache.zookeeper.data.Stat) ZPath(org.apache.zookeeper.server.jersey.jaxb.ZPath) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 14 with Builder

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;
}
Also used : Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with 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;
}
Also used : Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Builder (com.sun.jersey.api.client.WebResource.Builder)28 ClientResponse (com.sun.jersey.api.client.ClientResponse)24 WebResource (com.sun.jersey.api.client.WebResource)20 EurekaHttpResponseBuilder (com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder)8 Test (org.junit.Test)6 Stat (org.apache.zookeeper.data.Stat)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3 Map (java.util.Map)3 CacheBuilder (com.google.common.cache.CacheBuilder)2 Client (com.sun.jersey.api.client.Client)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ZSession (org.apache.zookeeper.server.jersey.jaxb.ZSession)2 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)2 DeprecatedRecordException (org.orcid.listener.exception.DeprecatedRecordException)2 LockedRecordException (org.orcid.listener.exception.LockedRecordException)2 AbstractLoadBalancerAwareClient (com.netflix.client.AbstractLoadBalancerAwareClient)1 ClientException (com.netflix.client.ClientException)1 ClientFactory (com.netflix.client.ClientFactory)1 RequestSpecificRetryHandler (com.netflix.client.RequestSpecificRetryHandler)1