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

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

Introduction

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

Prototype

@Override
public void releaseConnection() 

Source Link

Document

Releases the connection being used by this HTTP method.

Usage

From source file:demo.jaxrs.search.client.Client.java

private static void delete(final String url, final HttpClient httpClient) throws IOException, HttpException {

    System.out.println("Sent HTTP DELETE request to remove all books from catalog");

    final DeleteMethod delete = new DeleteMethod(url);
    try {/*from   w  w w .  ja  v a 2  s  . c om*/
        int status = httpClient.executeMethod(delete);
        if (status == 200) {
            System.out.println(delete.getResponseBodyAsString());
        }
    } finally {
        delete.releaseConnection();
    }
}

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);//  ww  w .jav a2s.  com
    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.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.
 *//*ww w  .j  a  va  2s .c  o  m*/
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:edu.stanford.epad.epadws.xnat.XNATSessionOperations.java

public static int invalidateXNATSessionID(HttpServletRequest httpRequest) {
    String xnatSessionURL = buildXNATSessionURL();
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(xnatSessionURL);
    String jsessionID = getJSessionIDFromRequest(httpRequest);
    int xnatStatusCode;

    method.setRequestHeader("Cookie", "JSESSIONID=" + jsessionID);

    try {/*from  ww  w .  j  a v  a 2s .c o m*/
        xnatStatusCode = client.executeMethod(method);
    } catch (IOException e) {
        log.warning("Error calling XNAT session service to invalidate session ID", e);
        xnatStatusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    } finally {
        method.releaseConnection();
    }

    if (xnatStatusCode != HttpServletResponse.SC_OK)
        log.warning("XNAT delete session call returned status code " + xnatStatusCode);

    return xnatStatusCode;
}

From source file:gov.tva.sparky.hbase.RestProxy.java

public static boolean DeleteHbaseRow(String strTablename, String strRowKey) throws URIException {

    Configuration conf = new Configuration(false);
    conf.addResource("hadoop-default.xml");
    conf.addResource("sparky-site.xml");

    int port = conf.getInt("sparky.hbase.restPort", 8092);
    String uri = conf.get("sparky.hbase.restURI", "http://socdvmhbase");

    boolean bResult = false;

    BufferedReader br = null;/*from  w w  w.j a  v a 2  s. c o  m*/
    HttpClient client = new HttpClient();

    String strRestPath = uri + ":" + port + "/" + strTablename + "/" + strRowKey;

    DeleteMethod delete_method = new DeleteMethod(strRestPath);

    try {

        int returnCode = client.executeMethod(delete_method);

        if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {

            System.out.println("The Post method is not implemented by this URI");

        } else {

            bResult = true;

        }
    } catch (Exception e) {
        System.out.println(e);
    } finally {
        delete_method.releaseConnection();
        if (br != null)
            try {
                br.close();
            } catch (Exception fe) {
            }
    }

    return bResult;

}

From source file:edu.stanford.epad.epadws.xnat.XNATDeletionOperations.java

public static int deleteXNATProject(String xnatProjectLabelOrID, String jsessionID) {
    String xnatProjectDeleteURL = XNATUtil.buildXNATProjectDeletionURL(xnatProjectLabelOrID);
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(xnatProjectDeleteURL);
    int xnatStatusCode;

    method.setRequestHeader("Cookie", "JSESSIONID=" + jsessionID);

    try {//  w w  w. j  av a2  s.  c  o  m
        log.info("Invoking XNAT with URL " + xnatProjectDeleteURL);
        xnatStatusCode = client.executeMethod(method);
        if (unexpectedDeletionStatusCode(xnatStatusCode))
            log.warning("Failure calling XNAT to delete project; status code = " + xnatStatusCode);
        else {
            eventTracker.recordProjectEvent(jsessionID, xnatProjectLabelOrID);
        }
    } catch (IOException e) {
        log.warning("Error calling XNAT to delete for project " + xnatProjectLabelOrID, e);
        xnatStatusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    } finally {
        method.releaseConnection();
    }
    return xnatStatusCode;
}

From source file:edu.stanford.epad.epadws.xnat.XNATDeletionOperations.java

public static int deleteXNATSubject(String xnatProjectLabelOrID, String xnatSubjectLabelOrID,
        String jsessionID) {//from  w  w w  . j  a  v a 2 s . com
    String xnatSubjectDeleteURL = XNATUtil.buildXNATSubjectDeletionURL(xnatProjectLabelOrID,
            xnatSubjectLabelOrID);
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(xnatSubjectDeleteURL);
    int xnatStatusCode;

    method.setRequestHeader("Cookie", "JSESSIONID=" + jsessionID);

    try {
        log.info("Invoking XNAT with URL " + xnatSubjectDeleteURL);
        xnatStatusCode = client.executeMethod(method);
        if (unexpectedDeletionStatusCode(xnatStatusCode))
            log.warning("Failure calling XNAT to delete subject; status code = " + xnatStatusCode);
        else {
            eventTracker.recordPatientEvent(jsessionID, xnatProjectLabelOrID, xnatSubjectLabelOrID);
        }
    } catch (IOException e) {
        log.warning("Error calling XNAT to delete patient " + xnatSubjectLabelOrID + " from project "
                + xnatProjectLabelOrID, e);
        xnatStatusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    } finally {
        method.releaseConnection();
    }
    return xnatStatusCode;
}

From source file:edu.stanford.epad.epadws.xnat.XNATDeletionOperations.java

public static int deleteXNATDICOMStudy(String xnatProjectLabelOrID, String xnatSubjectLabelOrID,
        String studyUID, String sessionID) {
    String xnatStudyDeleteURL = XNATUtil.buildXNATDICOMStudyDeletionURL(xnatProjectLabelOrID,
            xnatSubjectLabelOrID, studyUID);
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(xnatStudyDeleteURL);
    int xnatStatusCode;

    method.setRequestHeader("Cookie", "JSESSIONID=" + sessionID);

    try {//from   w w  w . j a v  a2s. c  o  m
        log.info("Invoking XNAT with URL " + xnatStudyDeleteURL);
        xnatStatusCode = client.executeMethod(method);
        if (unexpectedDeletionStatusCode(xnatStatusCode))
            log.warning("Failure calling XNAT to delete Study; status code = " + xnatStatusCode);
        else {
            eventTracker.recordStudyEvent(sessionID, xnatProjectLabelOrID, xnatSubjectLabelOrID, studyUID);
        }
    } catch (IOException e) {
        log.warning("Error calling XNAT to delete study + " + studyUID + " for patient " + xnatSubjectLabelOrID
                + " from project " + xnatProjectLabelOrID, e);
        xnatStatusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    } finally {
        method.releaseConnection();
    }
    return xnatStatusCode;
}

From source file:edu.stanford.epad.plugins.qifpwrapper.QIFPHandler.java

public static int invalidateRemoteEPADSessionID(String epadSessionID, String epadHost, int port) {
    String epadSessionURL = buildEPADSessionURL(epadHost, port);
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(epadSessionURL);
    int epadStatusCode;

    method.setRequestHeader("Cookie", "JSESSIONID=" + epadSessionID);

    try {//  ww  w . j a v  a2s .  c o m
        epadStatusCode = client.executeMethod(method);
    } catch (IOException e) {
        log.warning("Error calling EPAD session service to invalidate session ID", e);
        epadStatusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    } finally {
        method.releaseConnection();
    }

    if (epadStatusCode != HttpServletResponse.SC_OK)
        log.warning("EPAD delete session call returned status code " + epadStatusCode);

    return epadStatusCode;
}

From source file:net.sf.ufsc.http.HttpFile.java

/**
 * @see net.sf.ufsc.File#delete()//  www .  j a  v a  2 s  .  co  m
 */
public void delete() throws java.io.IOException {
    DeleteMethod method = new DeleteMethod(this.uri.toString());

    try {
        this.execute(method);

        method.getResponseBody();
    } finally {
        method.releaseConnection();
    }
}