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

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

Introduction

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

Prototype

public abstract String getResponseBodyAsString() throws IOException;

Source Link

Usage

From source file:org.iavante.sling.gad.collection.CollectionServiceTestIT.java

public void test_getContentsFolder() {

    try {/*from  ww w.  ja  v a 2 s.  c  o  m*/
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    // Get the content
    HttpMethod get_col_contents = new GetMethod(
            SLING_URL + COLLECTION_URL + slug + "/" + CONTENTS_FOLDER + "/" + "sling:resourceType");
    try {
        client.executeMethod(get_col_contents);
    } catch (HttpException e) {

        e.printStackTrace();
    } catch (IOException e) {

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

        e.printStackTrace();
    }

    assertEquals(response_body, CONTENTS_RESOURCE_TYPE);

}

From source file:org.iavante.sling.gad.collection.CollectionServiceTestIT.java

public void test_getSourcesFolder() {

    try {//from  www .  j ava 2  s  .co  m
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    String response_body = "";
    HttpMethod get_col_sources = new GetMethod(
            SLING_URL + COLLECTION_URL + slug + "/" + SOURCES_FOLDER + "/" + "sling:resourceType");
    try {
        client.executeMethod(get_col_sources);
    } catch (HttpException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

    try {
        response_body = get_col_sources.getResponseBodyAsString();
    } catch (IOException e) {

        e.printStackTrace();
    }

    assertEquals(response_body, SOURCES_RESOURCE_TYPE);
    get_col_sources.releaseConnection();
}

From source file:org.iavante.sling.gad.collection.CollectionServiceTestIT.java

public void test_getTagsFolder() {

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

        e1.printStackTrace();
    }

    String response_body = "";
    HttpMethod get_col_tags = new GetMethod(
            SLING_URL + COLLECTION_URL + slug + "/" + TAGS_FOLDER + "/" + "sling:resourceType");
    try {
        client.executeMethod(get_col_tags);
    } catch (HttpException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

    try {
        response_body = get_col_tags.getResponseBodyAsString();
    } catch (IOException e) {

        e.printStackTrace();
    }

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

From source file:org.iavante.sling.gad.content.ContentServiceTestIT.java

public void test_getContent() {

    // Get the content

    try {/*from w w  w .ja v  a  2  s.  c o  m*/
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    HttpMethod get_content = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER
            + "/" + slug_content + "/" + "title");
    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, title);
    get_content.releaseConnection();
}

From source file:org.iavante.sling.gad.content.ContentServiceTestIT.java

public void test_get_content_finish_prop() {

    // Get the content inmediatly
    PostMethod post_create = new PostMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content_dos);
    post_create.setDoAuthentication(true);

    NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", title), new NameValuePair("schema", schema),
            new NameValuePair("description",
                    "Content description generated by test case. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."),
            new NameValuePair("author", "Test case"), new NameValuePair("origin", "Test case"),
            new NameValuePair("lang", "es"), new NameValuePair("tags", tag1_input),
            new NameValuePair("tags", tag2_input), new NameValuePair("tags@TypeHint", "String[]"),
            new NameValuePair("state", "pending"), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", ""), new NameValuePair("_charset_", "utf-8") };

    post_create.setRequestBody(data_create);

    try {/*from w  w  w. j  a v a2  s  .  c  o m*/
        client.executeMethod(post_create);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    post_create.releaseConnection();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    HttpMethod get_content = new GetMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content_dos);

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

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

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

        e.printStackTrace();
    }

    assertTrue(response_body.contains("<finish>1"));
    get_content.releaseConnection();
}

From source file:org.iavante.sling.gad.content.ContentServiceTestIT.java

public void test_get_embed() {

    // Get the content inmediatly
    PostMethod post_create = new PostMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content_dos);
    post_create.setDoAuthentication(true);

    NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", title), new NameValuePair("schema", "playlist"),
            new NameValuePair("description",
                    "Content description generated by test case. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."),
            new NameValuePair("author", "Test case"), new NameValuePair("origin", "Test case"),
            new NameValuePair("lang", "es"), new NameValuePair("tags", tag1_input),
            new NameValuePair("tags", tag2_input), new NameValuePair("tags@TypeHint", "String[]"),
            new NameValuePair("state", "pending"), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", ""), new NameValuePair("_charset_", "utf-8") };

    post_create.setRequestBody(data_create);

    try {/*  w w  w  .j a v  a 2 s  .c  o m*/
        client.executeMethod(post_create);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    post_create.releaseConnection();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    HttpMethod get_content = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER
            + "/" + slug_content_dos
            + "/?player_width=1000&player_height=200&player_playlist_layout=left&player_plugins=test-1,test-2&player_autostart=true&player_repeat=none");

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

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

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

        e.printStackTrace();
    }

    assertTrue(response_body.contains("<embed>"));
    assertTrue(response_body.contains("</embed>"));
    assertTrue(response_body.contains("width='1000'"));
    assertTrue(response_body.contains("height='200'"));
    assertTrue(response_body.contains("playlist=left"));
    assertTrue(response_body.contains("plugins=test-1,test-2"));
    assertTrue(response_body.contains("autostart=true"));
    assertTrue(response_body.contains("repeat=none"));
    get_content.releaseConnection();
}

From source file:org.iavante.sling.gad.content.ContentServiceTestIT.java

public void test_getSourcesFolder() {

    // Get the content
    try {// w  w w  .  j a  va2s. c  o m
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    HttpMethod get_content = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER
            + "/" + slug_content + "/" + SOURCES_FOLDER + "/sling:resourceType");
    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, SOURCES_RESOURCE_TYPE);

    get_content.releaseConnection();
}

From source file:org.iavante.sling.gad.content.ContentServiceTestIT.java

public void test_getVersion() {

    // Get the content
    try {//from www. j  a  v a2s.  c om
        Thread.sleep(4000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    String version = "1.1";
    // Get the content
    HttpMethod get_content_version = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/"
            + CONTENTS_FOLDER + "/" + slug_content + "/" + "version");
    try {
        this.client.executeMethod(get_content_version);
    } catch (HttpException e) {

        e.printStackTrace();
    } catch (IOException e) {

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

        e.printStackTrace();
    }

    assertEquals(response_body, version);

    get_content_version.releaseConnection();
}

From source file:org.iavante.sling.gad.content.ContentServiceTestIT.java

public void test_getContentHits() {

    // Get the content hits property
    try {//w ww  .j ava2  s .  co  m
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    HttpMethod get_content = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER
            + "/" + slug_content + "/" + "hits");
    try {
        this.client.executeMethod(get_content);
    } catch (HttpException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

    // Get the content hits property
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    String response_body = null;
    try {
        response_body = get_content.getResponseBodyAsString();
    } catch (IOException e) {

        e.printStackTrace();
    }

    assertEquals(response_body, "0");

    get_content.releaseConnection();

    get_content = new GetMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content + "/");
    try {
        this.client.executeMethod(get_content);
    } catch (HttpException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

    // Get the content hits property
    try {
        Thread.sleep(4000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    get_content.releaseConnection();

    get_content = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/"
            + slug_content + "/" + "hits");
    try {
        this.client.executeMethod(get_content);
    } catch (HttpException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

    response_body = null;
    try {
        response_body = get_content.getResponseBodyAsString();
    } catch (IOException e) {

        e.printStackTrace();
    }

    assertEquals(response_body, "1");

    get_content.releaseConnection();
}

From source file:org.iavante.sling.gad.content.ContentServiceTestIT.java

public void test_getSMIL() {

    // Get the content
    try {//from  ww  w  .j  av  a  2  s. co m
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }
    HttpMethod get_content = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER
            + "/" + slug_content + ".smil");
    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();
    }

    assert response_body.indexOf("<meta name=\"title\" content=\"Test case content\"/>") != -1;
    assert response_body.indexOf("<meta name=\"author\" content=\"Test case\"/>") != -1;
    assert response_body.indexOf("<video ") != -1;

    get_content.releaseConnection();
}