當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientHandlerException類代碼示例

本文整理匯總了Java中com.sun.jersey.api.client.ClientHandlerException的典型用法代碼示例。如果您正苦於以下問題:Java ClientHandlerException類的具體用法?Java ClientHandlerException怎麽用?Java ClientHandlerException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClientHandlerException類屬於com.sun.jersey.api.client包,在下文中一共展示了ClientHandlerException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: postRest

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
/**
 * Performs a REST POST operation of a json string on the base
 * XOS REST URI with an optional additional URI suffix.
 *
 * @param uri URI suffix to append to base URI
 * @param json JSON string to post
 */
public void postRest(String uri, String json) {
    WebResource.Builder builder = getClientBuilder(uri);
    ClientResponse response;

    try {
        response = builder.post(ClientResponse.class, json);
    } catch (ClientHandlerException e) {
        log.warn("Unable to contact REST server: {}", e.getMessage());
        return;
    }

    if (response.getStatus() != HTTP_CREATED) {
        log.info("REST POST request returned error code {}",
                 response.getStatus());
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:XosManagerRestUtils.java

示例2: logResponse

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
private StringBuilder logResponse(long id, ClientResponse response) {
	StringBuilder b = new StringBuilder();

	printResponseLine(b, id, response);
	printResponseHeaders(b, id, response.getHeaders());

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	InputStream in = response.getEntityInputStream();
	try {
		ReaderWriter.writeTo(in, out);

		byte[] requestEntity = out.toByteArray();
		printEntity(b, requestEntity);
		response.setEntityInputStream(new ByteArrayInputStream(requestEntity));
	} catch (IOException ex) {
		throw new ClientHandlerException(ex);
	}
	log(b.toString());
	return b;
}
 
開發者ID:qmetry,項目名稱:qaf,代碼行數:21,代碼來源:RequestLogger.java

示例3: doUploadFile

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
ClientResponse.Status doUploadFile(WebResource webResource, File file, String sourceId, String fileTypeId) throws ClientHandlerException, UniformInterfaceException, IOException {
	try (InputStream is = new FileInputStream(file)) {
		FormDataMultiPart part = 
				new FormDataMultiPart();
		part.bodyPart(
				new FormDataBodyPart(
						FormDataContentDisposition
								.name("file")
								.fileName(file.getName())
								.build(), 
						is, MediaType.APPLICATION_OCTET_STREAM_TYPE));
		ClientResponse response = webResource
				.path("/api/protected/file/upload/" + sourceId + "/" + fileTypeId)
				.type(MediaType.MULTIPART_FORM_DATA_TYPE)
				.post(ClientResponse.class, part);
		ClientResponse.Status result = response.getClientResponseStatus();
		return result;
	}
}
 
開發者ID:eurekaclinical,項目名稱:eureka,代碼行數:20,代碼來源:FileUploadSupport.java

示例4: mockEntityClientResponse

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
private static ClientResponse mockEntityClientResponse(
    TimelineClientImpl client, ClientResponse.Status status,
    boolean hasError, boolean hasRuntimeError) {
  ClientResponse response = mock(ClientResponse.class);
  if (hasRuntimeError) {
    doThrow(new ClientHandlerException(new ConnectException())).when(client)
        .doPostingObject(any(TimelineEntities.class), any(String.class));
    return response;
  }
  doReturn(response).when(client)
      .doPostingObject(any(TimelineEntities.class), any(String.class));
  when(response.getClientResponseStatus()).thenReturn(status);
  TimelinePutResponse.TimelinePutError error =
      new TimelinePutResponse.TimelinePutError();
  error.setEntityId("test entity id");
  error.setEntityType("test entity type");
  error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION);
  TimelinePutResponse putResponse = new TimelinePutResponse();
  if (hasError) {
    putResponse.addError(error);
  }
  when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse);
  return response;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:TestTimelineClient.java

示例5: putRest

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
/**
 * Performs a REST PUT operation on the base XOS REST URI with
 * an optional additional URI.
 *
 * @param uri URI suffix to append to base URI
 * @return JSON string returned by the PUT operation
 */
public String putRest(String uri) {
    WebResource.Builder builder = getClientBuilder(uri);
    ClientResponse response;

    try {
        response = builder.put(ClientResponse.class);
    } catch (ClientHandlerException e) {
        log.warn("Unable to contact REST server: {}", e.getMessage());
        return "";
    }

    if (response.getStatus() != HTTP_OK) {
        log.info("REST PUT request returned error code {}",
                 response.getStatus());
    }
    return response.getEntity(String.class);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:25,代碼來源:XosManagerRestUtils.java

示例6: mockEntityClientResponse

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
private static ClientResponse mockEntityClientResponse(
    TimelineWriter spyTimelineWriter, ClientResponse.Status status,
    boolean hasError, boolean hasRuntimeError) {
  ClientResponse response = mock(ClientResponse.class);
  if (hasRuntimeError) {
    doThrow(new ClientHandlerException(new ConnectException())).when(
      spyTimelineWriter).doPostingObject(
      any(TimelineEntities.class), any(String.class));
    return response;
  }
  doReturn(response).when(spyTimelineWriter)
      .doPostingObject(any(TimelineEntities.class), any(String.class));
  when(response.getClientResponseStatus()).thenReturn(status);
  TimelinePutResponse.TimelinePutError error =
      new TimelinePutResponse.TimelinePutError();
  error.setEntityId("test entity id");
  error.setEntityType("test entity type");
  error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION);
  TimelinePutResponse putResponse = new TimelinePutResponse();
  if (hasError) {
    putResponse.addError(error);
  }
  when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse);
  return response;
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:26,代碼來源:TestTimelineClient.java

示例7: getAMContainerInfoForRMWebService

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
private List<JSONObject> getAMContainerInfoForRMWebService(
    Configuration conf, String appId) throws ClientHandlerException,
    UniformInterfaceException, JSONException {
  Client webServiceClient = Client.create();
  String webAppAddress =
      WebAppUtils.getWebAppBindURL(conf, YarnConfiguration.RM_BIND_HOST,
        WebAppUtils.getRMWebAppURLWithScheme(conf));
  WebResource webResource = webServiceClient.resource(webAppAddress);

  ClientResponse response =
      webResource.path("ws").path("v1").path("cluster").path("apps")
        .path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
  JSONObject json =
      response.getEntity(JSONObject.class).getJSONObject("appAttempts");
  JSONArray requests = json.getJSONArray("appAttempt");
  List<JSONObject> amContainersList = new ArrayList<JSONObject>();
  for (int i = 0; i < requests.length(); i++) {
    amContainersList.add(requests.getJSONObject(i));
  }
  return amContainersList;
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:23,代碼來源:LogsCLI.java

示例8: getAMContainerInfoForAHSWebService

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
private List<JSONObject> getAMContainerInfoForAHSWebService(Configuration conf,
    String appId) throws ClientHandlerException, UniformInterfaceException,
    JSONException {
  Client webServiceClient = Client.create();
  String webAppAddress =
      WebAppUtils.getHttpSchemePrefix(conf)
          + WebAppUtils.getAHSWebAppURLWithoutScheme(conf);
  WebResource webResource = webServiceClient.resource(webAppAddress);

  ClientResponse response =
      webResource.path("ws").path("v1").path("applicationhistory").path("apps")
        .path(appId).path("appattempts").accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
  JSONObject json = response.getEntity(JSONObject.class);
  JSONArray requests = json.getJSONArray("appAttempt");
  List<JSONObject> amContainersList = new ArrayList<JSONObject>();
  for (int i = 0; i < requests.length(); i++) {
    amContainersList.add(requests.getJSONObject(i));
  }
  Collections.reverse(amContainersList);
  return amContainersList;
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:23,代碼來源:LogsCLI.java

示例9: handle

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
	long id = ++_id;

	StringBuilder requestString = new StringBuilder();
	logRequest(id, request, requestString);

	LoggingBean loggingBean = new LoggingBean();
	loggingBean.setCommandName(request.getMethod() + ":" + request.getURI());

	loggingBean.setArgs(new String[] { request.getURI().getPath(), request.getURI().getQuery() });

	ClientResponse response = getNext().handle(request);
	loggingBean.setResult(response.toString());
	StringBuilder responseString = logResponse(id, response);

	LoggingBean detailsLoggingBean = new LoggingBean();
	detailsLoggingBean.setArgs(new String[] { noPrifix(requestString).toString() });
	detailsLoggingBean.setResult(noPrifix(responseString).toString());

	loggingBean.getSubLogs().add(detailsLoggingBean);

	TestBaseProvider.instance().get().getLog().add(loggingBean);

	return response;
}
 
開發者ID:qmetry,項目名稱:qaf,代碼行數:27,代碼來源:RequestLogger.java

示例10: testDelegateConnectionTimeoutException

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
@Test
public void testDelegateConnectionTimeoutException() throws Exception {
    doThrow(new ClientHandlerException(new ConnectTimeoutException())).when(_delegate).doIt();
    TestInterface service = _serviceFactory.create(_remoteEndPoint);

    try {
        service.doIt();
    } catch (PartitionForwardingException e) {
        assertTrue(e.getCause() instanceof ConnectTimeoutException);
    }

    assertEquals(_metricRegistry.getMeters().get("bv.emodb.web.partition-forwarding.TestInterface.errors").getCount(), 1);

    verify(_delegateServiceFactory).create(_remoteEndPoint);
    verify(_delegate).doIt();

}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:18,代碼來源:PartitionAwareServiceFactoryTest.java

示例11: test001AddTrigger

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
@Test
public void test001AddTrigger() throws UniformInterfaceException, ClientHandlerException, JsonProcessingException{
	WebResource webResource = resource();
	Trigger trigger = new Trigger();
	trigger.setAppId(TESTAPPID);
	trigger.setAppName(TESTAPPNAME);
	trigger.setBreachDurationSecs(120);
	trigger.setCallbackUrl("");
	trigger.setMetric("Memory");
	trigger.setMetricThreshold(30);
	trigger.setStatType(Trigger.AGGREGATE_TYPE_AVG);
	trigger.setStatWindowSecs(120);
	trigger.setThresholdType(Trigger.THRESHOLD_TYPE_LESS_THAN);
	trigger.setTriggerId(AutoScalerPolicyTrigger.TriggerId_LowerThreshold);
	trigger.setUnit("persent");
	ClientResponse response = webResource.path("/triggers").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,mapper.writeValueAsString(trigger));
	assertEquals(response.getStatus(), STATUS200);
}
 
開發者ID:cfibmers,項目名稱:open-Autoscaler,代碼行數:19,代碼來源:SubscriberRESTTest.java

示例12: handle

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
@Override
public ClientResponse handle(ClientRequest cr) throws ClientHandlerException
{
  URIBuilder uriBuilder = new URIBuilder(cr.getURI());
  String path = uriBuilder.getPath();
  uriBuilder.setPath(converter.convertCommandPath(path));
  try {
    cr.setURI(uriBuilder.build());
    ClientResponse response = getNext().handle(cr);
    String newEntity = converter.convertResponse(path, response.getEntity(String.class));
    response.setEntityInputStream(new ByteArrayInputStream(newEntity.getBytes()));
    return response;
  } catch (Exception ex) {
    throw new ClientHandlerException(ex);
  }
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:17,代碼來源:WebServicesVersionConversion.java

示例13: authentification

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
public static Pair<Boolean, String> authentification(String u, String p) {
    try {
        AuthSnd st = new AuthSnd(u, p, "TheSecretStringIsMuchStrongerThanOneMillionOfTanks");

        ClientResponse response = DataServer.getClientResponse(st, "login");
        AuthRcv output = response.getEntity(AuthRcv.class);

        if (output.getErr() != null) {
            return new Pair<>(false, output.getErr());
        } else {
           return new Pair<>(true, output.getRes());
        }
    } catch (ClientHandlerException e) {
        e.printStackTrace();
        return new Pair<>(false, e.getCause().getMessage());
    }
}
 
開發者ID:LeNiglo,項目名稱:TinyTank,代碼行數:18,代碼來源:DataServer.java

示例14: getServerList

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
public static Pair<Boolean, String> getServerList() {

        try {
            ClientResponse response = DataServer.getClientResponse(null, "list_servers");
            ServerListRcv output = response.getEntity(ServerListRcv.class);

            if (output.getErr() != null) {
                return new Pair<>(false, output.getErr());
            } else {
                return new Pair<>(true, output.getRes());
            }
        } catch (ClientHandlerException e) {
            e.printStackTrace();
            return new Pair<>(false, e.getCause().getMessage());
        }

    }
 
開發者ID:LeNiglo,項目名稱:TinyTank,代碼行數:18,代碼來源:DataServer.java

示例15: handle

import com.sun.jersey.api.client.ClientHandlerException; //導入依賴的package包/類
@Override
public ClientResponse handle(ClientRequest request)
        throws ClientHandlerException {

    String uuid = UUID.randomUUID().toString();

    if (LOGGER.isDebugEnabled()) {
        logRequest(uuid, request);
    }

    ClientResponse response = getNext().handle(request);

    if (LOGGER.isDebugEnabled()) {
        logResponse(uuid, response);
    }

    return response;
}
 
開發者ID:kenzanlabs,項目名稱:bowtie,代碼行數:19,代碼來源:LoggerFilter.java


注:本文中的com.sun.jersey.api.client.ClientHandlerException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。