use of com.sun.jersey.api.client.WebResource.Builder in project eureka by Netflix.
the class AbstractJerseyEurekaHttpClient method deleteStatusOverride.
@Override
public EurekaHttpResponse<Void> deleteStatusOverride(String appName, String id, InstanceInfo info) {
String urlPath = "apps/" + appName + '/' + id + "/status";
ClientResponse response = null;
try {
Builder requestBuilder = jerseyClient.resource(serviceUrl).path(urlPath).queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).getRequestBuilder();
addExtraHeaders(requestBuilder);
response = requestBuilder.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();
}
}
}
use of com.sun.jersey.api.client.WebResource.Builder in project eureka by Netflix.
the class AbstractJerseyEurekaHttpClient method getApplication.
@Override
public EurekaHttpResponse<Application> getApplication(String appName) {
String urlPath = "apps/" + appName;
ClientResponse response = null;
try {
Builder requestBuilder = jerseyClient.resource(serviceUrl).path(urlPath).getRequestBuilder();
addExtraHeaders(requestBuilder);
response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
Application application = null;
if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
application = response.getEntity(Application.class);
}
return anEurekaHttpResponse(response.getStatus(), Application.class).headers(headersOf(response)).entity(application).build();
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Jersey HTTP GET {}{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
}
if (response != null) {
response.close();
}
}
}
use of com.sun.jersey.api.client.WebResource.Builder in project eureka by Netflix.
the class JerseyReplicationClient method sendHeartBeat.
/**
* Compared to regular heartbeat, in the replication channel the server may return a more up to date
* instance copy.
*/
@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) {
String urlPath = "apps/" + appName + '/' + id;
ClientResponse response = null;
try {
WebResource webResource = jerseyClient.getClient().resource(serviceUrl).path(urlPath).queryParam("status", info.getStatus().toString()).queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString());
if (overriddenStatus != null) {
webResource = webResource.queryParam("overriddenstatus", overriddenStatus.name());
}
Builder requestBuilder = webResource.getRequestBuilder();
addExtraHeaders(requestBuilder);
response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).put(ClientResponse.class);
InstanceInfo infoFromPeer = null;
if (response.getStatus() == Status.CONFLICT.getStatusCode() && response.hasEntity()) {
infoFromPeer = response.getEntity(InstanceInfo.class);
}
return anEurekaHttpResponse(response.getStatus(), infoFromPeer).type(MediaType.APPLICATION_JSON_TYPE).build();
} finally {
if (logger.isDebugEnabled()) {
logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus());
}
if (response != null) {
response.close();
}
}
}
use of com.sun.jersey.api.client.WebResource.Builder in project ribbon by Netflix.
the class RestClient method execute.
private HttpResponse execute(HttpRequest.Verb verb, URI uri, Map<String, Collection<String>> headers, Map<String, Collection<String>> params, IClientConfig overriddenClientConfig, Object requestEntity) throws Exception {
HttpClientResponse thisResponse = null;
final boolean bbFollowRedirects = Optional.ofNullable(overriddenClientConfig).flatMap(config -> config.getIfSet(CommonClientConfigKey.FollowRedirects)).orElse(bFollowRedirects);
restClient.setFollowRedirects(bbFollowRedirects);
if (logger.isDebugEnabled()) {
logger.debug("RestClient sending new Request(" + verb + ": ) " + uri);
}
WebResource xResource = restClient.resource(uri.toString());
if (params != null) {
for (Map.Entry<String, Collection<String>> entry : params.entrySet()) {
String name = entry.getKey();
for (String value : entry.getValue()) {
xResource = xResource.queryParam(name, value);
}
}
}
ClientResponse jerseyResponse;
Builder b = xResource.getRequestBuilder();
if (headers != null) {
for (Map.Entry<String, Collection<String>> entry : headers.entrySet()) {
String name = entry.getKey();
for (String value : entry.getValue()) {
b = b.header(name, value);
}
}
}
Object entity = requestEntity;
switch(verb) {
case GET:
jerseyResponse = b.get(ClientResponse.class);
break;
case POST:
jerseyResponse = b.post(ClientResponse.class, entity);
break;
case PUT:
jerseyResponse = b.put(ClientResponse.class, entity);
break;
case DELETE:
jerseyResponse = b.delete(ClientResponse.class);
break;
case HEAD:
jerseyResponse = b.head();
break;
case OPTIONS:
jerseyResponse = b.options(ClientResponse.class);
break;
default:
throw new ClientException(ClientException.ErrorType.GENERAL, "You have to one of the REST verbs such as GET, POST etc.");
}
thisResponse = new HttpClientResponse(jerseyResponse, uri, overriddenClientConfig);
if (thisResponse.getStatus() == 503) {
thisResponse.close();
throw new ClientException(ClientException.ErrorType.SERVER_THROTTLED);
}
return thisResponse;
}
use of com.sun.jersey.api.client.WebResource.Builder in project zookeeper by apache.
the class SessionTest method testCreateEphemeralZNode.
@Test
public void testCreateEphemeralZNode() throws KeeperException, InterruptedException, IOException {
ZSession session = createSession("30");
WebResource wr = znodesr.path("/").queryParam("op", "create").queryParam("name", "ephemeral-test").queryParam("ephemeral", "true").queryParam("session", session.id).queryParam("null", "true");
Builder b = wr.accept(MediaType.APPLICATION_JSON);
ClientResponse cr = b.post(ClientResponse.class);
Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());
Stat stat = new Stat();
zk.getData("/ephemeral-test", false, stat);
ZooKeeper sessionZK = ZooKeeperService.getClient(CONTEXT_PATH, session.id);
Assert.assertEquals(stat.getEphemeralOwner(), sessionZK.getSessionId());
}
Aggregations