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.content.ContentServiceTestIT.java

public void test_getPlaylist() {

    // Get the content
    try {//  w  w  w .j av a2  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 + ".playlist");
    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;

    get_content.releaseConnection();
}

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

/**
 * Tests for tags postprocessing// w ww . j  av  a  2  s.  c o m
 */
public void test_getTagsCollection() {

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

        e1.printStackTrace();
    }

    // Get the collection tags
    HttpMethod get_col_tag1 = new GetMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + TAGS_FOLDER + "/" + tag1_slug + "/title");
    try {
        this.client.executeMethod(get_col_tag1);
    } catch (HttpException e) {

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

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

        e.printStackTrace();
    }

    assertEquals(response_body, tag1_title);
    get_col_tag1.releaseConnection();

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

        e1.printStackTrace();
    }
    // Get the collection tags
    HttpMethod get_col_tag2 = new GetMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + TAGS_FOLDER + "/" + tag2_slug + "/title");
    try {
        this.client.executeMethod(get_col_tag2);
    } catch (HttpException e) {

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

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

        e.printStackTrace();
    }

    assertEquals(response_body, tag2_title);
    get_col_tag2.releaseConnection();
}

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

/**
 * Tests path property/* w  ww .  java  2s.  c o  m*/
 */
public void test_getPathProp() {

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

        e1.printStackTrace();
    }

    // Get path property
    String path_response = COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content;
    String path_prop = "jcr_path";

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

        e1.printStackTrace();
    }
    // Get the content
    HttpMethod get_content_path = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/"
            + CONTENTS_FOLDER + "/" + slug_content + "/" + path_prop);
    try {
        this.client.executeMethod(get_content_path);
    } catch (HttpException e) {

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

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

        e.printStackTrace();
    }

    assertEquals(response_body, path_response);
    get_content_path.releaseConnection();
}

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

/**
 * Tests path property//from  ww w. jav  a 2  s  .c o  m
 */
public void test_getLogNode() {

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

        e1.printStackTrace();
    }

    String log_node = "log";
    String log_resourceType = "gad/log";

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

        e1.printStackTrace();
    }

    // Get the log node
    HttpMethod get_content_log = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/"
            + CONTENTS_FOLDER + "/" + slug_content + "/" + log_node + "/sling:resourceType");
    try {
        this.client.executeMethod(get_content_log);
    } catch (HttpException e) {

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

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

        e.printStackTrace();
    }

    assertEquals(response_body, log_resourceType);
    get_content_log.releaseConnection();

    // Get the url property
    HttpMethod get_content_log_url = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/"
            + CONTENTS_FOLDER + "/" + slug_content + "/" + log_node + "/url");
    try {
        this.client.executeMethod(get_content_log_url);
    } catch (HttpException e) {

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

        e.printStackTrace();
    }

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

        e.printStackTrace();
    }

    String log_url = COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content;

    assertEquals(response_body, log_url);
    get_content_log_url.releaseConnection();

}

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

/**
 * Test the validated property/*  w ww  .j  a  v a  2 s .c om*/
 */
public void test_content_validation() {

    String validated = "0";
    String response_body = "";

    String source_video = "fuente_default";
    String source_image = "thumbnail_default";

    String file_video = "test.avi";
    String mime_video = "video/avi";

    String file_image = "test.png";
    String mime_image = "image/png";

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

        e1.printStackTrace();
    }

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

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

        e.printStackTrace();
    }

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

        e.printStackTrace();
    }

    assertEquals(response_body, validated);
    get_valid_prop.releaseConnection();

    // Edit source default
    PostMethod post_edit = new PostMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER
            + "/" + slug_content + "/" + SOURCES_FOLDER + "/" + source_video);
    post_edit.setDoAuthentication(true);

    NameValuePair[] data_edit = { new NameValuePair("sling:resourceType", "gad/source"),
            new NameValuePair("file", file_video), new NameValuePair("mimetype", mime_video),
            new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""),
            new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", ""),
            new NameValuePair("bitrate", ""), new NameValuePair("tracks_number", ""),
            new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""),
            new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""),
            new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };
    post_edit.setRequestBody(data_edit);
    post_edit.setDoAuthentication(true);
    try {
        client.executeMethod(post_edit);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(200, post_edit.getStatusCode());
    post_edit.releaseConnection();

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

        e1.printStackTrace();
    }

    // Edit thumbnail default
    post_edit = null;
    post_edit = new PostMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/"
            + slug_content + "/" + SOURCES_FOLDER + "/" + source_image);
    post_edit.setDoAuthentication(true);

    NameValuePair[] data_edit_image = { new NameValuePair("sling:resourceType", "gad/source"),
            new NameValuePair("file", file_image), new NameValuePair("mimetype", mime_image),
            new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""),
            new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", ""),
            new NameValuePair("bitrate", ""), new NameValuePair("tracks_number", ""),
            new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""),
            new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""),
            new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };
    post_edit.setRequestBody(data_edit_image);
    post_edit.setDoAuthentication(true);
    try {
        client.executeMethod(post_edit);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(200, post_edit.getStatusCode());
    post_edit.releaseConnection();

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

        e1.printStackTrace();
    }

    // Test if the content is already validated
    validated = "1";
    get_valid_prop = new GetMethod(SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/"
            + slug_content + "/validated");
    try {
        client.executeMethod(get_valid_prop);
    } catch (HttpException e) {

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

        e.printStackTrace();
    }

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

        e.printStackTrace();
    }

    assertEquals(response_body, validated);
    get_valid_prop.releaseConnection();
}

From source file:org.iavante.sling.gad.source.SourceServiceTestIT.java

public void test_create_source_in_content() {

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

        e1.printStackTrace();
    }

    // Create the source
    PostMethod post_create = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title + "/" + SOURCES_FOLDER + "/" + source_title);
    post_create.setDoAuthentication(true);
    NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/source"),
            new NameValuePair("title", source_title), new NameValuePair("file", ""),
            new NameValuePair("mimetype", ""), new NameValuePair("text_encoding", ""),
            new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""),
            new NameValuePair("type", ""), new NameValuePair("bitrate", ""),
            new NameValuePair("tags", TAGS_REQUEST), new NameValuePair("tracks_number", ""),
            new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""),
            new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""),
            new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };
    post_create.setRequestBody(data_create);
    // post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(201, post_create.getStatusCode());
    post_create.releaseConnection();

    // Edit the source
    PostMethod post_edit = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title + "/" + SOURCES_FOLDER + "/" + source_title);
    post_create.setDoAuthentication(true);

    NameValuePair[] data_edit = { new NameValuePair("sling:resourceType", "gad/source"),
            new NameValuePair("file", file), new NameValuePair("mimetype", mimetype),
            new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""),
            new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", type),
            new NameValuePair("bitrate", ""), new NameValuePair("tracks_number", ""),
            new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""),
            new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""),
            new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };
    post_edit.setRequestBody(data_edit);
    post_edit.setDoAuthentication(true);
    try {
        client.executeMethod(post_edit);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(200, post_edit.getStatusCode());

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

        e1.printStackTrace();
    }

    // Get trans preview
    HttpMethod get_trans_preview = new GetMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title + "/" + SOURCES_FOLDER + "/" + source_title + "/" + TRANSFORMATIONS_FOLDER + "/"
            + TRANSFORMATION_PREVIEW + "/" + "title");
    try {
        client.executeMethod(get_trans_preview);
    } catch (HttpException e) {

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

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

        e.printStackTrace();
    }

    assertEquals(TRANSFORMATION_PREVIEW_TITLE, res_trans_title);
    get_trans_preview.releaseConnection();
}

From source file:org.iavante.sling.gad.source.SourceServiceTestIT.java

public void test_source_finish_prop() {

    try {//from w w w .  j av a 2 s . com
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

    // Create the source
    PostMethod post_create = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title + "/" + SOURCES_FOLDER + "/" + source_title);
    post_create.setDoAuthentication(true);
    NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/source"),
            new NameValuePair("title", source_title), new NameValuePair("file", ""),
            new NameValuePair("mimetype", ""), new NameValuePair("text_encoding", ""),
            new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""),
            new NameValuePair("type", ""), new NameValuePair("bitrate", ""),
            new NameValuePair("tags", TAGS_REQUEST), new NameValuePair("tracks_number", ""),
            new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""),
            new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""),
            new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };
    post_create.setRequestBody(data_create);
    // post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    post_create.releaseConnection();

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

        e1.printStackTrace();
    }

    // Get the source
    HttpMethod get_source = new GetMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title + "/" + SOURCES_FOLDER + "/" + source_title);
    try {
        client.executeMethod(get_source);
    } catch (HttpException e) {

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

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

        e.printStackTrace();
    }

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

From source file:org.iavante.sling.gad.source.SourceServiceTestIT.java

public void test_create_source_in_sources() {

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

        e1.printStackTrace();
    }

    // Create source
    PostMethod post_create = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + SOURCES_FOLDER + "/" + source_title);
    post_create.setDoAuthentication(true);

    NameValuePair[] data_create = { new NameValuePair("sling:resourceType", "gad/source"),
            new NameValuePair("title", source_title), new NameValuePair("file", ""),
            new NameValuePair("mimetype", ""), new NameValuePair("text_encoding", ""),
            new NameValuePair("lang", ""), new NameValuePair("length", ""), new NameValuePair("size", ""),
            new NameValuePair("type", ""), new NameValuePair("bitrate", ""),
            new NameValuePair("tracks_number", ""), new NameValuePair("track_1_type", ""),
            new NameValuePair("track_1_encoding", ""), new NameValuePair("track_1_features", ""),
            new NameValuePair("track_2_type", ""), new NameValuePair("track_2_encoding", ""),
            new NameValuePair("track_2_features", ""), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", "") };
    post_create.setRequestBody(data_create);
    // post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(201, post_create.getStatusCode());

    // Edit source
    PostMethod post_edit = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + SOURCES_FOLDER + "/" + source_title);
    post_edit.setDoAuthentication(true);

    NameValuePair[] data_edit = { new NameValuePair("sling:resourceType", "gad/source"),
            new NameValuePair("file", file), new NameValuePair("mimetype", mimetype),
            new NameValuePair("text_encoding", ""), new NameValuePair("lang", ""),
            new NameValuePair("length", ""), new NameValuePair("size", ""), new NameValuePair("type", type),
            new NameValuePair("bitrate", ""), new NameValuePair("tracks_number", ""),
            new NameValuePair("track_1_type", ""), new NameValuePair("track_1_encoding", ""),
            new NameValuePair("track_1_features", ""), new NameValuePair("track_2_type", ""),
            new NameValuePair("track_2_encoding", ""), new NameValuePair("track_2_features", ""),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };
    post_edit.setRequestBody(data_edit);
    post_edit.setDoAuthentication(true);
    try {
        client.executeMethod(post_edit);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(200, post_edit.getStatusCode());

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

        e1.printStackTrace();
    }

    // Get the source mime type
    HttpMethod get_trans_preview = new GetMethod(SLING_URL + COL_URL + col_title + "/" + SOURCES_FOLDER + "/"
            + source_title + "/" + TRANSFORMATIONS_FOLDER + "/" + TRANSFORMATION_PREVIEW + "/" + "title");
    try {
        client.executeMethod(get_trans_preview);
    } catch (HttpException e) {

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

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

        e.printStackTrace();
    }

    assertEquals(TRANSFORMATION_PREVIEW_TITLE, res_trans_title);
    get_trans_preview.releaseConnection();
}

From source file:org.iavante.sling.transcodingServer.TranscodingServerTestIT.java

public void test_error_job() {

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

    //System.out.println("---------------------     test_error_job        ---------------------------------");
    HttpMethod get_job = new GetMethod(SLING_URL + JOBS_ERROR_URL + title + ".xml");

    try {
        this.client.executeMethod(get_job);
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

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

    //System.out.println("-------------------------------------------------------");
    //System.out.println(response_body);
    //System.out.println("-------------------------------------------------------");
    assertTrue(response_body.contains("state=\"Error\""));
    get_job.releaseConnection();
}

From source file:org.intermine.webservice.server.VersionServiceTest.java

@Test
public void wsVersion() throws HttpException, IOException {
    HttpMethod get = new GetMethod(baseurl + "/version");
    try {//w  ww. j  a va 2 s  .co  m
        int statusCode = client.executeMethod(get);
        assertEquals("Request should be successful", 200, statusCode);
        assertEquals("Version should be " + expectedVersion, "" + expectedVersion,
                get.getResponseBodyAsString().trim());
    } finally {
        get.releaseConnection();
    }
}