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

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

Introduction

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

Prototype

@Override
public StatusLine getStatusLine() 

Source Link

Document

Provides access to the response status line.

Usage

From source file:gr.upatras.ece.nam.fci.uop.UoPGWClient.java

/**
 * It makes a DELETE towards the gateway
 * @author ctranoris/*from w ww  .  j a v a  2 s . c  o  m*/
 * @param resourceInstance sets the name of the resource Instance, e.g.: uop.rubis_db-27
 * @param ptmAlias sets the name of the provider URI, e.g.: uop
 * @param content sets the name of the content; send in utf8
 */
public void DELETEexecute(String resourceInstance, String ptmAlias, String content) {
    log.info("content body=" + "\n" + content);
    HttpClient client = new HttpClient();
    String tgwcontent = content;

    // resource instance is like uop.rubis_db-6 so we need to make it like
    // this /uop/uop.rubis_db-6
    String ptm = ptmAlias;
    String url = uopGWAddress + "/" + ptm + "/" + resourceInstance;
    log.info("Request: " + url);

    // Create a method instance.

    DeleteMethod delMethod = new DeleteMethod(url);
    delMethod.setRequestHeader("User-Agent", userAgent);
    delMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    // Provide custom retry handler is necessary
    //      delMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    //            new DefaultHttpMethodRetryHandler(3, false));

    //      RequestEntity requestEntity = null;
    //      try {
    //         requestEntity = new StringRequestEntity(tgwcontent,
    //               "application/x-www-form-urlencoded", "utf-8");
    //      } catch (UnsupportedEncodingException e1) {
    //         e1.printStackTrace();
    //      }

    //delMethod.setRequestEntity(requestEntity);

    try {
        // Execute the method.
        int statusCode = client.executeMethod(delMethod);

        if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + delMethod.getStatusLine());
        }

        // Deal with the response.
        // Use caution: ensure correct character encoding and is not binary
        // data
        // print the status and response
        InputStream responseBody = delMethod.getResponseBodyAsStream();

        CopyInputStream cis = new CopyInputStream(responseBody);
        response_stream = cis.getCopy();
        log.info("Response body=" + "\n" + convertStreamToString(response_stream));
        response_stream.reset();

        //         log.info("for address: " + url + " the response is:\n "
        //               + post.getResponseBodyAsString());

    } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
    } finally {
        // Release the connection.
        delMethod.releaseConnection();
    }

}

From source file:org.dasein.persist.riak.RiakCache.java

@Override
public void remove(Transaction xaction, T item) throws PersistenceException {
    startCall("remove");
    try {/* w ww . j av a2s  . co  m*/
        StringBuilder url = new StringBuilder();

        url.append(getEndpoint());
        url.append("buckets/");
        url.append(getBucket());
        url.append("/keys/");
        url.append(getKeyValue(item));

        HttpClient client = getClient();
        DeleteMethod delete = new DeleteMethod(url.toString());
        int code;

        try {
            if (wire.isDebugEnabled()) {
                try {
                    wire.debug(delete.getName() + " " + url.toString());
                    wire.debug("");
                    for (Header h : delete.getRequestHeaders()) {
                        wire.debug(h.getName() + ": " + h.getValue());
                    }
                    wire.debug("");
                } catch (Throwable ignore) {
                    // ignore
                }
            }
            code = client.executeMethod(delete);
        } catch (HttpException e) {
            throw new PersistenceException("HttpException during GET: " + e.getMessage());
        } catch (IOException e) {
            throw new PersistenceException("IOException during GET: " + e.getMessage());
        }
        try {
            String body = delete.getResponseBodyAsString();

            if (wire.isDebugEnabled()) {
                try {
                    wire.debug("----------------------------------------");
                    wire.debug("");
                    wire.debug(delete.getStatusLine().getStatusCode() + " "
                            + delete.getStatusLine().getReasonPhrase());
                    wire.debug("");
                    if (body != null) {
                        wire.debug(body);
                        wire.debug("");
                    }
                } catch (Throwable ignore) {
                    // ignore
                }
            }
            if (code != HttpStatus.SC_NO_CONTENT && code != HttpStatus.SC_NOT_FOUND) {
                throw new PersistenceException(code + ": " + body);
            }
            getCache().release(item);
        } catch (IOException e) {
            throw new PersistenceException(e);
        }
    } finally {
        endCall("remove");
    }
}

From source file:org.panlab.software.fci.uop.UoPGWClient.java

/**
 * It makes a DELETE towards the gateway
 * @author ctranoris/*  www.ja  v  a2  s  . co m*/
 * @param resourceInstance sets the name of the resource Instance, e.g.: uop.rubis_db-27
 * @param ptmAlias sets the name of the provider URI, e.g.: uop
 * @param content sets the name of the content; send in utf8
 */
public void DELETEexecute(String resourceInstance, String ptmAlias, String content) {
    System.out.println("content body=" + "\n" + content);
    HttpClient client = new HttpClient();
    String tgwcontent = content;

    // resource instance is like uop.rubis_db-6 so we need to make it like
    // this /uop/uop.rubis_db-6
    String ptm = ptmAlias;
    String url = uopGWAddress + "/" + ptm + "/" + resourceInstance;
    System.out.println("Request: " + url);

    // Create a method instance.

    DeleteMethod delMethod = new DeleteMethod(url);
    delMethod.setRequestHeader("User-Agent", userAgent);
    delMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    // Provide custom retry handler is necessary
    //      delMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
    //            new DefaultHttpMethodRetryHandler(3, false));

    //      RequestEntity requestEntity = null;
    //      try {
    //         requestEntity = new StringRequestEntity(tgwcontent,
    //               "application/x-www-form-urlencoded", "utf-8");
    //      } catch (UnsupportedEncodingException e1) {
    //         e1.printStackTrace();
    //      }

    //delMethod.setRequestEntity(requestEntity);

    try {
        // Execute the method.
        int statusCode = client.executeMethod(delMethod);

        if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + delMethod.getStatusLine());
        }

        // Deal with the response.
        // Use caution: ensure correct character encoding and is not binary
        // data
        // print the status and response
        InputStream responseBody = delMethod.getResponseBodyAsStream();

        CopyInputStream cis = new CopyInputStream(responseBody);
        response_stream = cis.getCopy();
        System.out.println("Response body=" + "\n" + convertStreamToString(response_stream));
        response_stream.reset();

        //         System.out.println("for address: " + url + " the response is:\n "
        //               + post.getResponseBodyAsString());

    } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
    } finally {
        // Release the connection.
        delMethod.releaseConnection();
    }

}

From source file:org.ws4d.pipes.modules.http.Delete.java

public void doWork() {

    // execute base module doWork()
    super.doWork();

    // check if we can terminate
    if (canClose()) {
        closeAllPorts();/* w w  w .  j  av  a 2  s.  c  o  m*/
        return;
    }

    if (getUrl() != null) {
        final DeleteMethod method = new DeleteMethod(getUrl());

        try {
            getClient().executeMethod(method);

            setOutData(PORT_STATUSCODE, method.getStatusCode());
            setOutData(PORT_STATUSLINE, method.getStatusLine());

        } catch (Exception e) {
            getLogger().log(Level.SEVERE, "Can't execute http get request: ", e);
        } finally {
            method.releaseConnection();
        }
    }
}

From source file:org.wso2.carbon.esb.rest.test.api.ESBJAVA4852URITemplateWithCompleteURLTestCase.java

@Test(groups = { "wso2.esb" }, description = "Sending complete URL to API and for dispatching")
public void testCompleteURLWithHTTPMethod() throws Exception {

    DeleteMethod delete = new DeleteMethod(getApiInvocationURL(
            "myApi1/order/21441/item/17440079" + "?message_id=41ec2ec4-e629-4e04-9fdf-c32e97b35bd1"));
    HttpClient httpClient = new HttpClient();
    LogViewerClient logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(), getSessionCookie());
    logViewerClient.clearLogs();// w w w.  ja va2 s  .c  o  m

    try {
        httpClient.executeMethod(delete);
        Assert.assertEquals(delete.getStatusLine().getStatusCode(), 202, "Response code mismatched");
    } finally {
        delete.releaseConnection();
    }

    LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs();
    boolean isLogMessageFound = false;

    for (LogEvent log : logEvents) {
        if (log != null && log.getMessage().contains("order API INVOKED")) {
            isLogMessageFound = true;
            break;
        }
    }
    Assert.assertTrue(isLogMessageFound, "Request Not Dispatched to API when HTTP method having full url");

}