本文整理汇总了Java中org.apache.commons.httpclient.methods.DeleteMethod.getResponseBodyAsString方法的典型用法代码示例。如果您正苦于以下问题:Java DeleteMethod.getResponseBodyAsString方法的具体用法?Java DeleteMethod.getResponseBodyAsString怎么用?Java DeleteMethod.getResponseBodyAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.DeleteMethod
的用法示例。
在下文中一共展示了DeleteMethod.getResponseBodyAsString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doDelete
import org.apache.commons.httpclient.methods.DeleteMethod; //导入方法依赖的package包/类
/**
* 处理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);
}
示例2: deleteSchema
import org.apache.commons.httpclient.methods.DeleteMethod; //导入方法依赖的package包/类
/**
* 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;
}
}
示例3: deleteSite
import org.apache.commons.httpclient.methods.DeleteMethod; //导入方法依赖的package包/类
/**
* Deletes site using REST API, http method is sent to appropriate web script
*
* @param user current user
* @param shortName shortName of site we are going to delete
* @throws HttpException
* @throws IOException
*/
public void deleteSite(SessionUser user, String shortName) throws HttpException, IOException
{
HttpClient httpClient = new HttpClient();
DeleteMethod deleteSiteMethod = new DeleteMethod(getAlfrescoHostWithPort() + getAlfrescoContext() + "/s/api/sites/" + shortName + "?alf_ticket=" + user.getTicket());
try
{
if (logger.isDebugEnabled())
logger.debug("Trying to delete site with name: " + shortName);
int status = httpClient.executeMethod(deleteSiteMethod);
if (logger.isDebugEnabled())
logger.debug("Delete site method returned status: " + status);
if (status != HttpStatus.SC_OK)
{
throw new RuntimeException("Failed to delete site with name: " + shortName + ". Returned status is: " + status +
". \n Response from server :\n" + deleteSiteMethod.getResponseBodyAsString());
}
deleteSiteMethod.getResponseBody();
}
catch (Exception e)
{
if (logger.isDebugEnabled())
logger.debug("Fail to delete site with name: " + shortName);
throw new RuntimeException(e);
}
finally
{
deleteSiteMethod.releaseConnection();
}
// deletes site dashboard
deleteSiteDashboard(httpClient, shortName, user);
// deletes title component
deleteSiteComponent(httpClient, shortName, user, "title");
// deletes navigation component
deleteSiteComponent(httpClient, shortName, user, "navigation");
// deletes component-2-2 component
deleteSiteComponent(httpClient, shortName, user, "component-2-2");
// deletes component-1-1 component
deleteSiteComponent(httpClient, shortName, user, "component-1-1");
// deletes component-2-1 component
deleteSiteComponent(httpClient, shortName, user, "component-2-1");
// deletes component-1-2 component
deleteSiteComponent(httpClient, shortName, user, "component-1-2");
}