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:com.tribune.uiautomation.testscripts.Photo.java

private boolean delete(String namespaceParam, String slugParam) {
    checkValidStateForDelete();//from   w  ww.  j  a va2s .  c  o m

    DeleteMethod delete = new DeleteMethod(constructResourceUrl(namespaceParam, slugParam));

    try {
        setRequestHeaders(delete);

        HttpClient client = new HttpClient();
        int status = client.executeMethod(delete);

        log.debug("Photo Service delete return status: " + delete.getStatusLine());
        if (status == HttpStatus.SC_OK) {
            return true;
        }
    } catch (HttpException e) {
        log.fatal("Fatal protocol violation: " + e.getMessage(), e);
    } catch (IOException e) {
        log.fatal("Fatal transport error: " + e.getMessage(), e);
    } finally {
        // Release the connection.
        delete.releaseConnection();
    }

    return false;
}

From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java

/**
 * @see {@link GraphRepository#delete(String)}
 *//*  ww w .j a va  2s  .c om*/
public void delete(String rdfXml) throws Exception {

    // DELETE
    DeleteMethod del = new DeleteMethod(servletURL);
    try {

        // add the range header
        if (rdfXml != null) {
            String triples = "triples[" + trim(rdfXml) + "]";
            Header range = new Header(GraphRepositoryServlet.HTTP_RANGE, triples);
            del.addRequestHeader(range);
        }

        // Execute the method.
        int sc = getHttpClient().executeMethod(del);
        if (sc != HttpStatus.SC_OK) {
            throw new IOException("HTTP-DELETE failed: " + del.getStatusLine());
        }

    } finally {
        // Release the connection.
        del.releaseConnection();
    }

}

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

/**
 * delete a single resource//ww  w .  j  a v a  2s . c  o  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:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java

/**
 * @see {@link GraphRepository#delete(String, QueryLanguage)}
 *///from ww  w. jav a 2s.c om
public void delete(String query, QueryLanguage ql) throws Exception {

    if (query == null || ql == null) {
        return;

    }
    // DELETE
    DeleteMethod del = new DeleteMethod(servletURL);

    try {

        // add the header for the query
        if (query != null) {
            query = ql.toString().toLowerCase() + "[" + trim(query) + "]";
            String rangeHeader = "query[" + query + "]";
            Header range = new Header(GraphRepositoryServlet.HTTP_RANGE, rangeHeader);
            del.addRequestHeader(range);
        }

        // Execute the method.
        int sc = getHttpClient().executeMethod(del);
        if (sc != HttpStatus.SC_OK) {
            throw new IOException("HTTP-DELETE failed: " + del.getStatusLine());
        }

    } finally {
        // Release the connection.
        del.releaseConnection();
    }

}

From source file:gr.upatras.ece.nam.fci.panlab.PanlabGWClient.java

/**
 * It makes a DELETE towards the gateway
 * @author ctranoris/*from  www . j  a v  a2 s . c om*/
 * @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 = panlabGWAddress + "/" + 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:muki.tool.JavaCompilationDeploymentTestCase.java

@Test
public void testDeleteOperation1() throws Exception {
    String url = URL_RESOURCE1 + "/pathDeleteOperation1";
    DeleteMethod method = new DeleteMethod(url);

    int statusCode = this.getHttpClient().executeMethod(method);
    assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NO_CONTENT);
    byte[] responseBody = method.getResponseBody();
    assertNull(responseBody);//  w ww .  j a va2  s .  c  o m
}

From source file:muki.tool.JavaCompilationDeploymentTestCase.java

@Test
public void testDeleteOperation2() throws Exception {
    String url = URL_RESOURCE1 + "/pathDeleteOperation2";
    DeleteMethod method = new DeleteMethod(url);

    int statusCode = this.getHttpClient().executeMethod(method);
    assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NO_CONTENT);
    byte[] responseBody = method.getResponseBody();
    assertNull(responseBody);//from   ww  w. j  a  v  a2  s .c  o m
}

From source file:muki.tool.JavaCompilationDeploymentTestCase.java

@Test
public void testDeleteOperation3() throws Exception {
    String url = URL_RESOURCE1 + "/pathDeleteOperation3";
    DeleteMethod method = new DeleteMethod(url);

    int statusCode = this.getHttpClient().executeMethod(method);
    assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NO_CONTENT);
    byte[] responseBody = method.getResponseBody();
    assertNull(responseBody);/*from   w w w .  j  a v a  2 s  .  co m*/
}

From source file:muki.tool.JavaCompilationDeploymentTestCase.java

@Test
public void testDeleteOperation4() throws Exception {
    String url = URL_RESOURCE1 + "/pathDeleteOperation4/4/5";
    DeleteMethod method = new DeleteMethod(url);

    int statusCode = this.getHttpClient().executeMethod(method);
    assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NO_CONTENT);
    byte[] responseBody = method.getResponseBody();
    assertNull(responseBody);/*from  w w w.j a  v  a 2  s  .  co  m*/
}

From source file:muki.tool.JavaCompilationDeploymentTestCase.java

@Test
public void testDeleteOperation5() throws Exception {
    String url = URL_RESOURCE1 + "/pathDeleteOperation5/55?date=2010-07-08";
    DeleteMethod method = new DeleteMethod(url);

    int statusCode = this.getHttpClient().executeMethod(method);
    assertTrue("Method failed: " + method.getStatusLine(), statusCode == HttpStatus.SC_NO_CONTENT);
    byte[] responseBody = method.getResponseBody();
    assertNull(responseBody);//from   w w w .ja  v a2s  .  c  o  m
}