co.cask.common.http.HttpResponse.getResponseBody()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中co.cask.common.http.HttpResponse.getResponseBody()方法的一些代码示例,展示了HttpResponse.getResponseBody()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getResponseBody()方法的具体详情如下:
包路径:co.cask.common.http.HttpResponse
类名称:HttpResponse
方法名:getResponseBody

HttpResponse.getResponseBody介绍

暂无

代码示例

代码示例来源:origin: cdapio/cdap

private String parseResponseAsMap(HttpResponse response, String key) throws ExploreException {
 Map<String, String> responseMap = parseJson(response, MAP_TYPE_TOKEN);
 if (responseMap.containsKey(key)) {
  return responseMap.get(key);
 }
 String message = String.format("Cannot find key %s in server response: %s", key,
                 new String(response.getResponseBody(), Charsets.UTF_8));
 LOG.error(message);
 throw new ExploreException(message);
}

代码示例来源:origin: cdapio/cdap

@Override
public SecureStoreData get(String namespace, String name) throws Exception {
 // 1. Get metadata of the secure key
 HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET,
                          createPath(namespace, name) + "/metadata").build();
 HttpResponse response = remoteClient.execute(request);
 handleResponse(response, namespace, name, String.format("Error occurred while getting metadata for key %s:%s",
                             namespace, name));
 SecureStoreMetadata metadata = GSON.fromJson(response.getResponseBodyAsString(), SecureStoreMetadata.class);
 // 2. Get sensitive data for the secure key
 request = remoteClient.requestBuilder(HttpMethod.GET, createPath(namespace, name)).build();
 response = remoteClient.execute(request);
 handleResponse(response, namespace, name, String.format("Error occurred while getting key %s:%s",
                             namespace, name));
 // response is not a json object
 byte[] data = response.getResponseBody();
 return new SecureStoreData(metadata, data);
}

代码示例来源:origin: co.cask.cdap/cdap-explore-client

private String parseResponseAsMap(HttpResponse response, String key) throws ExploreException {
 Map<String, String> responseMap = parseJson(response, MAP_TYPE_TOKEN);
 if (responseMap.containsKey(key)) {
  return responseMap.get(key);
 }
 String message = String.format("Cannot find key %s in server response: %s", key,
                 new String(response.getResponseBody(), Charsets.UTF_8));
 LOG.error(message);
 throw new ExploreException(message);
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

private DatasetAdminOpResponse executeAdminOp(DatasetId datasetInstanceId, String opName)
 throws IOException, HandlerException, ConflictException {
 HttpResponse httpResponse = doRequest(datasetInstanceId, opName, null);
 return GSON.fromJson(Bytes.toString(httpResponse.getResponseBody()), DatasetAdminOpResponse.class);
}

代码示例来源:origin: cdapio/cdap

private DatasetAdminOpResponse executeAdminOp(DatasetId datasetInstanceId, String opName)
 throws IOException, HandlerException, ConflictException {
 HttpResponse httpResponse = doRequest(datasetInstanceId, opName, null);
 return GSON.fromJson(Bytes.toString(httpResponse.getResponseBody()), DatasetAdminOpResponse.class);
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Nullable
@Override
public RollbackDetail publish(StoreRequest request) throws TopicNotFoundException, IOException {
 HttpResponse response = performWriteRequest(request, true);
 byte[] body = response.getResponseBody();
 if (body.length == 0) {
  return null;
 }
 // It has rollback detail, verify the content-type and decode it
 verifyContentType(response.getHeaders().asMap(), "avro/binary");
 return new ClientRollbackDetail(body);
}

代码示例来源:origin: caskdata/cdap

@Nullable
@Override
public RollbackDetail publish(StoreRequest request) throws TopicNotFoundException, IOException {
 HttpResponse response = performWriteRequest(request, true);
 byte[] body = response.getResponseBody();
 if (body.length == 0) {
  return null;
 }
 // It has rollback detail, verify the content-type and decode it
 verifyContentType(response.getHeaders().asMap(), "avro/binary");
 return new ClientRollbackDetail(body);
}

代码示例来源:origin: caskdata/cdap

/**
 * Gets the live info of a system service.
 *
 * @param serviceName Name of the system service
 * @return live info of the system service
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public SystemServiceLiveInfo getSystemServiceLiveInfo(String serviceName)
 throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
 URL url = config.resolveURLV3(String.format("system/services/%s/live-info", serviceName));
 HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(),
                       HttpURLConnection.HTTP_NOT_FOUND);
 String responseBody = new String(response.getResponseBody());
 if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
  throw new NotFoundException(new SystemServiceId(serviceName));
 }
 return GSON.fromJson(responseBody, SystemServiceLiveInfo.class);
}

代码示例来源:origin: caskdata/cdap

/**
 * Gets the status of a system service.
 *
 * @param serviceName Name of the system service
 * @return status of the system service
 * @throws IOException if a network error occurred
 * @throws NotFoundException if the system service with the specified name could not be found
 * @throws BadRequestException if the operation was not valid for the system service
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public String getSystemServiceStatus(String serviceName)
 throws IOException, NotFoundException, BadRequestException, UnauthenticatedException, UnauthorizedException {
 URL url = config.resolveURL(String.format("system/services/%s/status", serviceName));
 HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(),
                       HttpURLConnection.HTTP_NOT_FOUND,
                       HttpURLConnection.HTTP_BAD_REQUEST);
 String responseBody = new String(response.getResponseBody());
 if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
  throw new NotFoundException(new SystemServiceId(serviceName));
 } else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
  throw new BadRequestException(responseBody);
 }
 Map<String, String> status = GSON.fromJson(responseBody, new TypeToken<Map<String, String>>() { }.getType());
 return status.get("status");
}

代码示例来源:origin: caskdata/cdap

/**
 * Sets the number of instances the system service is running on.
 *
 * @param serviceName name of the system service
 * @param instances number of instances the system service is running on
 * @throws IOException if a network error occurred
 * @throws NotFoundException if the system service with the specified name was not found
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public void setSystemServiceInstances(String serviceName, int instances)
 throws IOException, NotFoundException, BadRequestException, UnauthenticatedException, UnauthorizedException {
 URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
 HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
 HttpResponse response = restClient.execute(request, config.getAccessToken(),
                       HttpURLConnection.HTTP_NOT_FOUND,
                       HttpURLConnection.HTTP_BAD_REQUEST);
 if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
  throw new NotFoundException(new SystemServiceId(serviceName));
 } else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
  throw new BadRequestException(new String(response.getResponseBody()));
 }
}

代码示例来源:origin: caskdata/cdap

/**
 * Gets the logs of a program.
 *
 * @param program the program
 * @param start start time of the time range of desired logs
 * @param stop end time of the time range of desired logs
 * @return the logs of the program
 * @throws IOException if a network error occurred
 * @throws NotFoundException if the application or program could not be found
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public String getProgramLogs(ProgramId program, long start, long stop)
 throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
 String path = String.format("apps/%s/%s/%s/logs?start=%d&stop=%d&escape=false",
               program.getApplication(), program.getType().getCategoryName(),
               program.getProgram(), start, stop);
 URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), path);
 HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
 if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
  throw new ProgramNotFoundException(program);
 }
 return new String(response.getResponseBody(), Charsets.UTF_8);
}

代码示例来源:origin: caskdata/cdap

private void testAdminOp(DatasetId datasetInstanceId, String opName, int expectedStatus,
             Object expectedResult)
 throws IOException {
 String path = String.format("/namespaces/%s/data/datasets/%s/admin/%s",
               datasetInstanceId.getNamespace(), datasetInstanceId.getEntityName(), opName);
 URL targetUrl = resolve(path);
 HttpResponse response = HttpRequests.execute(HttpRequest.post(targetUrl).build());
 DatasetAdminOpResponse body = getResponse(response.getResponseBody());
 Assert.assertEquals(expectedStatus, response.getResponseCode());
 Assert.assertEquals(expectedResult, body.getResult());
}

相关文章