Example usage for org.apache.commons.httpclient HttpMethod releaseConnection

List of usage examples for org.apache.commons.httpclient HttpMethod releaseConnection

Introduction

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

Prototype

public abstract void releaseConnection();

Source Link

Usage

From source file:org.hydracache.client.transport.HttpTransport.java

@Override
public ResponseMessage sendRequest(RequestMessage requestMessage) throws Exception {
    if (httpClient == null)
        throw new IllegalStateException("Establish connection first.");

    HttpMethod getMethod = getMethod(requestMessage);
    try {//from   w  w w  .  j ava  2  s  . co m
        int responseCode = httpClient.executeMethod(getMethod);
        if (responseCode == HttpStatus.SC_NOT_FOUND)
            return null;

        ResponseMessageHandler handler = handlers.get(responseCode);

        return (handler == null ? null : handler.accept(responseCode, getMethod.getResponseBody()));
    } finally {
        getMethod.releaseConnection();
    }
}

From source file:org.iavante.sling.commons.services.CopyAndRenameOperationIT.java

public void test_copy_and_rename() {

    try {/*from w w w  .  j  ava2s .co m*/
        Thread.sleep(2000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    PostMethod post_copyandrename = new PostMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + SOURCES_FOLDER + "/" + source_title);
    post_copyandrename.setDoAuthentication(true);

    String dest = COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content1 + "/"
            + SOURCES_FOLDER + "/" + source_dest_slug;

    NameValuePair[] data_copy = { new NameValuePair(":operation", "copyandrename"),
            new NameValuePair(":dest", dest) };

    post_copyandrename.setRequestBody(data_copy);
    try {
        client.executeMethod(post_copyandrename);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    post_copyandrename.releaseConnection();

    // Create another content in collection       
    try {
        Thread.sleep(4000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    HttpMethod get_content = new GetMethod(SLING_URL + dest + "/file");

    try {
        this.client.executeMethod(get_content);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // handle response.   
    String response_body = "";
    try {
        response_body = get_content.getResponseBodyAsString();
    } catch (IOException e) {
        e.printStackTrace();
    }

    assertEquals(response_body, source_file);
    get_content.releaseConnection();

    HttpMethod get_content_title = new GetMethod(SLING_URL + dest + "/title");

    try {
        this.client.executeMethod(get_content_title);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // handle response.   
    response_body = "";
    try {
        response_body = get_content_title.getResponseBodyAsString();
    } catch (IOException e) {
        e.printStackTrace();
    }

    assertEquals(response_body, source_dest_title);
    get_content.releaseConnection();

    // Bad operation
    PostMethod post_copyandrename_bad = new PostMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + SOURCES_FOLDER);
    dest = COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content1 + "/"
            + SOURCES_FOLDER + "/" + source_dest_slug;

    NameValuePair[] data_copy_bad = { new NameValuePair(":operation", "copyandrename"),
            new NameValuePair(":dest", dest) };

    post_copyandrename_bad.setRequestBody(data_copy_bad);
    try {
        client.executeMethod(post_copyandrename_bad);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(post_copyandrename_bad.getStatusCode(), 412);
    post_copyandrename_bad.releaseConnection();
}

From source file:org.iavante.sling.gad.catalog.CatalogValidationFilterIT.java

public void test_revision_created() {

    String revision_resource_type = "gad/revision";

    try {//from w w w . ja  v a2 s.c  o m
        Thread.sleep(5000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Get source test not present in schema    
    HttpMethod get_revision = new GetMethod(
            SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title + "/sling:resourceType");
    System.out.println("Get revision" + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    try {
        client.executeMethod(get_revision);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // handle response.   
    String res_resource_type = "";
    try {
        res_resource_type = get_revision.getResponseBodyAsString();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Response: " + res_resource_type);

    assertEquals(res_resource_type, revision_resource_type);
    get_revision.releaseConnection();

}

From source file:org.iavante.sling.gad.catalog.DenyRevisionServiceIT.java

public void test_denied_created() {

    System.out.println("TEST Denied Revision created");
    String revision_resource_type = "gad/revision";

    try {/*  w  w w  .ja  v a2 s . c  o  m*/
        Thread.sleep(5000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Get source test not present in schema
    HttpMethod get_revision = new GetMethod(
            SLING_URL + CATALOG_URL + DENIED_FOLDER + "/" + content_title + "/sling:resourceType");
    System.out.println(SLING_URL + CATALOG_URL + DENIED_FOLDER + "/" + content_title);
    try {
        client.executeMethod(get_revision);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // handle response.
    String res_resource_type = "";
    try {
        res_resource_type = get_revision.getResponseBodyAsString();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Response: " + res_resource_type);

    assertEquals(res_resource_type, revision_resource_type);
    get_revision.releaseConnection();
}

From source file:org.iavante.sling.gad.catalog.PendingServiceIT.java

public void test_revision_created() {

    String revision_resource_type = "gad/revision";

    try {//from   ww w .j a v a 2 s .c  o m
        Thread.sleep(5000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Get source test not present in schema
    HttpMethod get_revision = new GetMethod(
            SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title + "/sling:resourceType");
    System.out.println(SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    try {
        client.executeMethod(get_revision);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // handle response.
    String res_resource_type = "";
    try {
        res_resource_type = get_revision.getResponseBodyAsString();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Response: " + res_resource_type);

    assertEquals(res_resource_type, revision_resource_type);
    get_revision.releaseConnection();

}

From source file:org.iavante.sling.gad.catalog.PendingServiceIT.java

public void test_source_not_in_schema() {

    try {// w  w  w .  j a v a2 s  . c  o m
        Thread.sleep(8000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Get source test not present in schema
    HttpMethod get_source = new GetMethod(SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title + "/"
            + SOURCES_FOLDER + "/" + source_title);
    System.out.println("Request: " + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title + "/"
            + SOURCES_FOLDER + "/" + source_title);
    try {
        client.executeMethod(get_source);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Response: " + get_source.getStatusCode());
    assertEquals(get_source.getStatusCode(), 404);
    get_source.releaseConnection();
}

From source file:org.iavante.sling.gad.catalog.PendingServiceIT.java

public void test_source_in_schema() {

    try {/*from w  w  w.ja v a2s  .  c  om*/
        Thread.sleep(9000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Get source test not present in schema
    HttpMethod get_source = new GetMethod(SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title + "/"
            + SOURCES_FOLDER + "/fuente_default");
    System.out.println("Request: " + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title + "/"
            + SOURCES_FOLDER + "/fuente_default");
    try {
        client.executeMethod(get_source);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Response: " + get_source.getStatusCode());
    assertEquals(get_source.getStatusCode(), 200);
    get_source.releaseConnection();
}

From source file:org.iavante.sling.gad.catalog.RevisedServiceIT.java

public void test_revision_created() {

    System.out.println("TEST Revision created");
    String revision_resource_type = "gad/revision";

    try {//from   w  w w .  j a  v  a  2  s .  c o m
        Thread.sleep(5000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Get source test not present in schema    
    HttpMethod get_revision = new GetMethod(
            SLING_URL + CATALOG_URL + REVISED_FOLDER + "/" + content_title + "/sling:resourceType");
    System.out.println(SLING_URL + CATALOG_URL + REVISED_FOLDER + "/" + content_title);
    try {
        client.executeMethod(get_revision);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // handle response.   
    String res_resource_type = "";
    try {
        res_resource_type = get_revision.getResponseBodyAsString();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Response: " + res_resource_type);

    assertEquals(res_resource_type, revision_resource_type);
    get_revision.releaseConnection();
}

From source file:org.iavante.sling.gad.catalog.RevisedServiceIT.java

public void test_getTagsFolder() {

    try {//from   ww  w.ja va  2s. c o m
        Thread.sleep(2000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    String response_body = "";
    HttpMethod get_col_tags = new GetMethod(SLING_URL + CATALOG_URL + TAGS_FOLDER + "/" + "sling:resourceType");
    try {
        client.executeMethod(get_col_tags);
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        response_body = get_col_tags.getResponseBodyAsString();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    assertEquals(response_body, TAGS_RESOURCE_TYPE);
    get_col_tags.releaseConnection();
}

From source file:org.iavante.sling.gad.catalog.RevisedServiceIT.java

/**
  * Tests for tags postprocessing/*from w  w w.j a v a2s . c o m*/
  */
public void test_getTagsCatalog() {

    try {
        Thread.sleep(4000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // Get the  tags
    HttpMethod get_col_tag1 = new GetMethod(SLING_URL + CATALOG_URL + TAGS_FOLDER + "/" + tag1_slug + "/title");
    try {
        this.client.executeMethod(get_col_tag1);
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // handle response.
    String response_body = "";
    try {
        response_body = get_col_tag1.getResponseBodyAsString();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // System.out.println("Tag 1: " + response_body);
    assertEquals(response_body, tag1_title);
    get_col_tag1.releaseConnection();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // Get the collection tags
    HttpMethod get_col_tag2 = new GetMethod(SLING_URL + CATALOG_URL + TAGS_FOLDER + "/" + tag2_slug + "/title");
    try {
        this.client.executeMethod(get_col_tag2);
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // handle response.
    try {
        response_body = get_col_tag2.getResponseBodyAsString();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // System.out.println("Tag 2: " + response_body);
    assertEquals(response_body, tag2_title);
    get_col_tag2.releaseConnection();
}