当前位置: 首页>>代码示例>>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;未经允许,请勿转载。