Example usage for org.apache.commons.httpclient.methods PostMethod setRequestBody

List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestBody

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods PostMethod setRequestBody.

Prototype

public void setRequestBody(NameValuePair[] paramArrayOfNameValuePair) throws IllegalArgumentException 

Source Link

Usage

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

private void createTest3() {

    PostMethod post_create_ok = new PostMethod(SLING_URL + "/apps/gad/*");
    post_create_ok.setDoAuthentication(true);
    NameValuePair[] data_create_ok = { new NameValuePair("title", "test3"), };

    post_create_ok.setRequestBody(data_create_ok);
    post_create_ok.setDoAuthentication(true);
    try {/*ww w.j  a v  a 2 s.  c  o  m*/
        client.executeMethod(post_create_ok);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Content created
    System.out.println("Created ok: " + post_create_ok.getStatusCode());
    assertEquals(201, post_create_ok.getStatusCode());
    post_create_ok.releaseConnection();
}

From source file:org.iavante.sling.gad.administration.impl.AbstractHttpOperation.java

/** Execute a POST request and check status */
protected Header[] assertAuthenticatedPostStatus(Credentials creds, String url, List<String> expectedStatusCode,
        List<NameValuePair> postParams, String assertMessage) throws IOException {

    Header[] headers = null;/*  w w w .  j  a v  a  2s  .  c o m*/

    URL baseUrl = new URL(HTTP_BASE_URL);

    List authPrefs = new ArrayList(2);
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);

    HttpClient httpClient = new HttpClient();
    httpClient.getParams().setAuthenticationPreemptive(true);
    httpClient.getState().setCredentials(AuthScope.ANY, creds);
    httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

    PostMethod post = new PostMethod(url);
    post.setFollowRedirects(false);
    post.setDoAuthentication(true);

    try {

        if (postParams != null) {
            final NameValuePair[] nvp = {};
            post.setRequestBody(postParams.toArray(nvp));
        }

        final int status = httpClient.executeMethod(post);

        if (!expectedStatusCode.contains("" + status)) {
            log.error("ResponseCode: " + status + " isn't in " + expectedStatusCode.toString());
            throw new IOException("ResponseCode: " + status + " isn't in " + expectedStatusCode.toString());
        }

        headers = post.getResponseHeaders();

    } finally {
        post.releaseConnection();
    }

    return headers;
}

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

protected void setUp() {

    Map<String, String> envs = System.getenv();
    Set<String> keys = envs.keySet();

    Iterator<String> it = keys.iterator();
    boolean hashost = false;
    while (it.hasNext()) {
        String key = (String) it.next();

        if (key.compareTo(HOSTVAR) == 0) {
            SLING_URL = SLING_URL + (String) envs.get(key);
            hashost = true;/*  ww  w .ja  v a 2s  . c o m*/
        }
    }
    if (hashost == false)
        SLING_URL = SLING_URL + HOSTPREDEF;

    client = new HttpClient();
    col_title = "admin";
    content_title = "it_content";
    source_title = "it_source";
    file = "it.flv";
    mimetype = "video/flv";
    schema = "default";
    title = "Test case content";
    schema = "default";
    slug_collection = "admin";
    slug_content = "it_content";
    tags_request = "    test,     case";
    tags_response = "test,case";
    defaultcreds = new UsernamePasswordCredentials("admin", "admin");

    authPrefs = new ArrayList(2);
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);

    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

    // Delete the collection
    System.out.println("Delete collection: " + SLING_URL + COL_URL + col_title);
    PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title);
    NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), };

    post_delete.setDoAuthentication(true);
    post_delete.setRequestBody(data_delete);

    try {
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    post_delete.releaseConnection();

    // Create collection          
    PostMethod post_create_col = new PostMethod(SLING_URL + COL_URL + col_title);
    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"),
            new NameValuePair("title", col_title), new NameValuePair("schema", schema),
            new NameValuePair("subtitle", ""), new NameValuePair("extern_storage", "on"),
            new NameValuePair("picture", ""), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", "") };
    post_create_col.setRequestBody(data_create_col);
    //post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create_col);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Collection created
    assertEquals(post_create_col.getStatusCode(), 201);
    post_create_col.releaseConnection();

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

    // Create content in collection      
    PostMethod post_create_content = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title);
    post_create_content.setDoAuthentication(true);

    NameValuePair[] data_create_content = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", content_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", "test case"),
            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", "") };
    post_create_content.setRequestBody(data_create_content);
    //post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create_content);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Content created
    assertEquals(post_create_content.getStatusCode(), 201);
    post_create_content.releaseConnection();

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

    // Edit content in collection      
    PostMethod post_edit_content = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title);
    post_create_content.setDoAuthentication(true);

    NameValuePair[] data_edit_content = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", content_title), new NameValuePair("schema", schema),
            new NameValuePair("description", "Content description edited."),
            new NameValuePair("author", "Test case edited"), new NameValuePair("origin", "Test case edite"),
            new NameValuePair("lang", "es"), new NameValuePair("tags", "test case"),
            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", "") };
    post_edit_content.setRequestBody(data_edit_content);
    //post.setDoAuthentication(true);
    try {
        client.executeMethod(post_edit_content);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Content edited
    assertEquals(post_edit_content.getStatusCode(), 200);
    post_create_content.releaseConnection();

    try {
        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);
    System.out.println("Request: " + 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", ""),
            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(post_create.getStatusCode(), 201);
    post_create.releaseConnection();

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

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

    // Send the content to revision
    PostMethod post_send_to_revision = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title);
    String catalog_pending_url = CATALOG_URL + PENDING_FOLDER + "/";
    System.out.println("Catalog url: " + catalog_pending_url);
    System.out.println("Send to revision: " + SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title);
    post_send_to_revision.setDoAuthentication(true);

    NameValuePair[] data_send_to_revision = { new NameValuePair(":operation", "copy"),
            new NameValuePair(":dest", catalog_pending_url), new NameValuePair("replace", "true") };
    post_send_to_revision.setRequestBody(data_send_to_revision);
    try {
        client.executeMethod(post_send_to_revision);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(post_send_to_revision.getStatusCode(), 201);
    post_send_to_revision.releaseConnection();
}

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

protected void tearDown() {

    try {/*from  w w  w. j  a  v a2 s. co m*/
        Thread.sleep(9000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Delete the collection
    System.out.println("Delete collection: " + SLING_URL + COL_URL + col_title);
    PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title);
    NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), };

    post_delete.setDoAuthentication(true);
    post_delete.setRequestBody(data_delete);

    try {
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(post_delete.getStatusCode(), 200);
    System.out.println("Response: " + post_delete.getStatusCode());
    post_delete.releaseConnection();

    // Delete revision
    System.out.println("Delete revision: " + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    PostMethod post_delete_rev = new PostMethod(SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    NameValuePair[] data_delete_rev = { new NameValuePair(":operation", "delete"), };

    post_delete_rev.setDoAuthentication(true);
    post_delete_rev.setRequestBody(data_delete_rev);

    try {
        client.executeMethod(post_delete_rev);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(post_delete_rev.getStatusCode(), 200);
    System.out.println("Response: " + post_delete_rev.getStatusCode());
    post_delete_rev.releaseConnection();
}

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

/**
 * Edit more properties than tags in a revision
 *///from   w  ww  .  j  a  v  a  2 s. c  om
public void test_edit_revision_bad() {

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

    // Edit revision in pending      
    PostMethod post_edit_revision = new PostMethod(
            SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    System.out.println("Edit revision bad: " + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    post_edit_revision.setDoAuthentication(true);

    NameValuePair[] data_edit_rev = { new NameValuePair("sling:resourceType", "gad/revision"),
            new NameValuePair("title", content_title), new NameValuePair("schema", schema),
            new NameValuePair("description", "Content description edited."),
            new NameValuePair("author", "Test case edited"), new NameValuePair("origin", "Test case edite"),
            new NameValuePair("lang", "es"), new NameValuePair("state", "pending"),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };

    post_edit_revision.setRequestBody(data_edit_rev);
    //post.setDoAuthentication(true);
    try {
        client.executeMethod(post_edit_revision);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Revision edited
    assertEquals(post_edit_revision.getStatusCode(), 401);
    System.out.println("Response: " + post_edit_revision.getStatusCode());
    post_edit_revision.releaseConnection();
}

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

/**
 * Edit tags property in a revision/*from  w  ww.  j  a  v a2 s .  c o m*/
 */
public void test_edit_revision_ok() {

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

    // Edit revision in pending      
    PostMethod post_edit_revision = new PostMethod(
            SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    System.out.println("Edit revision ok: " + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    post_edit_revision.setDoAuthentication(true);

    NameValuePair[] data_edit_rev = { new NameValuePair("sling:resourceType", "gad/revision"),
            new NameValuePair("tags", "test case modified"), new NameValuePair("tags@TypeHint", "String[]"),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };

    post_edit_revision.setRequestBody(data_edit_rev);
    //post.setDoAuthentication(true);
    try {
        client.executeMethod(post_edit_revision);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Revision edited
    assertEquals(post_edit_revision.getStatusCode(), 200);
    System.out.println("Response: " + post_edit_revision.getStatusCode());
    post_edit_revision.releaseConnection();
}

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

protected void setUp() {

    Map<String, String> envs = System.getenv();
    Set<String> keys = envs.keySet();

    Iterator<String> it = keys.iterator();
    boolean hashost = false;
    while (it.hasNext()) {
        String key = (String) it.next();

        if (key.compareTo(HOSTVAR) == 0) {
            SLING_URL = SLING_URL + (String) envs.get(key);
            hashost = true;//from   w ww .j  a  va2  s  . c  o  m
        }
    }
    if (hashost == false)
        SLING_URL = SLING_URL + HOSTPREDEF;

    client = new HttpClient();
    col_title = "it_col";
    content_title = "it_content";
    source_title = "it_source";
    file = "it.flv";
    mimetype = "video/flv";
    schema = "default";
    title = "Test case content";
    schema = "default";
    slug_collection = "admin";
    slug_content = "it_content";
    tags_request = "    test,     case";
    tags_response = "test,case";
    defaultcreds = new UsernamePasswordCredentials("admin", "admin");

    authPrefs = new ArrayList(2);
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);

    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

    // Delete the collection
    System.out.println("Delete collection: " + SLING_URL + COL_URL + col_title);
    PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title);
    NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), };

    post_delete.setDoAuthentication(true);
    post_delete.setRequestBody(data_delete);

    try {
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    post_delete.releaseConnection();

    // Create collection
    System.out.println("Create collection");
    PostMethod post_create_col = new PostMethod(SLING_URL + COL_URL + col_title);
    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"),
            new NameValuePair("title", col_title), new NameValuePair("schema", schema),
            new NameValuePair("subtitle", ""), new NameValuePair("extern_storage", "on"),
            new NameValuePair("picture", ""), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", "") };
    post_create_col.setRequestBody(data_create_col);
    // post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create_col);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Collection created
    assertEquals(post_create_col.getStatusCode(), 201);
    post_create_col.releaseConnection();

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

    // Create content in collection
    System.out.println("Create content in collection");
    PostMethod post_create_content = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title);
    post_create_content.setDoAuthentication(true);

    NameValuePair[] data_create_content = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", content_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", "test case"),
            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", "") };
    post_create_content.setRequestBody(data_create_content);
    // post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create_content);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Content created
    assertEquals(post_create_content.getStatusCode(), 201);
    post_create_content.releaseConnection();

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

    // Create the source
    System.out.println("Create source in content");
    PostMethod post_create = new PostMethod(SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title + "/" + SOURCES_FOLDER + "/" + source_title);
    System.out.println("Request: " + 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", ""),
            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(post_create.getStatusCode(), 201);
    post_create.releaseConnection();

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

    // Send the content to revision
    System.out.println("Send the content to revision");
    PostMethod post_send_to_revision = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title);
    String catalog_pending_url = CATALOG_URL + PENDING_FOLDER + "/";
    System.out.println("Catalog url: " + catalog_pending_url);
    System.out.println("Send to revision: " + SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title);
    post_send_to_revision.setDoAuthentication(true);

    NameValuePair[] data_send_to_revision = { new NameValuePair(":operation", "copy"),
            new NameValuePair(":dest", catalog_pending_url), new NameValuePair("replace", "true") };
    post_send_to_revision.setRequestBody(data_send_to_revision);
    try {
        client.executeMethod(post_send_to_revision);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

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

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

    // Deny revision
    System.out.println("Deny revision");
    PostMethod post_deny_revision = new PostMethod(
            SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    String catalog_denied_url = CATALOG_URL + DENIED_FOLDER + "/";
    System.out.println("Deny Revision: " + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    post_send_to_revision.setDoAuthentication(true);

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

    assertEquals(post_deny_revision.getStatusCode(), 201);
    post_deny_revision.releaseConnection();
}

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

protected void tearDown() {

    try {//from   ww  w.ja  v  a  2 s  . c om
        Thread.sleep(9000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Delete the collection
    System.out.println("Deleting collection");
    PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title);
    NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), };

    post_delete.setDoAuthentication(true);
    post_delete.setRequestBody(data_delete);

    try {
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(post_delete.getStatusCode(), 200);
    post_delete.releaseConnection();

    // Delete revision
    PostMethod post_delete_rev = new PostMethod(SLING_URL + CATALOG_URL + DENIED_FOLDER + "/" + content_title);
    NameValuePair[] data_delete_rev = { new NameValuePair(":operation", "delete"), };

    post_delete_rev.setDoAuthentication(true);
    post_delete_rev.setRequestBody(data_delete_rev);

    try {
        client.executeMethod(post_delete_rev);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(post_delete_rev.getStatusCode(), 200);
    post_delete_rev.releaseConnection();
}

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

protected void setUp() {

    Map<String, String> envs = System.getenv();
    Set<String> keys = envs.keySet();

    Iterator<String> it = keys.iterator();
    boolean hashost = false;
    while (it.hasNext()) {
        String key = (String) it.next();

        if (key.compareTo(HOSTVAR) == 0) {
            SLING_URL = SLING_URL + (String) envs.get(key);
            hashost = true;//from  w  ww.  ja  v a 2s. c  o m
        }
    }
    if (hashost == false)
        SLING_URL = SLING_URL + HOSTPREDEF;

    client = new HttpClient();
    col_title = "it_col";
    content_title = "it_content";
    source_title = "it_source";
    file = "it.flv";
    mimetype = "video/flv";
    schema = "default";
    title = "Test case content";
    schema = "default";
    slug_collection = "admin";
    slug_content = "it_content";
    tags_request = "    test,     case";
    tags_response = "test,case";
    defaultcreds = new UsernamePasswordCredentials("admin", "admin");

    authPrefs = new ArrayList(2);
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);

    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);

    // Delete the collection
    System.out.println("Delete collection: " + SLING_URL + COL_URL + col_title);
    PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title);
    NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), };

    post_delete.setDoAuthentication(true);
    post_delete.setRequestBody(data_delete);

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

    try {
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    post_delete.releaseConnection();

    // Create collection
    PostMethod post_create_col = new PostMethod(SLING_URL + COL_URL + col_title);
    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"),
            new NameValuePair("title", col_title), new NameValuePair("schema", schema),
            new NameValuePair("subtitle", ""), new NameValuePair("extern_storage", "on"),
            new NameValuePair("picture", ""), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", "") };
    post_create_col.setRequestBody(data_create_col);
    // post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create_col);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Collection created
    assertEquals(post_create_col.getStatusCode(), 201);
    post_create_col.releaseConnection();

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

    // Create content in collection
    PostMethod post_create_content = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title);
    post_create_content.setDoAuthentication(true);

    NameValuePair[] data_create_content = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", content_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", "test case"),
            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", "") };
    post_create_content.setRequestBody(data_create_content);
    // post.setDoAuthentication(true);
    try {
        client.executeMethod(post_create_content);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Content created
    assertEquals(post_create_content.getStatusCode(), 201);
    post_create_content.releaseConnection();

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

    // Edit content in collection
    PostMethod post_edit_content = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title);
    post_create_content.setDoAuthentication(true);

    NameValuePair[] data_edit_content = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", content_title), new NameValuePair("schema", schema),
            new NameValuePair("description", "Content description edited."),
            new NameValuePair("author", "Test case edited"), new NameValuePair("origin", "Test case edite"),
            new NameValuePair("lang", "es"), new NameValuePair("tags", "test case"),
            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", "") };
    post_edit_content.setRequestBody(data_edit_content);
    // post.setDoAuthentication(true);
    try {
        client.executeMethod(post_edit_content);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    // Content edited
    assertEquals(post_edit_content.getStatusCode(), 200);
    post_create_content.releaseConnection();

    try {
        Thread.sleep(8000);
    } 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);
    System.out.println("Request: " + 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", ""),
            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(post_create.getStatusCode(), 201);
    post_create.releaseConnection();

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

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

    // Send the content to revision
    PostMethod post_send_to_revision = new PostMethod(
            SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/" + content_title);
    String catalog_pending_url = CATALOG_URL + PENDING_FOLDER + "/";
    System.out.println("Catalog url: " + catalog_pending_url);
    System.out.println("Send to revision: " + SLING_URL + COL_URL + col_title + "/" + CONTENTS_FOLDER + "/"
            + content_title);
    post_send_to_revision.setDoAuthentication(true);

    NameValuePair[] data_send_to_revision = { new NameValuePair(":operation", "copy"),
            new NameValuePair(":dest", catalog_pending_url), new NameValuePair("replace", "true") };
    post_send_to_revision.setRequestBody(data_send_to_revision);
    try {
        client.executeMethod(post_send_to_revision);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals(post_send_to_revision.getStatusCode(), 201);
    post_send_to_revision.releaseConnection();
}

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

protected void tearDown() {

    try {/*from  w w w  . j  a  va 2  s .  c  om*/
        Thread.sleep(9000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    // Delete the collection
    System.out.println("Delete collectio: " + SLING_URL + COL_URL + col_title);
    PostMethod post_delete = new PostMethod(SLING_URL + COL_URL + col_title);
    NameValuePair[] data_delete = { new NameValuePair(":operation", "delete"), };

    post_delete.setDoAuthentication(true);
    post_delete.setRequestBody(data_delete);

    try {
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(post_delete.getStatusCode(), 200);
    System.out.println("Response: " + post_delete.getStatusCode());
    post_delete.releaseConnection();

    // Delete revision
    System.out.println("Delete revision: " + SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    PostMethod post_delete_rev = new PostMethod(SLING_URL + CATALOG_URL + PENDING_FOLDER + "/" + content_title);
    NameValuePair[] data_delete_rev = { new NameValuePair(":operation", "delete"), };

    post_delete_rev.setDoAuthentication(true);
    post_delete_rev.setRequestBody(data_delete_rev);

    try {
        client.executeMethod(post_delete_rev);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(post_delete_rev.getStatusCode(), 200);
    System.out.println("Response: " + post_delete_rev.getStatusCode());
    post_delete_rev.releaseConnection();
}