Java Code Examples for org.apache.commons.httpclient.methods.DeleteMethod#getResponseBodyAsString()
The following examples show how to use
org.apache.commons.httpclient.methods.DeleteMethod#getResponseBodyAsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpUtils.java From Java-sdk with Apache License 2.0 | 6 votes |
/** * 处理delete请求 * @param url * @param headers * @return */ public static JSONObject doDelete(String url, Map<String, String> headers){ HttpClient httpClient = new HttpClient(); DeleteMethod deleteMethod = new DeleteMethod(url); //设置header setHeaders(deleteMethod,headers); String responseStr = ""; try { httpClient.executeMethod(deleteMethod); responseStr = deleteMethod.getResponseBodyAsString(); } catch (Exception e) { log.error(e); responseStr="{status:0}"; } return JSONObject.parseObject(responseStr); }
Example 2
Source File: SchemaUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Given host, port and schema name, send a http DELETE request to delete the {@link Schema}. * * @return <code>true</code> on success. * <P><code>false</code> on failure. */ public static boolean deleteSchema(@Nonnull String host, int port, @Nonnull String schemaName) { Preconditions.checkNotNull(host); Preconditions.checkNotNull(schemaName); try { URL url = new URL("http", host, port, "/schemas/" + schemaName); DeleteMethod httpDelete = new DeleteMethod(url.toString()); try { int responseCode = HTTP_CLIENT.executeMethod(httpDelete); if (responseCode >= 400) { String response = httpDelete.getResponseBodyAsString(); LOGGER.warn("Got error response code: {}, response: {}", responseCode, response); return false; } return true; } finally { httpDelete.releaseConnection(); } } catch (Exception e) { LOGGER.error("Caught exception while getting the schema: {} from host: {}, port: {}", schemaName, host, port, e); return false; } }
Example 3
Source File: ExperimentRestApiIT.java From submarine with Apache License 2.0 | 4 votes |
private void run(String body, String patchBody, String contentType) throws Exception { // create LOG.info("Create training job by Job REST API"); PostMethod postMethod = httpPost(BASE_API_PATH, body, contentType); Assert.assertEquals(Response.Status.OK.getStatusCode(), postMethod.getStatusCode()); String json = postMethod.getResponseBodyAsString(); JsonResponse jsonResponse = gson.fromJson(json, JsonResponse.class); Assert.assertEquals(Response.Status.OK.getStatusCode(), jsonResponse.getCode()); Experiment createdExperiment = gson.fromJson(gson.toJson(jsonResponse.getResult()), Experiment.class); verifyCreateJobApiResult(createdExperiment); // find GetMethod getMethod = httpGet(BASE_API_PATH + "/" + createdExperiment.getExperimentId().toString()); Assert.assertEquals(Response.Status.OK.getStatusCode(), getMethod.getStatusCode()); json = getMethod.getResponseBodyAsString(); jsonResponse = gson.fromJson(json, JsonResponse.class); Assert.assertEquals(Response.Status.OK.getStatusCode(), jsonResponse.getCode()); Experiment foundExperiment = gson.fromJson(gson.toJson(jsonResponse.getResult()), Experiment.class); verifyGetJobApiResult(createdExperiment, foundExperiment); // get log list // TODO(JohnTing): Test the job log after creating the job // patch // TODO(jiwq): the commons-httpclient not support patch method // https://tools.ietf.org/html/rfc5789 // delete DeleteMethod deleteMethod = httpDelete(BASE_API_PATH + "/" + createdExperiment.getExperimentId().toString()); Assert.assertEquals(Response.Status.OK.getStatusCode(), deleteMethod.getStatusCode()); json = deleteMethod.getResponseBodyAsString(); jsonResponse = gson.fromJson(json, JsonResponse.class); Assert.assertEquals(Response.Status.OK.getStatusCode(), jsonResponse.getCode()); Experiment deletedExperiment = gson.fromJson(gson.toJson(jsonResponse.getResult()), Experiment.class); verifyDeleteJobApiResult(createdExperiment, deletedExperiment); }