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

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

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

HttpResponse.getResponseCode介绍

暂无

代码示例

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

public void deleteModule(String moduleName) throws DatasetManagementException {
 HttpResponse response = doDelete("modules/" + moduleName);
 if (HttpResponseStatus.CONFLICT.code() == response.getResponseCode()) {
  throw new ModuleConflictException(String.format("Failed to delete module %s due to conflict, details: %s",
                          moduleName, response));
 }
 if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
  throw new DatasetManagementException(String.format("Failed to delete module %s, details: %s",
                            moduleName, response));
 }
}

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

/**
 * Deletes all dataset instances inside the namespace of this client is operating in.
 */
void deleteInstances() throws DatasetManagementException {
 HttpResponse response = doDelete("datasets");
 if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
  throw new DatasetManagementException(String.format("Failed to delete instances, details: %s", response));
 }
}

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

@Override
public List<TableNameInfo> getTables(String namespace) throws ExploreException {
 HttpResponse response = doGet(String.format("namespaces/%s/data/explore/tables", namespace));
 if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
  return parseJson(response, TABLES_TYPE);
 }
 throw new ExploreException("Cannot get the tables. Reason: " + response);
}

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

@Override
public QueryHandle createNamespace(NamespaceMeta namespace) throws ExploreException, SQLException {
 HttpResponse response = doPut(String.format("data/explore/namespaces/%s", namespace.getName()),
                GSON.toJson(namespace), null);
 if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
  return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
 }
 throw new ExploreException("Cannot add a namespace. Reason: " + response);
}

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

private static void createNamespaces() throws Exception {
 HttpResponse response = doPut(String.format("%s/namespaces/%s", Constants.Gateway.API_VERSION_3, TEST_NAMESPACE1),
                GSON.toJson(TEST_NAMESPACE_META1));
 Assert.assertEquals(200, response.getResponseCode());
 response = doPut(String.format("%s/namespaces/%s", Constants.Gateway.API_VERSION_3, TEST_NAMESPACE2),
          GSON.toJson(TEST_NAMESPACE_META2));
 Assert.assertEquals(200, response.getResponseCode());
}

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

private void verifyInitialBatchInstanceOutput(HttpResponse response) {
 Assert.assertEquals(200, response.getResponseCode());
 List<JsonObject> returnedBody = readResponse(response, LIST_OF_JSONOBJECT_TYPE);
 for (JsonObject obj : returnedBody) {
  Assert.assertEquals(200, obj.get("statusCode").getAsInt());
  Assert.assertEquals(1, obj.get("requested").getAsInt());
  Assert.assertEquals(0, obj.get("provisioned").getAsInt());
 }
}

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

protected Map<String, String> getPreferences(String uri, boolean resolved, int expectedStatus) throws Exception {
 String request = String.format("/v3/%s/preferences", uri);
 if (resolved) {
  request += "?resolved=true";
 }
 HttpResponse response = doGet(request);
 Assert.assertEquals(expectedStatus, response.getResponseCode());
 if (expectedStatus == 200) {
  return GSON.fromJson(response.getResponseBodyAsString(), MAP_STRING_STRING_TYPE);
 }
 return null;
}

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

protected ScheduleDetail getSchedule(String namespace, String appName, @Nullable String appVersion,
                   String scheduleName) throws Exception {
 appVersion = appVersion == null ? ApplicationId.DEFAULT_VERSION : appVersion;
 String path = String.format("apps/%s/versions/%s/schedules/%s", appName, appVersion, scheduleName);
 HttpResponse response = doGet(getVersionedAPIPath(path, namespace));
 Assert.assertEquals(HttpResponseStatus.OK.code(), response.getResponseCode());
 return readResponse(response, ScheduleDetail.class);
}

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

private static List<DashboardProgramRunRecord> getDashboardRecords(String path) throws Exception {
 HttpResponse response = doGet(path);
 Assert.assertEquals(200, response.getResponseCode());
 return GSON.fromJson(response.getResponseBodyAsString(), DASHBOARD_DETAIL_TYPE);
}

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

private void verifyProgramList(String namespace, ProgramType programType, int expected) throws Exception {
 HttpResponse response = requestProgramList(namespace, programType.getCategoryName());
 Assert.assertEquals(200, response.getResponseCode());
 List<Map<String, String>> programs = GSON.fromJson(response.getResponseBodyAsString(), LIST_MAP_STRING_STRING_TYPE);
 Assert.assertEquals(expected, programs.size());
}

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

@Test
 public void testStatus() throws Exception {
  HttpResponse response = doGet("/v3/system/services/appfabric/status");
  Assert.assertEquals(200, response.getResponseCode());
 }
}

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

@Test
public void testPruneNow() throws Exception {
 HttpResponse response = doPost("/v3/transactions/prune/now");
 Assert.assertEquals(200, response.getResponseCode());
}

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

protected List<BatchProgramHistory> getProgramRuns(NamespaceId namespace, List<ProgramId> programs) throws Exception {
 List<BatchProgram> request = programs.stream()
  .map(program -> new BatchProgram(program.getApplication(), program.getType(), program.getProgram()))
  .collect(Collectors.toList());
 HttpResponse response = doPost(getVersionedAPIPath("runs", namespace.getNamespace()), GSON.toJson(request));
 Assert.assertEquals(200, response.getResponseCode());
 return GSON.fromJson(response.getResponseBodyAsString(), BATCH_PROGRAM_RUNS_TYPE);
}

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

@Test
public void testAddBadApp() throws Exception {
 ArtifactId artifactId = NamespaceId.DEFAULT.artifact("wordcount", "1.0.0");
 Assert.assertEquals(HttpResponseStatus.BAD_REQUEST.code(),
           addAppArtifact(Id.Artifact.fromEntityId(artifactId),
                   ArtifactSummary.class).getResponseCode());
}

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

/**
 * Tries to start the given program with the given runtime arguments and expect the call completed with the status.
 */
protected void debugProgram(Id.Program program, int expectedStatusCode) throws Exception {
 String path = String.format("apps/%s/%s/%s/debug",
               program.getApplicationId(),
               program.getType().getCategoryName(),
               program.getId());
 HttpResponse response = doPost(getVersionedAPIPath(path, program.getNamespaceId()),
                 GSON.toJson(ImmutableMap.<String, String>of()));
 Assert.assertEquals(expectedStatusCode, response.getResponseCode());
}

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

protected Set<String> getAppVersions(String namespace, String appName) throws Exception {
 HttpResponse response = doGet(getVersionedAPIPath(String.format("apps/%s/versions", appName),
                          Constants.Gateway.API_VERSION_3_TOKEN, namespace));
 Assert.assertEquals(200, response.getResponseCode());
 Assert.assertEquals("application/json", getFirstHeaderValue(response, HttpHeaderNames.CONTENT_TYPE.toString()));
 return readResponse(response, SET_TRING_TYPE);
}

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

protected List<RunRecord> getProgramRuns(Id.Program program, ProgramRunStatus status) throws Exception {
 String path = String.format("apps/%s/%s/%s/runs?status=%s", program.getApplicationId(),
               program.getType().getCategoryName(), program.getId(), status.name());
 HttpResponse response = doGet(getVersionedAPIPath(path, program.getNamespaceId()));
 Assert.assertEquals(200, response.getResponseCode());
 return GSON.fromJson(response.getResponseBodyAsString(), LIST_RUNRECORD_TYPE);
}

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

protected void deleteArtifact(Id.Artifact artifact, int expectedResponseCode) throws Exception {
 String path = String.format("artifacts/%s/versions/%s", artifact.getName(), artifact.getVersion().getVersion());
 HttpResponse response = doDelete(getVersionedAPIPath(path, artifact.getNamespace().getId()));
 Assert.assertEquals(expectedResponseCode, response.getResponseCode());
}

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

@Test
public void testDeployUsingNonexistantArtifact404() throws Exception {
 Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "badapp");
 AppRequest<Config> appRequest =
  new AppRequest<>(new ArtifactSummary("something", "1.0.0"), null);
 HttpResponse response = deploy(appId, appRequest);
 Assert.assertEquals(404, response.getResponseCode());
}

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

protected int deployModuleBundled(String moduleName, String moduleClassName, Class moduleClass,
                 Location...bundleEmbeddedJars) throws IOException {
 Location moduleJar = createModuleJar(moduleClass, bundleEmbeddedJars);
 HttpRequest request = HttpRequest.put(getUrl("/data/modules/" + moduleName))
  .addHeader("X-Class-Name", moduleClassName)
  .withBody((ContentProvider<? extends InputStream>) moduleJar::getInputStream).build();
 return HttpRequests.execute(request).getResponseCode();
}

相关文章