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: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 ava 2  s  .  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:com.funambol.json.dao.JsonDAOImpl.java

public JsonResponse removeItem(String token, String id, long since) throws HttpException, IOException {

    String request = Utility.getUrl(jsonServerUrl, resourceType, REMOVE_ITEM_URL) + Utility.URL_SEP + id;

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: start removeItem with id:" + id + "and since=" + since);
    }/*from  w  w w .j av  a2s  . c om*/

    DeleteMethod remove = new DeleteMethod(request);

    if (since != 0) {
        NameValuePair nvp_since = new NameValuePair();
        nvp_since.setName("since");
        nvp_since.setValue("" + since);
        NameValuePair[] nvp = { nvp_since };
        remove.setQueryString(nvp);
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: removeItem request:" + request);
    }
    remove.setRequestHeader(Utility.TOKEN_HEADER_NAME, token);

    int statusCode = 0;
    String responseBody = null;
    try {
        statusCode = httpClient.executeMethod(remove);
        responseBody = remove.getResponseBodyAsString();
    } finally {
        remove.releaseConnection();
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: deleteItem response " + responseBody);
        log.trace("JsonDAOImpl: item with id:" + id + " removed");
    }

    JsonResponse response = new JsonResponse(statusCode, responseBody);

    return response;
}

From source file:it.geosolutions.geoserver.rest.HTTPUtils.java

public static boolean delete(String url, final String user, final String pw) {

    DeleteMethod httpMethod = null;//from w  w w  .jav a 2  s .co  m
    HttpClient client = new HttpClient();
    HttpConnectionManager connectionManager = client.getHttpConnectionManager();
    try {
        setAuth(client, url, user, pw);
        httpMethod = new DeleteMethod(url);
        connectionManager.getParams().setConnectionTimeout(5000);
        int status = client.executeMethod(httpMethod);
        String response = "";
        if (status == HttpStatus.SC_OK) {
            InputStream is = httpMethod.getResponseBodyAsStream();
            response = IOUtils.toString(is);
            IOUtils.closeQuietly(is);
            if (response.trim().equals("")) {
                if (LOGGER.isTraceEnabled())
                    LOGGER.trace(
                            "ResponseBody is empty (this may be not an error since we just performed a DELETE call)");
                return true;
            }
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("(" + status + ") " + httpMethod.getStatusText() + " -- " + url);
            return true;
        } else {
            LOGGER.info("(" + status + ") " + httpMethod.getStatusText() + " -- " + url);
            LOGGER.info("Response: '" + response + "'");
        }
    } catch (ConnectException e) {
        LOGGER.info("Couldn't connect to [" + url + "]");
    } catch (IOException e) {
        LOGGER.info("Error talking to [" + url + "]", e);
    } finally {
        if (httpMethod != null)
            httpMethod.releaseConnection();
        connectionManager.closeIdleConnections(0);
    }

    return false;
}

From source file:edu.indiana.d2i.registryext.RegistryExtAgent.java

/**
 * delete a single resource/*from  w w w  .jav a 2s. co m*/
 * 
 * @param repoPath
 *            path in registry
 * @throws HttpException
 * @throws IOException
 * @throws RegistryExtException
 * @throws OAuthSystemException
 * @throws OAuthProblemException
 */
public void deleteResource(String repoPath)
        throws HttpException, IOException, RegistryExtException, OAuthSystemException, OAuthProblemException {

    Map<String, Object> session = ActionContext.getContext().getSession();

    int statusCode = 200;
    String accessToken = (String) session.get(Constants.SESSION_TOKEN);

    String requestURL = composeURL(FILEOPPREFIX, repoPath);

    if (logger.isDebugEnabled()) {
        logger.debug("Deletion request URL=" + requestURL);
    }

    HttpClient httpclient = new HttpClient();
    DeleteMethod delete = new DeleteMethod(requestURL);
    delete.addRequestHeader("Authorization", "Bearer " + accessToken);

    try {

        httpclient.executeMethod(delete);

        statusCode = delete.getStatusLine().getStatusCode();
        /* handle token expiration */
        if (statusCode == 401) {
            logger.info(String.format("Access token %s expired, going to refresh it", accessToken));

            refreshToken(session);

            // use refreshed access token
            accessToken = (String) session.get(Constants.SESSION_TOKEN);
            delete.addRequestHeader("Authorization", "Bearer " + accessToken);

            // re-send the request
            httpclient.executeMethod(delete);

            statusCode = delete.getStatusLine().getStatusCode();

        }

        if (statusCode != 204) {
            throw new RegistryExtException(
                    "Failed in delete resource : HTTP error code : " + delete.getStatusLine().getStatusCode());
        }

    } finally {
        if (delete != null)
            delete.releaseConnection();
    }

}

From source file:io.fabric8.gateway.apiman.HTTPGatewayApiManTest.java

public static void cleanAddedConfig() throws IOException {

    int restPort = httpGatewayServer.getPort() - 1;
    HttpClient httpClient = new HttpClient();
    //Removing applications
    LOG.info("Unregister clientApp Application");
    DeleteMethod method = new DeleteMethod("http://127.0.0.1:" + restPort
            + "/rest/apimanager/applications/ClientOrg/clientApp/1.0/?apikey=apiman-config-key");
    httpClient.executeMethod(method);/*from   w  w  w . j  a  v  a 2s  .  c  o  m*/

    //Removing services
    LOG.info("Retire Hello World Service");
    method = new DeleteMethod("http://127.0.0.1:" + restPort
            + "/rest/apimanager/services/Kurt/HelloWorld/1.0/?apikey=apiman-config-key");
    httpClient.executeMethod(method);
}

From source file:com.mirth.connect.connectors.http.HttpMessageDispatcher.java

private HttpMethod buildHttpRequest(String address, MessageObject mo) throws Exception {
    String method = connector.getDispatcherMethod();
    String content = replacer.replaceValues(connector.getDispatcherContent(), mo);
    String contentType = connector.getDispatcherContentType();
    String charset = connector.getDispatcherCharset();
    boolean isMultipart = connector.isDispatcherMultipart();
    Map<String, String> headers = replacer.replaceValuesInMap(connector.getDispatcherHeaders(), mo);
    Map<String, String> parameters = replacer.replaceValuesInMap(connector.getDispatcherParameters(), mo);

    HttpMethod httpMethod = null;/* ww  w . j a va  2 s  . c  om*/

    // populate the query parameters
    NameValuePair[] queryParameters = new NameValuePair[parameters.size()];
    int index = 0;

    for (Entry<String, String> parameterEntry : parameters.entrySet()) {
        queryParameters[index] = new NameValuePair(parameterEntry.getKey(), parameterEntry.getValue());
        index++;
        logger.debug("setting query parameter: [" + parameterEntry.getKey() + ", " + parameterEntry.getValue()
                + "]");
    }

    // create the method
    if ("GET".equalsIgnoreCase(method)) {
        httpMethod = new GetMethod(address);
        httpMethod.setQueryString(queryParameters);
    } else if ("POST".equalsIgnoreCase(method)) {
        PostMethod postMethod = new PostMethod(address);

        if (isMultipart) {
            logger.debug("setting multipart file content");
            File tempFile = File.createTempFile(UUID.randomUUID().toString(), ".tmp");
            FileUtils.writeStringToFile(tempFile, content, charset);
            Part[] parts = new Part[] { new FilePart(tempFile.getName(), tempFile, contentType, charset) };
            postMethod.setQueryString(queryParameters);
            postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
        } else if (StringUtils.equals(contentType, "application/x-www-form-urlencoded")) {
            postMethod.setRequestBody(queryParameters);
        } else {
            postMethod.setQueryString(queryParameters);
            postMethod.setRequestEntity(new StringRequestEntity(content, contentType, charset));
        }

        httpMethod = postMethod;
    } else if ("PUT".equalsIgnoreCase(method)) {
        PutMethod putMethod = new PutMethod(address);
        putMethod.setRequestEntity(new StringRequestEntity(content, contentType, charset));
        putMethod.setQueryString(queryParameters);
        httpMethod = putMethod;
    } else if ("DELETE".equalsIgnoreCase(method)) {
        httpMethod = new DeleteMethod(address);
        httpMethod.setQueryString(queryParameters);
    }

    // set the headers
    for (Entry<String, String> headerEntry : headers.entrySet()) {
        httpMethod.setRequestHeader(new Header(headerEntry.getKey(), headerEntry.getValue()));
        logger.debug("setting method header: [" + headerEntry.getKey() + ", " + headerEntry.getValue() + "]");
    }

    return httpMethod;
}

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 av a  2s .  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:com.funambol.json.dao.JsonDAOImpl.java

public JsonResponse removeAllItems(String token, long since) throws HttpException, IOException {

    String request = Utility.getUrl(jsonServerUrl, resourceType, REMOVE_ITEM_URL);

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: start removeAllItems");
    }/*from w  ww  . ja  va 2s  .  co m*/

    DeleteMethod remove = new DeleteMethod(request);

    if (since != 0) {
        NameValuePair nvp_since = new NameValuePair();
        nvp_since.setName("since");
        nvp_since.setValue("" + since);
        NameValuePair[] nvp = { nvp_since };
        remove.setQueryString(nvp);
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: removeAllItem request:" + request);
    }
    remove.setRequestHeader(Utility.TOKEN_HEADER_NAME, token);

    int statusCode = 0;
    String responseBody = null;
    try {
        statusCode = httpClient.executeMethod(remove);
        responseBody = remove.getResponseBodyAsString();
    } finally {
        remove.releaseConnection();
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: deleteAllItem response " + responseBody);
    }

    JsonResponse response = new JsonResponse(statusCode, responseBody);

    return response;
}

From source file:au.edu.usq.fascinator.harvester.fedora.restclient.FedoraRestClient.java

public void purgeObject(String pid, boolean force) throws IOException {
    StringBuilder uri = new StringBuilder(getBaseUrl());
    uri.append("/objects/");
    uri.append(pid);//  ww w . j av  a2s .  co m
    uri.append("?force=");
    uri.append(force);
    DeleteMethod method = new DeleteMethod(uri.toString());
    executeMethod(method);
    method.releaseConnection();
}

From source file:it.geosolutions.geonetwork.util.HTTPUtils.java

public boolean delete(String url) {

    DeleteMethod httpMethod = null;//from  w ww  .j  a v a 2s . c o m

    try {
        //            HttpClient client = new HttpClient();
        setAuth(client, url, username, pw);
        httpMethod = new DeleteMethod(url);
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        lastHttpStatus = client.executeMethod(httpMethod);
        String response = "";
        if (lastHttpStatus == HttpStatus.SC_OK) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("(" + lastHttpStatus + ") " + httpMethod.getStatusText() + " -- " + url);

            if (!ignoreResponseContentOnSuccess) {
                InputStream is = httpMethod.getResponseBodyAsStream();
                response = IOUtils.toString(is);
                if (response.trim().equals("")) {
                    if (LOGGER.isDebugEnabled())
                        LOGGER.debug(
                                "ResponseBody is empty (this may be not an error since we just performed a DELETE call)");
                }
            }
            return true;
        } else {
            LOGGER.info("(" + lastHttpStatus + ") " + httpMethod.getStatusText() + " -- " + url);
            LOGGER.info("Response: '" + response + "'");
        }
    } catch (ConnectException e) {
        LOGGER.info("Couldn't connect to [" + url + "]");
    } catch (IOException e) {
        LOGGER.info("Error talking to [" + url + "]", e);
    } finally {
        if (httpMethod != null)
            httpMethod.releaseConnection();
    }

    return false;
}