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

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

Introduction

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

Prototype

@Override
public int getStatusCode() 

Source Link

Document

Returns the response status code.

Usage

From source file:net.bioclipse.opentox.api.Task.java

public static void delete(String task) throws IOException, GeneralSecurityException {
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(task);
    method.getParams().setParameter("http.socket.timeout", new Integer(Activator.TIME_OUT));
    client.executeMethod(method);// w w  w  .  j av  a 2  s.c  o m
    int status = method.getStatusCode();
    switch (status) {
    case 200:
        // excellent, it worked
        break;
    case 401:
        throw new GeneralSecurityException("Not authorized");
    case 404:
        // not found, well, I guess equals 'deleted'
        break;
    case 503:
        throw new IOException("Service unavailable");
    default:
        throw new IOException("Unknown server state: " + status);
    }
}

From source file:net.bioclipse.opentox.api.Dataset.java

public static void deleteDataset(String datasetURI) throws Exception {
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(datasetURI);
    HttpMethodHelper.addMethodHeaders(method, null);
    client.executeMethod(method);//from  www. ja v a  2  s .  c  om
    int status = method.getStatusCode();
    method.releaseConnection();
    if (status == 404)
        throw new IllegalArgumentException("Dataset does not exist.");
    if (status == 503)
        throw new IllegalStateException("Service error: " + status);
}

From source file:com.agile_coder.poker.server.stories.steps.ResetEstimatesSteps.java

@When("I reset the estimates")
public void reset() throws IOException {
    HttpClient client = new HttpClient();
    DeleteMethod delete = new DeleteMethod(BASE_URL + "/" + sessionId + "/status");
    client.executeMethod(delete);/*from   w w w.j  a  va  2s  .c om*/
    assertEquals(HttpStatus.SC_NO_CONTENT, delete.getStatusCode());
}

From source file:com.wandisco.s3hdfs.rewrite.redirect.MultiPartFileRedirect.java

public void sendComplete() throws IOException, ServletException {
    //STEP 1. Get listing of .part's.
    GetMethod httpGet = (GetMethod) getHttpMethod(request.getScheme(), request.getServerName(),
            request.getServerPort(), "LISTSTATUS", path.getUserName(),
            ADD_WEBHDFS(path.getHdfsRootUploadPath()), GET);
    httpClient.executeMethod(httpGet);/*from   w  ww.ja v a 2s  .c om*/

    // STEP 2. Parse sources from listing.
    String sourceStr = readInputStream(httpGet.getResponseBodyAsStream());

    List<String> sources = parseSources(path.getHdfsRootUploadPath(), sourceStr);
    httpGet.releaseConnection();
    assert httpGet.getStatusCode() == 200;

    //STEP 3. Perform concatenation of other .part's into 1.part.
    if (sources.size() > 1) {
        Collections.sort(sources, new PartComparator(path.getHdfsRootUploadPath()));
        if (!partsAreInOrder(sources)) {
            response.setStatus(400);
            return;
        }
        doIncrementalConcat(sources);
    }

    //STEP 3. Rename concat'd 1.part as .obj
    PutMethod httpPut = (PutMethod) getHttpMethod(request.getScheme(), request.getServerName(),
            request.getServerPort(), "RENAME&destination=" + path.getFullHdfsObjPath(), path.getUserName(),
            ADD_WEBHDFS(path.getHdfsRootUploadPath() + "1" + PART_FILE_NAME), PUT);
    httpClient.executeMethod(httpPut);
    httpPut.releaseConnection();
    assert httpPut.getStatusCode() == 200;

    //STEP 4. Delete upload directory
    DeleteMethod httpDelete = (DeleteMethod) getHttpMethod(request.getScheme(), request.getServerName(),
            request.getServerPort(), "DELETE", path.getUserName(), path.getHdfsRootUploadPath(), DELETE);
    httpClient.executeMethod(httpDelete);
    httpDelete.releaseConnection();
    assert httpDelete.getStatusCode() == 200;
}

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

public void executeDeleteObject(final String uri) throws CloudstackRESTException {
    final DeleteMethod dm = (DeleteMethod) createMethod(DELETE_METHOD_TYPE, uri);
    dm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);

    executeMethod(dm);//  w w w .  j  a va2 s .  c om

    if (dm.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
        final String errorMessage = responseToErrorMessage(dm);
        dm.releaseConnection();
        s_logger.error("Failed to delete object : " + errorMessage);
        throw new CloudstackRESTException("Failed to delete object : " + errorMessage);
    }
    dm.releaseConnection();
}

From source file:com.cloud.network.bigswitch.BigSwitchVnsApi.java

protected void executeDeleteObject(String uri) throws BigSwitchVnsApiException {
    if (_host == null || _host.isEmpty()) {
        throw new BigSwitchVnsApiException("Hostname is null or empty");
    }/*from  w  ww.  j a  v  a2  s. c  o  m*/

    DeleteMethod dm = (DeleteMethod) createMethod("delete", uri, 80);
    dm.setRequestHeader(CONTENT_TYPE, CONTENT_JSON);
    dm.setRequestHeader(ACCEPT, CONTENT_JSON);
    dm.setRequestHeader(HTTP_HEADER_INSTANCE_ID, CLOUDSTACK_INSTANCE_ID);

    executeMethod(dm);

    if (dm.getStatusCode() != HttpStatus.SC_OK) {
        String errorMessage = responseToErrorMessage(dm);
        dm.releaseConnection();
        s_logger.error("Failed to delete object : " + errorMessage);
        throw new BigSwitchVnsApiException("Failed to delete object : " + errorMessage);
    }
    dm.releaseConnection();
}

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 o m*/
            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.cloud.network.nicira.NiciraNvpApi.java

private void executeDeleteObject(String uri) throws NiciraNvpApiException {
    String url;//from   w  ww .  j  a va  2  s. c om
    try {
        url = new URL(_protocol, _host, uri).toString();
    } catch (MalformedURLException e) {
        s_logger.error("Unable to build Nicira API URL", e);
        throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
    }

    DeleteMethod dm = new DeleteMethod(url);
    dm.setRequestHeader("Content-Type", "application/json");

    executeMethod(dm);

    if (dm.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
        String errorMessage = responseToErrorMessage(dm);
        dm.releaseConnection();
        s_logger.error("Failed to delete object : " + errorMessage);
        throw new NiciraNvpApiException("Failed to delete object : " + errorMessage);
    }
    dm.releaseConnection();
}

From source file:edu.northwestern.jcr.adapter.fedora.persistence.FedoraConnectorREST.java

/**
 * Sends an HTTP DELETE request and returns the status code.
 *
 * @param url URL of the resource// ww  w  . j  av a  2  s.co  m
 * @return status code
 */
private int httpDelete(String url) {
    DeleteMethod deleteMethod = null;

    try {
        deleteMethod = new DeleteMethod(url);
        deleteMethod.setDoAuthentication(true);
        deleteMethod.getParams().setParameter("Connection", "Keep-Alive");
        fc.getHttpClient().executeMethod(deleteMethod);

        return deleteMethod.getStatusCode();
    } catch (Exception e) {
        e.printStackTrace();
        log.warn("failed to delete!");

        return -1;
    } finally {
        if (deleteMethod != null) {
            deleteMethod.releaseConnection();
        }
    }
}

From source file:org.apache.cloudstack.network.element.SspClient.java

public boolean deleteTenantNetwork(String tenantNetworkUuid) {
    DeleteMethod method = deleteMethod;
    method.setPath("/ssp.v1/tenant-networks/" + tenantNetworkUuid);

    executeMethod(method);/*  w  w  w.  j  a  v  a  2 s  .  c o m*/
    if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
        return true;
    }
    return false;
}