當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpDelete類代碼示例

本文整理匯總了Java中org.apache.http.client.methods.HttpDelete的典型用法代碼示例。如果您正苦於以下問題:Java HttpDelete類的具體用法?Java HttpDelete怎麽用?Java HttpDelete使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpDelete類屬於org.apache.http.client.methods包,在下文中一共展示了HttpDelete類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testIntegrityUnicityError

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
/**
 * @see ExceptionMapperResource#throwDataIntegrityUnicityException()
 */
@Test
public void testIntegrityUnicityError() throws IOException {
	final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/integrity-unicity");
	HttpResponse response = null;
	try {
		response = httpclient.execute(httpdelete);
		Assert.assertEquals(HttpStatus.SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
		final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
		final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
		Assert.assertEquals("integrity-unicity", result.get("code"));
		Assert.assertNull(result.get("cause"));
		Assert.assertEquals("2003/PRIMARY", result.get("message"));
	} finally {
		if (response != null) {
			response.getEntity().getContent().close();
		}
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:22,代碼來源:ExceptionMapperIT.java

示例2: delete

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
private void delete(String url) throws IOException, HttpException {
	CredentialsProvider credentials = credentialsProvider();
	CloseableHttpClient httpclient = HttpClients.custom()
               .setDefaultCredentialsProvider(credentials)
               .build();

	try {
		HttpDelete httpDelete = new HttpDelete(url);
 		httpDelete.setHeader("Accept", "application/json");
	        
	    System.out.println("Executing request " + httpDelete.getRequestLine());
	    CloseableHttpResponse response = httpclient.execute(httpDelete);
	    try {
	        LOG.debug("----------------------------------------");
	        LOG.debug((String)response.getStatusLine().getReasonPhrase());
	    } finally {
	        response.close();
	    }
	} finally {
	    httpclient.close();
	}
}
 
開發者ID:dellemc-symphony,項目名稱:ticketing-service-paqx-parent-sample,代碼行數:23,代碼來源:TicketingIntegrationService.java

示例3: sendHttpDelete

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
@Override
public CloseableHttpResponse sendHttpDelete(String url, List<Header> headers) {
    CloseableHttpResponse execute = null;
    try {
        LOGGER.info("Sending GET request to url-" + url);
        CloseableHttpClient httpClient = this.httpClientFactory.getHttpClient();
        HttpDelete httpDelete = new HttpDelete(url);
        if (headers != null && !headers.isEmpty()) {
            for (Header header : headers) {
                httpDelete.addHeader(header);
            }
        }
        execute = httpClient.execute(httpDelete);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Was unable to send Get request to url-" + url, e);
    }

    return execute;
}
 
開發者ID:SoftGorilla,項目名稱:restheart-java-client,代碼行數:20,代碼來源:HttpConnectionUtils.java

示例4: sendDeleteCommand

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
/**
 * sendDeleteCommand
 *
 * @param url
 * @return
 */
public Map<String, String> sendDeleteCommand(String url, Map<String, Object> credentials)
        throws ManagerResponseException {
    Map<String, String> response = new HashMap<String, String>();
    CloseableHttpClient httpclient = HttpClients.createDefault();

    HttpDelete httpDelete = new HttpDelete(url);
    CloseableHttpResponse httpResponse;
    try {
        httpResponse = httpclient.execute(httpDelete, localContext);
        ResponseHandler<String> handler = new CustomResponseErrorHandler();
        String body = handler.handleResponse(httpResponse);
        response.put("body", body);
        httpResponse.close();
    } catch (Exception e) {
        throw new ManagerResponseException(e.getMessage(), e);
    }

    return response;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:26,代碼來源:RestUtils.java

示例5: sendDelete

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
public DockerResponse sendDelete(URI uri, Boolean httpRequired) throws JSONClientException {

        if (logger.isDebugEnabled()) {
            logger.debug("Send a delete request to : " + uri);
        }
        CloseableHttpResponse response = null;
        try {
            CloseableHttpClient httpClient = buildSecureHttpClient();
            HttpDelete httpDelete = new HttpDelete(uri);
            response = httpClient.execute(httpDelete);
        } catch (IOException e) {
            throw new JSONClientException("Error in sendDelete method due to : " + e.getMessage(), e);
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Status code : " + response.getStatusLine().getStatusCode());
        }

        return new DockerResponse(response.getStatusLine().getStatusCode(), "");
    }
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:21,代碼來源:JSONClient.java

示例6: assertNotFound

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
private void assertNotFound(final String path, final String message) throws IOException, ClientProtocolException, JsonParseException, JsonMappingException {
	final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + path);
	HttpResponse response = null;
	try {
		response = httpclient.execute(httpdelete);
		Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
		final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
		final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
		Assert.assertEquals("entity", result.get("code"));
		Assert.assertEquals(message, result.get("message"));
		Assert.assertNull(result.get("cause"));
	} finally {
		if (response != null) {
			response.getEntity().getContent().close();
		}
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:18,代碼來源:ExceptionMapperIT.java

示例7: testCannotAcquireLockException

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
/**
 * @see ExceptionMapperResource#throwCannotAcquireLockException()
 */
@Test
public void testCannotAcquireLockException() throws IOException {
	final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/cannotAcquireLockException");
	HttpResponse response = null;
	try {
		response = httpclient.execute(httpdelete);
		Assert.assertEquals(HttpStatus.SC_CONFLICT, response.getStatusLine().getStatusCode());
		final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
		final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
		Assert.assertEquals("database-lock", result.get("code"));
		Assert.assertNull(result.get("message"));
		Assert.assertNull(result.get("cause"));
	} finally {
		if (response != null) {
			response.getEntity().getContent().close();
		}
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:22,代碼來源:ExceptionMapperIT.java

示例8: getRequest

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
private HttpRequestBase getRequest(String url){
	switch(method){
	case DELETE:
		return new HttpDelete(url);
	case GET:
		return new HttpGet(url);
	case HEAD:
		return new HttpHead(url);
	case PATCH:
		return new HttpPatch(url);
	case POST:
		return new HttpPost(url);
	case PUT:
		return new HttpPut(url);
	default:
		throw new IllegalArgumentException("Invalid or null HttpMethod: " + method);
	}
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:19,代碼來源:DatarouterHttpRequest.java

示例9: createApacheRequest

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
private HttpRequestBase createApacheRequest(SdkHttpFullRequest request, String uri) {
    switch (request.method()) {
        case HEAD:
            return new HttpHead(uri);
        case GET:
            return new HttpGet(uri);
        case DELETE:
            return new HttpDelete(uri);
        case OPTIONS:
            return new HttpOptions(uri);
        case PATCH:
            return wrapEntity(request, new HttpPatch(uri));
        case POST:
            return wrapEntity(request, new HttpPost(uri));
        case PUT:
            return wrapEntity(request, new HttpPut(uri));
        default:
            throw new RuntimeException("Unknown HTTP method name: " + request.method());
    }
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:21,代碼來源:ApacheHttpRequestFactory.java

示例10: delete

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
static Request delete(DeleteRequest deleteRequest) {
    String endpoint = endpoint(deleteRequest.index(), deleteRequest.type(), deleteRequest.id());

    Params parameters = Params.builder();
    parameters.withRouting(deleteRequest.routing());
    parameters.withParent(deleteRequest.parent());
    parameters.withTimeout(deleteRequest.timeout());
    parameters.withVersion(deleteRequest.version());
    parameters.withVersionType(deleteRequest.versionType());
    parameters.withRefreshPolicy(deleteRequest.getRefreshPolicy());
    parameters.withWaitForActiveShards(deleteRequest.waitForActiveShards());

    return new Request(HttpDelete.METHOD_NAME, endpoint, parameters.getParams(), null);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:Request.java

示例11: doDelete

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
@Override
public Response doDelete(final URL url, final Set<RequestHeader> headers) throws IOException {
    final HttpDelete request = new HttpDelete(url.toString());
    for(RequestHeader header : headers) {
        if(header.getKey().equals(HTTP.TRANSFER_ENCODING)) {
            continue;
        }
        if(header.getKey().equals(HTTP.CONTENT_LEN)) {
            continue;
        }
        request.addHeader(new BasicHeader(header.getKey(), header.getValue()));
    }
    final CloseableHttpResponse response = client.execute(request);
    return new CommonsHttpResponse(response);
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:16,代碼來源:OneDriveCommonsHttpRequestExecutor.java

示例12: deleteRESTUser

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
public static void deleteRESTUser(String usrName){
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/manage/v2/users/"+usrName);

		HttpResponse response = client.execute(delete);
		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(3500);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}

}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:21,代碼來源:ConnectedRESTQA.java

示例13: deleteUserRole

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
public static void deleteUserRole(String roleName){
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/manage/v2/roles/"+roleName);

		HttpResponse response = client.execute(delete);
		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(3500);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}

}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:21,代碼來源:ConnectedRESTQA.java

示例14: deleteRESTServerWithDB

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
public static void deleteRESTServerWithDB(String restServerName)	{
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/v1/rest-apis/"+restServerName+"?include=content&include=modules");

		HttpResponse response = client.execute(delete);
		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(9500);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}
}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:20,代碼來源:ConnectedRESTQA.java

示例15: deleteRESTServer

import org.apache.http.client.methods.HttpDelete; //導入依賴的package包/類
public static void deleteRESTServer(String restServerName)	{
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/v1/rest-apis/"+restServerName+"&include=modules");
		HttpResponse response = client.execute(delete);

		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(3500);
			waitForServerRestart();
		}
		else System.out.println("Server response "+response.getStatusLine().getStatusCode());
	}catch (Exception e) {
		// writing error to Log
		System.out.println("Inside Deleting Rest server is throwing an error");
		e.printStackTrace();
	}
}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:23,代碼來源:ConnectedRESTQA.java


注:本文中的org.apache.http.client.methods.HttpDelete類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。