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

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

Introduction

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

Prototype

@Override
public void setRequestHeader(String headerName, String headerValue) 

Source Link

Document

Set the specified request header, overwriting any previous value.

Usage

From source file:com.manning.blogapps.chapter10.examples.AuthDelete.java

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.out.println("USAGE: authdelete <username> <password> <url>");
        System.exit(-1);//from   w  w w.  ja  va2  s. c o  m
    }
    String credentials = args[0] + ":" + args[1];
    String url = args[2];

    HttpClient httpClient = new HttpClient();
    DeleteMethod method = new DeleteMethod(url);
    method.setRequestHeader("Authorization",
            "Basic " + new String(Base64.encodeBase64(credentials.getBytes())));

    httpClient.executeMethod(method);
    System.out.println("Server returned status code: ");
}

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 {//from   w w w .  j ava  2 s.  co  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 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 ww. j  a  v a  2 s .  co 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.epadws.xnat.XNATDeletionOperations.java

public static int deleteXNATSubject(String xnatProjectLabelOrID, String xnatSubjectLabelOrID,
        String jsessionID) {//from   w w w  . ja v  a  2 s.  co m
    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.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   w w  w .  jav  a 2  s  .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: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 {//from   www  .  j  a  v  a 2  s  .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:com.moss.bdbadmin.client.service.BdbClient.java

public void delete(IdProof assertion, String path) throws ServiceException {
    try {/*from   ww w .ja v a2s. com*/
        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.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 {/*from w w  w.j a  va2 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: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  ava  2s . com*/

    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: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);/*  ww w.ja va  2  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();
}