Example usage for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod

List of usage examples for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods DeleteMethod DeleteMethod.

Prototype

public DeleteMethod(String paramString) 

Source Link

Usage

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized Object deleteForObject(String uri, Map<String, String> paramMap) {
    Object responseObject = new Object();

    HttpMethod httpMethod = new DeleteMethod(uri);

    if ((null != paramMap) && (!paramMap.isEmpty())) {
        httpMethod.setQueryString(getNameValuePair(paramMap));
    }//from w  ww.j  av a 2  s.co m

    Yaml yaml = new Yaml();

    HttpClient client = new HttpClient();
    InputStream responseStream = null;
    Reader inputStreamReader = null;

    try {
        int responseCode = client.executeMethod(httpMethod);

        if (HttpStatus.SC_OK != responseCode) {
            logger.error("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.error("[ METHOD   ] " + httpMethod.getName());
            logger.error("[ STATUS   ] " + responseCode);
        } else {
            logger.trace("[ REQUEST  ] " + httpMethod.getURI().toString());
            logger.trace("[ METHOD   ] " + httpMethod.getName());
            logger.trace("[ STATUS   ] " + responseCode);
        }

        responseStream = httpMethod.getResponseBodyAsStream();
        inputStreamReader = new InputStreamReader(responseStream, VideoRecorderServiceConstants.UTF);
        responseObject = yaml.load(inputStreamReader);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } finally {
        cleanUp(inputStreamReader, responseStream, httpMethod);
    }

    return responseObject;
}

From source file:com.atlassian.jira.web.action.setup.SetupProductBundleHelper.java

public void destroySession() {
    final HttpClient httpClient = prepareClient();
    final DeleteMethod method = new DeleteMethod(getAuthenticationUrl());
    method.setRequestHeader("Content-Type", "application/json");

    try {//  w w  w.  j  a v  a 2  s.  co  m
        httpClient.executeMethod(method);
    } catch (final IOException e) {
        log.warn("Problem with destroying session during product bundle license installation", e);
    } finally {
        method.releaseConnection();
        removeCookies();
        clearWebSudoToken();
    }
}

From source file:edu.ucsb.eucalyptus.cloud.ws.HttpTransfer.java

public HttpMethodBase constructHttpMethod(String verb, String addr, String eucaOperation, String eucaHeader) {
    String date = new Date().toString();
    String httpVerb = verb;//from ww w. j  a va2  s  .  com
    String addrPath;
    try {
        java.net.URI addrUri = new URL(addr).toURI();
        addrPath = addrUri.getPath().toString();
        String query = addrUri.getQuery();
        if (query != null) {
            addrPath += "?" + query;
        }
    } catch (Exception ex) {
        LOG.error(ex, ex);
        return null;
    }
    String data = httpVerb + "\n" + date + "\n" + addrPath + "\n";

    HttpMethodBase method = null;
    if (httpVerb.equals("PUT")) {
        method = new PutMethodWithProgress(addr);
    } else if (httpVerb.equals("DELETE")) {
        method = new DeleteMethod(addr);
    } else {
        method = new GetMethod(addr);
    }
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", date);
    //method.setRequestHeader("Expect", "100-continue");
    method.setRequestHeader(StorageProperties.EUCALYPTUS_OPERATION, eucaOperation);
    if (eucaHeader != null) {
        method.setRequestHeader(StorageProperties.EUCALYPTUS_HEADER, eucaHeader);
    }
    try {
        PrivateKey ccPrivateKey = SystemCredentials.lookup(Storage.class).getPrivateKey();
        Signature sign = Signature.getInstance("SHA1withRSA");
        sign.initSign(ccPrivateKey);
        sign.update(data.getBytes());
        byte[] sig = sign.sign();

        method.setRequestHeader("EucaSignature", new String(Base64.encode(sig)));
    } catch (Exception ex) {
        LOG.error(ex, ex);
    }
    return method;
}

From source file:liveplugin.toolwindow.addplugin.git.jetbrains.plugins.github.api.GithubApiUtil.java

@NotNull
private static HttpMethod doREST(@NotNull final GithubAuthData auth, @NotNull final String uri,
        @Nullable final String requestBody, @NotNull final Collection<Header> headers,
        @NotNull final HttpVerb verb) throws IOException {
    HttpClient client = getHttpClient(auth.getBasicAuth(), auth.isUseProxy());
    return GithubSslSupport.getInstance().executeSelfSignedCertificateAwareRequest(client, uri,
            new ThrowableConvertor<String, HttpMethod, IOException>() {
                @Override//from   w ww  .ja  va2s. c o m
                public HttpMethod convert(String uri) throws IOException {
                    HttpMethod method;
                    switch (verb) {
                    case POST:
                        method = new PostMethod(uri);
                        if (requestBody != null) {
                            ((PostMethod) method).setRequestEntity(
                                    new StringRequestEntity(requestBody, "application/json", "UTF-8"));
                        }
                        break;
                    case GET:
                        method = new GetMethod(uri);
                        break;
                    case DELETE:
                        method = new DeleteMethod(uri);
                        break;
                    case HEAD:
                        method = new HeadMethod(uri);
                        break;
                    default:
                        throw new IllegalStateException("Wrong HttpVerb: unknown method: " + verb.toString());
                    }
                    GithubAuthData.TokenAuth tokenAuth = auth.getTokenAuth();
                    if (tokenAuth != null) {
                        method.addRequestHeader("Authorization", "token " + tokenAuth.getToken());
                    }
                    for (Header header : headers) {
                        method.addRequestHeader(header);
                    }
                    return method;
                }
            });
}

From source file:com.linkedin.pinot.common.utils.SchemaUtils.java

/**
 * 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.
 *//*from  ww w  .  java 2s.com*/
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;
    }
}

From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java

@Override
public HttpResponse delete(String path, Map<String, String> headers, int timeoutMillis)
        throws HttpClientException {
    return executeMethod(new DeleteMethod(path), headers, timeoutMillis);
}

From source file:de.mpg.escidoc.http.UserGroup.java

public Boolean deleteUserGroup() {
    String userGroupID = Util.input("ID of the UserGroup to be deleted: ");
    // String userGroupID = "escidoc:27001";
    if (this.USER_HANDLE != null) {
        DeleteMethod delete = new DeleteMethod(FRAMEWORK_URL + "/aa/user-group/" + userGroupID);
        delete.setRequestHeader("Cookie", "escidocCookie=" + this.USER_HANDLE);
        try {//from   w w w . j  a v a 2 s  .c  om
            this.client.executeMethod(delete);
            if (delete.getStatusCode() != 200) {
                System.out.println("Server StatusCode: " + delete.getStatusCode());
                return false;
            }
            System.out.println("Usergroup " + userGroupID + " deleted");
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("Error in deleteUserGroup: No userHandle available");
    }
    return true;
}

From source file:com.assemblade.client.AbstractClient.java

protected void delete(String path) throws ClientException {
    DeleteMethod delete = new DeleteMethod(baseUrl + path);
    try {/*from ww w. jav a 2  s  . co m*/
        int statusCode = executeMethod(delete);
        if (statusCode != 204) {
            throw new InvalidStatusException(204, statusCode);
        }
    } finally {
        delete.releaseConnection();
    }
}

From source file:com.kodokux.github.api.GithubApiUtil.java

@NotNull
private static HttpMethod doREST(@NotNull final GithubAuthData auth, @NotNull final String uri,
        @Nullable final String requestBody, @NotNull final Collection<Header> headers,
        @NotNull final HttpVerb verb) throws IOException {
    HttpClient client = getHttpClient(auth.getBasicAuth(), auth.isUseProxy());
    HttpMethod method;//w  w w . ja va 2  s. c  o  m
    switch (verb) {
    case POST:
        method = new PostMethod(uri);
        if (requestBody != null) {
            ((PostMethod) method)
                    .setRequestEntity(new StringRequestEntity(requestBody, "application/json", "UTF-8"));
        }
        break;
    case GET:
        method = new GetMethod(uri);
        break;
    case DELETE:
        method = new DeleteMethod(uri);
        break;
    case HEAD:
        method = new HeadMethod(uri);
        break;
    default:
        throw new IllegalStateException("Wrong HttpVerb: unknown method: " + verb.toString());
    }
    GithubAuthData.TokenAuth tokenAuth = auth.getTokenAuth();
    if (tokenAuth != null) {
        method.addRequestHeader("Authorization", "token " + tokenAuth.getToken());
    }
    for (Header header : headers) {
        method.addRequestHeader(header);
    }

    client.executeMethod(method);
    return method;
}

From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java

@Override
public HttpStreamResponse deleteStream(String path, int timeoutMillis) throws HttpClientException {
    return executeMethodStream(new DeleteMethod(path), timeoutMillis);
}