本文整理了Java中co.cask.common.http.HttpResponse.getResponseBodyAsString()
方法的一些代码示例,展示了HttpResponse.getResponseBodyAsString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getResponseBodyAsString()
方法的具体详情如下:
包路径:co.cask.common.http.HttpResponse
类名称:HttpResponse
方法名:getResponseBodyAsString
暂无
代码示例来源:origin: cdapio/cdap
Collection<DatasetSpecificationSummary> getAllInstances() throws DatasetManagementException {
HttpResponse response = doGet("datasets");
if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
throw new DatasetManagementException(String.format("Cannot retrieve all dataset instances, details: %s",
response));
}
return GSON.fromJson(response.getResponseBodyAsString(), SUMMARY_LIST_TYPE);
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
Collection<DatasetSpecificationSummary> getAllInstances() throws DatasetManagementException {
HttpResponse response = doGet("datasets");
if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
throw new DatasetManagementException(String.format("Cannot retrieve all dataset instances, details: %s",
response));
}
return GSON.fromJson(response.getResponseBodyAsString(), SUMMARY_LIST_TYPE);
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
@Nullable
public DatasetTypeMeta getType(String typeName) throws DatasetManagementException {
HttpResponse response = doGet("types/" + typeName);
if (HttpResponseStatus.NOT_FOUND.code() == response.getResponseCode()) {
return null;
}
if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
throw new DatasetManagementException(String.format("Cannot retrieve dataset type %s info, details: %s",
typeName, response));
}
return GSON.fromJson(response.getResponseBodyAsString(), DatasetTypeMeta.class);
}
代码示例来源:origin: caskdata/cdap
public void ping() throws IOException, UnauthenticatedException, UnauthorizedException {
HttpResponse response = restClient.execute(
HttpMethod.GET, config.resolveURLNoVersion("ping"), config.getAccessToken());
if (!Objects.equals(response.getResponseBodyAsString(), "OK.\n")) {
throw new IOException("Unexpected response body");
}
}
代码示例来源:origin: caskdata/cdap
@Override
public List<TopicId> listTopics(NamespaceId namespaceId) throws IOException {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET, namespaceId.getNamespace() + "/topics").build();
HttpResponse response = remoteClient.execute(request);
handleError(response, "Failed to list topics in namespace " + namespaceId);
List<String> topics = GSON.fromJson(response.getResponseBodyAsString(), TOPIC_LIST_TYPE);
List<TopicId> result = new ArrayList<>(topics.size());
for (String topic : topics) {
result.add(namespaceId.topic(topic));
}
return Collections.unmodifiableList(result);
}
代码示例来源:origin: cdapio/cdap
private Set<? extends EntityId> visibilityCheckCall(VisibilityRequest visibilityRequest) throws IOException {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.POST, "isVisible")
.withBody(GSON.toJson(visibilityRequest))
.build();
return GSON.fromJson(remoteClient.execute(request).getResponseBodyAsString(), SET_ENTITY_TYPE);
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
private void verifyResponse(HttpResponse httpResponse) throws ConflictException {
if (httpResponse.getResponseCode() == 409) {
throw new ConflictException(httpResponse.getResponseBodyAsString(Charsets.UTF_8));
}
if (httpResponse.getResponseCode() != 200) {
throw new HandlerException(HttpResponseStatus.valueOf(httpResponse.getResponseCode()),
httpResponse.getResponseBodyAsString(Charsets.UTF_8));
}
}
}
代码示例来源:origin: cdapio/cdap
@Override
public List<SecureStoreMetadata> list(String namespace) throws Exception {
HttpRequest request = remoteClient.requestBuilder(HttpMethod.GET, createPath(namespace)).build();
HttpResponse response = remoteClient.execute(request);
handleResponse(response, namespace, "", "Error occurred while listing keys");
return GSON.fromJson(response.getResponseBodyAsString(), LIST_TYPE);
}
代码示例来源:origin: cdapio/cdap
private JsonElement getProperty(int expectedStatus) throws Exception {
HttpResponse response = doGet("/v3/configuration/user");
Assert.assertEquals(expectedStatus, response.getResponseCode());
if (expectedStatus == HttpResponseStatus.OK.code()) {
return new JsonParser().parse(response.getResponseBodyAsString());
}
return null;
}
代码示例来源:origin: cdapio/cdap
private JsonElement getDashboards(String namespace) throws Exception {
String req = String.format("/v3/namespaces/%s/configuration/dashboards", namespace);
HttpResponse response = doGet(req);
Assert.assertEquals(200, response.getResponseCode());
return new JsonParser().parse(response.getResponseBodyAsString());
}
代码示例来源: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 Optional<ProfileStatus> getProfileStatus(ProfileId profileId, int expectedCode) throws Exception {
HttpResponse response = doGet(String.format("/v3/namespaces/%s/profiles/%s/status",
profileId.getNamespace(), profileId.getProfile()));
Assert.assertEquals(expectedCode, response.getResponseCode());
if (expectedCode == HttpResponseStatus.OK.code()) {
return Optional.of(GSON.fromJson(response.getResponseBodyAsString(), ProfileStatus.class));
}
return Optional.empty();
}
代码示例来源: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
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
private Collection<TimeSeries> query(URL serviceUrl, CubeQuery query) throws IOException {
URL url = new URL(serviceUrl, "query");
HttpRequest request = HttpRequest.post(url).withBody(GSON.toJson(query)).build();
HttpResponse response = HttpRequests.execute(request);
Assert.assertEquals(200, response.getResponseCode());
return GSON.fromJson(response.getResponseBodyAsString(), new TypeToken<Collection<TimeSeries>>() { }.getType());
}
}
代码示例来源: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
private void testListInitialState(String namespace, ProgramType programType) throws Exception {
HttpResponse response = doGet(getVersionedAPIPath(programType.getCategoryName(),
Constants.Gateway.API_VERSION_3_TOKEN, namespace));
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals(EMPTY_ARRAY_JSON, response.getResponseBodyAsString());
}
代码示例来源:origin: cdapio/cdap
/**
* Tests deploying an application in a non-existing non-default namespace.
*/
@Test
public void testDeployNonExistingNamespace() throws Exception {
HttpResponse response = deploy(AllProgramsApp.class, 404, Constants.Gateway.API_VERSION_3_TOKEN, "random");
NotFoundException nfe = new NamespaceNotFoundException(new NamespaceId("random"));
Assert.assertEquals(nfe.getMessage(), response.getResponseBodyAsString());
}
代码示例来源:origin: cdapio/cdap
@Test
public void testCreate() throws Exception {
SecureKeyCreateRequest secureKeyCreateRequest = new SecureKeyCreateRequest(DESCRIPTION, DATA,
PROPERTIES);
HttpResponse response = create(KEY, secureKeyCreateRequest);
Assert.assertEquals(200, response.getResponseCode());
response = get(KEY);
Assert.assertEquals(200, response.getResponseCode());
Assert.assertEquals(DATA, response.getResponseBodyAsString());
response = delete(KEY);
Assert.assertEquals(200, response.getResponseCode());
}
内容来源于网络,如有侵权,请联系作者删除!