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.rometools.propono.atom.client.ClientEntry.java

/**
 * Remove entry from server.// ww  w .ja v  a2 s .co  m
 */
public void remove() throws ProponoException {
    if (getEditURI() == null) {
        throw new ProponoException("ERROR: cannot delete unsaved entry");
    }
    final DeleteMethod method = new DeleteMethod(getEditURI());
    addAuthentication(method);
    try {
        getHttpClient().executeMethod(method);
    } catch (final IOException ex) {
        throw new ProponoException("ERROR: removing entry, HTTP code", ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java

/**
 * @see {@link GraphRepository#delete(String)}
 *//*from   w w  w.  ja  v a 2  s.c  om*/
public void delete(String rdfXml) throws Exception {

    // DELETE
    DeleteMethod del = new DeleteMethod(servletURL);
    try {

        // add the range header
        if (rdfXml != null) {
            String triples = "triples[" + trim(rdfXml) + "]";
            Header range = new Header(GraphRepositoryServlet.HTTP_RANGE, triples);
            del.addRequestHeader(range);
        }

        // Execute the method.
        int sc = getHttpClient().executeMethod(del);
        if (sc != HttpStatus.SC_OK) {
            throw new IOException("HTTP-DELETE failed: " + del.getStatusLine());
        }

    } finally {
        // Release the connection.
        del.releaseConnection();
    }

}

From source file:edu.htwm.vsp.phoebook.rest.client.RestClient.java

public void verifyDeleteNumber(String userID, String phoneCaption, int expectedStatusCode, String contentType)
        throws IOException {

    System.out.println("Deleing PhoneNumber: " + phoneCaption + " of phoneUser: " + userID + " ...\n");

    HttpClient client = new HttpClient();
    // -- build HTTP DELETE request
    DeleteMethod method = new DeleteMethod(
            getServiceBaseURI() + "/users" + "/" + userID + "/numbers/" + phoneCaption);
    int responseCode = client.executeMethod(method);

    assertEquals(expectedStatusCode, responseCode);

}

From source file:com.cloud.utils.rest.RESTServiceConnector.java

public HttpMethod createMethod(final String type, final String uri) throws CloudstackRESTException {
    String url;//from w w w.  j a va 2s .  com
    try {
        url = new URL(protocol, validation.getHost(), uri).toString();
    } catch (final MalformedURLException e) {
        s_logger.error("Unable to build REST Service URL", e);
        throw new CloudstackRESTException("Unable to build Nicira API URL", e);
    }

    if (POST_METHOD_TYPE.equalsIgnoreCase(type)) {
        return new PostMethod(url);
    } else if (GET_METHOD_TYPE.equalsIgnoreCase(type)) {
        return new GetMethod(url);
    } else if (DELETE_METHOD_TYPE.equalsIgnoreCase(type)) {
        return new DeleteMethod(url);
    } else if (PUT_METHOD_TYPE.equalsIgnoreCase(type)) {
        return new PutMethod(url);
    } else {
        throw new CloudstackRESTException("Requesting unknown method type");
    }
}

From source file:com.zimbra.cs.mailbox.MailboxTestUtil.java

public static void cleanupIndexStore(Mailbox mbox) {
    IndexStore index = mbox.index.getIndexStore();
    if (index instanceof ElasticSearchIndex) {
        String key = mbox.getAccountId();
        String indexUrl = String.format("%s%s/", LC.zimbra_index_elasticsearch_url_base.value(), key);
        HttpMethod method = new DeleteMethod(indexUrl);
        try {// w  w  w . j a v  a 2  s.c  om
            ElasticSearchConnector connector = new ElasticSearchConnector();
            int statusCode = connector.executeMethod(method);
            if (statusCode == HttpStatus.SC_OK) {
                boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false);
                boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false);
                if (!ok || !acknowledged) {
                    ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged);
                }
            } else {
                String error = connector.getStringAtJsonPath(new String[] { "error" });
                if (error != null && error.startsWith("IndexMissingException")) {
                    ZimbraLog.index.debug("Unable to delete index for key=%s.  Index is missing", key);
                } else {
                    ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error);
                }
            }
        } catch (HttpException e) {
            ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
        } catch (IOException e) {
            ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
        }
    }
}

From source file:com.moss.bdbadmin.client.service.BdbClient.java

public void delete(IdProof assertion, String path) throws ServiceException {
    try {/*from w ww.j a va  2  s  .  co m*/
        DeleteMethod method = new DeleteMethod(baseUrl + "/" + path);
        method.setRequestHeader(AuthenticationHeader.HEADER_NAME, AuthenticationHeader.encode(assertion));

        int result = httpClient.executeMethod(method);
        if (result != 200) {
            throw new ServiceException(result);
        }
    } catch (IOException ex) {
        throw new ServiceFailure(ex);
    }
}

From source file:com.intuit.tank.http.BaseRequest.java

/**
 * Execute the delete request.//from  w  ww .j  a va 2 s .  com
 * 
 * @param response
 *            The response object to populate
 */
public void doDelete(BaseResponse response) {
    DeleteMethod httpdelete = null;
    try {
        URL url = BaseRequestHandler.buildUrl(protocol, host, port, path, urlVariables);
        httpdelete = new DeleteMethod(url.toString());
        String requestBody = this.getBody(); // Multiple calls can be
                                             // expensive, so get it once
        String type = headerInformation.get("Content-Type");
        if (StringUtils.isBlank(type)) {
            headerInformation.put("Content-Type", "application/x-www-form-urlencoded");
        }
        sendRequest(response, httpdelete, requestBody);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        if (null != httpdelete)
            httpdelete.releaseConnection();
    }
}

From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java

/**
 * @see {@link GraphRepository#delete(String, QueryLanguage)}
 */// w  w w . java 2  s.c  o m
public void delete(String query, QueryLanguage ql) throws Exception {

    if (query == null || ql == null) {
        return;

    }
    // DELETE
    DeleteMethod del = new DeleteMethod(servletURL);

    try {

        // add the header for the query
        if (query != null) {
            query = ql.toString().toLowerCase() + "[" + trim(query) + "]";
            String rangeHeader = "query[" + query + "]";
            Header range = new Header(GraphRepositoryServlet.HTTP_RANGE, rangeHeader);
            del.addRequestHeader(range);
        }

        // Execute the method.
        int sc = getHttpClient().executeMethod(del);
        if (sc != HttpStatus.SC_OK) {
            throw new IOException("HTTP-DELETE failed: " + del.getStatusLine());
        }

    } finally {
        // Release the connection.
        del.releaseConnection();
    }

}

From source file:com.nextcloud.android.sso.InputStreamBinder.java

private InputStream processRequest(final NextcloudRequest request) throws UnsupportedOperationException,
        com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException,
        OperationCanceledException, AuthenticatorException, IOException {
    Account account = AccountUtils.getOwnCloudAccountByName(context, request.getAccountName()); // TODO handle case that account is not found!
    if (account == null) {
        throw new IllegalStateException(EXCEPTION_ACCOUNT_NOT_FOUND);
    }//  www  . ja va2s .c o  m

    // Validate token
    if (!isValid(request)) {
        throw new IllegalStateException(EXCEPTION_INVALID_TOKEN);
    }

    // Validate URL
    if (request.getUrl().length() == 0 || request.getUrl().charAt(0) != PATH_SEPARATOR) {
        throw new IllegalStateException(EXCEPTION_INVALID_REQUEST_URL,
                new IllegalStateException("URL need to start with a /"));
    }

    OwnCloudClientManager ownCloudClientManager = OwnCloudClientManagerFactory.getDefaultSingleton();
    OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
    OwnCloudClient client = ownCloudClientManager.getClientFor(ocAccount, context);

    String requestUrl = client.getBaseUri() + request.getUrl();
    HttpMethodBase method;

    switch (request.getMethod()) {
    case "GET":
        method = new GetMethod(requestUrl);
        break;

    case "POST":
        method = new PostMethod(requestUrl);
        if (request.getRequestBody() != null) {
            StringRequestEntity requestEntity = new StringRequestEntity(request.getRequestBody(),
                    CONTENT_TYPE_APPLICATION_JSON, CHARSET_UTF8);
            ((PostMethod) method).setRequestEntity(requestEntity);
        }
        break;

    case "PUT":
        method = new PutMethod(requestUrl);
        if (request.getRequestBody() != null) {
            StringRequestEntity requestEntity = new StringRequestEntity(request.getRequestBody(),
                    CONTENT_TYPE_APPLICATION_JSON, CHARSET_UTF8);
            ((PutMethod) method).setRequestEntity(requestEntity);
        }
        break;

    case "DELETE":
        method = new DeleteMethod(requestUrl);
        break;

    default:
        throw new UnsupportedOperationException(EXCEPTION_UNSUPPORTED_METHOD);

    }

    method.setQueryString(convertMapToNVP(request.getParameter()));
    method.addRequestHeader("OCS-APIREQUEST", "true");

    client.setFollowRedirects(request.isFollowRedirects());
    int status = client.executeMethod(method);

    // Check if status code is 2xx --> https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success
    if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) {
        return method.getResponseBodyAsStream();
    } else {
        throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED,
                new IllegalStateException(String.valueOf(status)));
    }
}

From source file:com.cubeia.backoffice.users.client.UserServiceClientHTTP.java

@Override
public void invalidateSessionToken(Long userId) {
    // Create a method instance.
    String resource = String.format(baseUrl + USER_SESSION, userId);
    DeleteMethod method = new DeleteMethod(resource);

    try {/*from  w ww  .  j ava  2s.c o m*/
        // Execute the method.
        int statusCode = getClient().executeMethod(method);
        assertResponseCodeOK(method, statusCode);

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}