Search in sources :

Example 6 with Builder

use of com.sun.jersey.api.client.WebResource.Builder in project eureka by Netflix.

the class AbstractJerseyEurekaHttpClient method getApplicationsInternal.

private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath, String[] regions) {
    ClientResponse response = null;
    String regionsParamValue = null;
    try {
        WebResource webResource = jerseyClient.resource(serviceUrl).path(urlPath);
        if (regions != null && regions.length > 0) {
            regionsParamValue = StringUtil.join(regions);
            webResource = webResource.queryParam("regions", regionsParamValue);
        }
        Builder requestBuilder = webResource.getRequestBuilder();
        addExtraHeaders(requestBuilder);
        response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
        Applications applications = null;
        if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
            applications = response.getEntity(Applications.class);
        }
        return anEurekaHttpResponse(response.getStatus(), Applications.class).headers(headersOf(response)).entity(applications).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey HTTP GET {}{}?{}; statusCode={}", serviceUrl, urlPath, regionsParamValue == null ? "" : "regions=" + regionsParamValue, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Applications(com.netflix.discovery.shared.Applications) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource)

Example 7 with Builder

use of com.sun.jersey.api.client.WebResource.Builder in project eureka by Netflix.

the class AbstractJerseyEurekaHttpClient method getInstanceInternal.

private EurekaHttpResponse<InstanceInfo> getInstanceInternal(String urlPath) {
    ClientResponse response = null;
    try {
        Builder requestBuilder = jerseyClient.resource(serviceUrl).path(urlPath).getRequestBuilder();
        addExtraHeaders(requestBuilder);
        response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
        InstanceInfo infoFromPeer = null;
        if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
            infoFromPeer = response.getEntity(InstanceInfo.class);
        }
        return anEurekaHttpResponse(response.getStatus(), InstanceInfo.class).headers(headersOf(response)).entity(infoFromPeer).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey HTTP GET {}{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(com.sun.jersey.api.client.WebResource.Builder) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 8 with Builder

use of com.sun.jersey.api.client.WebResource.Builder in project eureka by Netflix.

the class AbstractJerseyEurekaHttpClient method cancel.

@Override
public EurekaHttpResponse<Void> cancel(String appName, String id) {
    String urlPath = "apps/" + appName + '/' + id;
    ClientResponse response = null;
    try {
        Builder resourceBuilder = jerseyClient.resource(serviceUrl).path(urlPath).getRequestBuilder();
        addExtraHeaders(resourceBuilder);
        response = resourceBuilder.delete(ClientResponse.class);
        return anEurekaHttpResponse(response.getStatus()).headers(headersOf(response)).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey HTTP DELETE {}{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(com.sun.jersey.api.client.WebResource.Builder)

Example 9 with Builder

use of com.sun.jersey.api.client.WebResource.Builder in project eureka by Netflix.

the class AbstractJerseyEurekaHttpClient method statusUpdate.

@Override
public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus, InstanceInfo info) {
    String urlPath = "apps/" + appName + '/' + id + "/status";
    ClientResponse response = null;
    try {
        Builder requestBuilder = jerseyClient.resource(serviceUrl).path(urlPath).queryParam("value", newStatus.name()).queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).getRequestBuilder();
        addExtraHeaders(requestBuilder);
        response = requestBuilder.put(ClientResponse.class);
        return anEurekaHttpResponse(response.getStatus()).headers(headersOf(response)).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey HTTP PUT {}{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(com.sun.jersey.api.client.WebResource.Builder)

Example 10 with Builder

use of com.sun.jersey.api.client.WebResource.Builder in project zookeeper by apache.

the class SessionTest method testDeleteSession.

@Test
public void testDeleteSession() {
    ZSession session = createSession("30");
    WebResource wr = sessionsr.path(session.id);
    Builder b = wr.accept(MediaType.APPLICATION_JSON);
    Assert.assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
    ClientResponse cr = b.delete(ClientResponse.class, null);
    Assert.assertEquals(ClientResponse.Status.NO_CONTENT, cr.getClientResponseStatus());
    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)

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