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

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

Introduction

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

Prototype

public abstract int getStatusCode();

Source Link

Usage

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

public void test_source_in_schema() {

    try {//w w  w.jav  a 2  s  .c o  m
        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.channel.ChannelServiceIT.java

@org.junit.Test
public void test_unpublish_revision() {

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

    // Unpublish the content
    PostMethod post_publish = new PostMethod(
            SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title);
    String unpublished_dest = CHANNEL_URL + channel_slug + "/" + UNPUBLISHED_FOLDER + "/";
    post_publish.setDoAuthentication(true);

    NameValuePair[] data_publish = { new NameValuePair(":operation", "move"),
            new NameValuePair(":dest", unpublished_dest), new NameValuePair("replace", "true") };
    post_publish.setRequestBody(data_publish);
    try {
        client.executeMethod(post_publish);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

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

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

    // Get the unpublished revision in contents folder
    HttpMethod get_unpublished_revision = new GetMethod(
            SLING_URL + CHANNEL_URL + channel_slug + "/" + CONTENTS_FOLDER + "/" + content_title);
    try {
        client.executeMethod(get_unpublished_revision);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    assertEquals(404, get_unpublished_revision.getStatusCode());
    get_unpublished_revision.releaseConnection();

    // Get the unpublished revision in unpublished folder
    get_unpublished_revision = new GetMethod(
            SLING_URL + CHANNEL_URL + channel_slug + "/" + UNPUBLISHED_FOLDER + "/" + content_title);
    try {
        client.executeMethod(get_unpublished_revision);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

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

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

    String unpublished_state = "unpublished";
    HttpMethod get_ref_content_state = new GetMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER
            + "/" + content_title + "/" + LOG_FOLDER + "/state");
    try {
        this.client.executeMethod(get_ref_content_state);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // handle response.
    String response_body = "";
    try {
        response_body = get_ref_content_state.getResponseBodyAsString();
    } catch (IOException e) {
        e.printStackTrace();
    }

    assertEquals(unpublished_state, response_body);
    get_ref_content_state.releaseConnection();
}

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

public void test_get_content_inmediatly() {

    // 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 {/* w ww.j a v a 2  s.  co m*/
        client.executeMethod(post_create);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    post_create.releaseConnection();

    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();
    }

    assertEquals(get_content.getStatusCode(), 200);
    get_content.releaseConnection();
}

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

public void test_getContentGadUuid() {

    // Get the content gaduuid property
    try {/*w w w.  j  av  a 2s.  c om*/
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

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

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

        e.printStackTrace();
    }

    assertEquals(get_content.getStatusCode(), 200);
    get_content.releaseConnection();
}

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

/**
 * Test for content postprocesing. Associate schema
 *//*from  ww  w  .  j  a  v  a  2 s. c o  m*/
public void test_sourceAssociation() {

    // Check sources content type created from schema
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {

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

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

        e.printStackTrace();
    }
    assertEquals(get_source.getStatusCode(), 200);

    get_source.releaseConnection();
}

From source file:org.iavante.sling.gad.downloader.ProxyFileSystemIT.java

@org.junit.Test
public void test_download_with_no_file() {

    // Get the content
    HttpMethod get_downloader = new GetMethod(SLING_URL + DOWNLOADER_URL);
    try {/*from  w  w  w. j  a  v  a  2  s.  c  om*/
        client.executeMethod(get_downloader);
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(get_downloader.getStatusCode(), 500);
}

From source file:org.iavante.sling.gad.red5backend.Red5BackendImplIT.java

/**
 * Tests if config properties are created
 **//*from w  w  w .  jav  a  2 s  . c  o  m*/
public void test_red5backend_properties() {

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

        e1.printStackTrace();
    }

    // Get red5 config folder
    HttpMethod get_red5_config = new GetMethod(
            SLING_URL + "/" + "content" + "/" + CONFIG_FOLDER + "/" + RED5BACKEND_FOLDER + "/rtmp");
    try {
        client.executeMethod(get_red5_config);
    } catch (HttpException e) {

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

        e.printStackTrace();
    }

    assertEquals(get_red5_config.getStatusCode(), 200);
    get_red5_config.releaseConnection();
}

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

public void test_notify_status_code() {

    try {/*w w w  . java 2 s. c om*/
        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);

    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(12000);
    } catch (InterruptedException e1) {

        e1.printStackTrace();
    }

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

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

        e.printStackTrace();
    }

    int status_code = get_trans_preview_status.getStatusCode();

    boolean failed = true;

    if (status_code != 404)
        failed = false;

    assertFalse(failed);
    get_trans_preview_status.releaseConnection();

}

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

public void test_transformation_folder_created() {

    try {//from w  ww .  j a v a2  s  .  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();

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

        e1.printStackTrace();
    }

    // Get trans folder
    HttpMethod get_trans_folder = new GetMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title + "/" + SOURCES_FOLDER
                    + "/" + source_title + "/" + TRANSFORMATIONS_FOLDER + ".html");
    // get_trans_folder.setDoAuthentication(true);
    try {
        client.executeMethod(get_trans_folder);
    } catch (HttpException e) {

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

        e.printStackTrace();
    }

    assertEquals(200, get_trans_folder.getStatusCode());
    get_trans_folder.releaseConnection();
}

From source file:org.iavante.sling.gad.transcoder.TranscoderServiceImplIT.java

/**
 * Tests if config properties are created
 **//* www .j  a v  a  2s.  co  m*/
public void test_transcoder_properties() {

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

        e1.printStackTrace();
    }

    // Get transcoder config folder
    HttpMethod get_trans_config = new GetMethod(
            SLING_URL + "/" + "content" + "/" + CONFIG_FOLDER + "/" + TRANSCODER_FOLDER + "/url");
    get_trans_config.setDoAuthentication(true);
    try {
        client.executeMethod(get_trans_config);
    } catch (HttpException e) {

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

        e.printStackTrace();
    }

    assertEquals(200, get_trans_config.getStatusCode());
    get_trans_config.releaseConnection();
}