Example usage for org.apache.commons.httpclient.auth AuthPolicy DIGEST

List of usage examples for org.apache.commons.httpclient.auth AuthPolicy DIGEST

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.auth AuthPolicy DIGEST.

Prototype

String DIGEST

To view the source code for org.apache.commons.httpclient.auth AuthPolicy DIGEST.

Click Source Link

Usage

From source file:org.iavante.sling.gad.content.ContentServiceTestIT.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  ww  w  .  j a v a 2 s  . c o m
        }
    }

    if (hashost == false)
        SLING_URL = SLING_URL + HOSTPREDEF;

    client = new HttpClient();
    title = "Test case content";
    schema = "default";
    slug_collection = "admin";
    slug_content = "it_content";
    slug_content_dos = "it_content_dos";

    tag1_input = "AEIOU";
    tag2_input = "Recetas Equilibradas";

    tag1_title = "aeiou";
    tag2_title = "recetas equilibradas";

    tag1_slug = "aeiou";
    tag2_slug = "recetas-equilibradas";

    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    defaultcreds = new UsernamePasswordCredentials("admin", "admin");

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

    // Create collection
    PostMethod post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + slug_collection);

    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"),
            new NameValuePair("title", title), new NameValuePair("subtitle", ""),
            new NameValuePair("schema", schema), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", "") };

    post_create_col.setRequestBody(data_create_col);

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

    post_create_col.releaseConnection();

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

        e1.printStackTrace();
    }

    PostMethod post_create = new PostMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content);
    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 {
        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();
    }

    // Edit the content
    PostMethod post_edit = new PostMethod(
            SLING_URL + COLLECTIONS_URL + slug_collection + "/" + CONTENTS_FOLDER + "/" + slug_content);

    post_edit.setDoAuthentication(true);

    NameValuePair[] data_edit = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", title), new NameValuePair("schema", schema),
            new NameValuePair("description",
                    "Edited  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("state", "pending"),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", ""),
            new NameValuePair("_charset_", "utf-8") };

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

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

        e1.printStackTrace();
    }

    post_edit.releaseConnection();

    // Edit the content again
    post_edit.setRequestBody(data_edit);

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

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

        e1.printStackTrace();
    }

    post_edit.releaseConnection();
}

From source file:org.iavante.sling.gad.content.impl.DirectPublication.java

/**
 * Initial http client configuration./* w  ww .  java2 s.  c  o m*/
 */
private void setup() {
    client = new HttpClient();
    // defaultCreds = new UsernamePasswordCredentials(authInfo.getUserID(),
    // authInfo.getPassword().toString());

    int colIdx = userPass.indexOf(':');
    if (colIdx < 0) {
        userCreds = new UsernamePasswordCredentials(userPass);
    } else {
        userCreds = new UsernamePasswordCredentials(userPass.substring(0, colIdx),
                userPass.substring(colIdx + 1));
    }

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

From source file:org.iavante.sling.gad.source.SourceServiceTestIT.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;// w w  w .j  av a 2  s  .  co  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 = "integration-test.flv";
    mimetype = "video/flv";
    type = "video";
    schema = "default";

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

    defaultcreds = new UsernamePasswordCredentials("admin", "admin");

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

    // 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(201, post_create_col.getStatusCode());
    post_create_col.releaseConnection();

    // 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(201, post_create_content.getStatusCode());
    post_create_content.releaseConnection();
}

From source file:org.iavante.sling.gad.transcoder.impl.TranscoderServiceImpl.java

public int sendConversionTask3(String conversionType, String sourceLocation, String targetLocation,
        String notificationUrl, String externalStorageServer, String externalStorageUrl, String params,
        String ds_custom_props) {

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

    List authPrefs = new ArrayList(2);
    Credentials defaultcreds;/*from  ww  w .  ja  va  2 s .co m*/

    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);

    defaultcreds = new UsernamePasswordCredentials(transcodingServerUser, transcodingServerPassword);

    // Set client connection params
    MultiThreadedHttpConnectionManager connManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams connParams = connManager.getParams();
    connParams.setConnectionTimeout(800);
    HttpClient client = new HttpClient(connManager);

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

    if (log.isInfoEnabled())
        log.info("Sending conversion task");
    Node convTypeNode = null;
    try {
        convTypeNode = rootNode.getNode(baseRepoDir + "/" + COMPONENTS_FOLDER + "/" + TRANSCODER_FOLDER)
                .getNode(conversionType);
    } catch (PathNotFoundException e) {
        e.printStackTrace();
    } catch (RepositoryException e) {
        e.printStackTrace();
    }

    String executable = null;

    try {
        executable = convTypeNode.getProperty("command").getValue().getString();
        if (params == null) {
            params = convTypeNode.getProperty("params").getValue().getString();
        }
        if (ds_custom_props == null) {
            ds_custom_props = "";
        }
    } catch (ValueFormatException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (PathNotFoundException e) {
        e.printStackTrace();
    } catch (RepositoryException e) {
        e.printStackTrace();
    }

    PostMethod post = new PostMethod(sendConversionUrl);
    //post.getParams().setParameter("http.socket.timeout", new Integer(50));
    post.setDoAuthentication(true);

    NameValuePair[] data = { new NameValuePair("source_location", sourceLocation),
            new NameValuePair("target_location", targetLocation), new NameValuePair("executable", executable),
            new NameValuePair("params", params), new NameValuePair("ds_custom_props", ds_custom_props),
            new NameValuePair("notification_url", notificationUrl),
            new NameValuePair("extern_storage_server", externalStorageServer),
            new NameValuePair("sling:resourceType", "gad/job"),
            new NameValuePair("extern_storage_url", externalStorageUrl) };

    post.setRequestBody(data);

    post.setDoAuthentication(true);

    int status = 0;
    int intentos = 0;

    while ((status != 201) && (intentos < 2)) {
        try {
            client.executeMethod(post);
            status = post.getStatusCode();
            log.info("Conversion sent. Status code: " + status);
        } catch (HttpException e1) {
            log.error("Excepcion: HttpException");
            e1.printStackTrace();
            post.releaseConnection();
            return status;
        } catch (IOException e1) {
            log.error("Excepcion: IOexception");
            e1.printStackTrace();
            post.releaseConnection();
            return status;
        } finally {
            intentos++;
        }
    }
    post.releaseConnection();
    return status;

}

From source file:org.iavante.sling.permissions.PermissionsFilterTest.java

License:asdf

@org.junit.Before
public 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;/* w  ww.  j  ava2  s .c o  m*/
        }
    }
    if (hashost == false)
        SLING_URL = SLING_URL + HOSTPREDEF;

    client = new HttpClient();
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    defaultcreds = new UsernamePasswordCredentials("admin", "admin");

}

From source file:org.iavante.sling.permissions.ValidationFilterIT.java

@org.junit.Before
public 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;/* www  . j  a  v a2s . c o  m*/
        }
    }
    if (hashost == false)
        SLING_URL = SLING_URL + HOSTPREDEF;

    client = new HttpClient();
    title = "Test case content";
    schema = "default";
    slug_content = "test_case_content";
    slug_collection = "admin";
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    defaultcreds = new UsernamePasswordCredentials("admin", "admin");
    anonymouscreds = new UsernamePasswordCredentials("anonymous", "anonymous");

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

    PostMethod post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + slug_collection);

    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"),
            new NameValuePair("title", title), new NameValuePair("subtitle", ""),
            new NameValuePair("schema", schema), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", "") };
    post_create_col.setRequestBody(data_create_col);

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

    // Collection created
    post_create_col.releaseConnection();
}

From source file:org.iavante.sling.s3backend.S3BackendTestIT.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  ww  w .j  av a 2 s. c o  m*/
        }
    }
    if (hashost == false)
        SLING_URL = SLING_URL + HOSTPREDEF;

    client = new HttpClient();
    title = "Test case content";
    schema = "default";
    slug = "test_case_contents3";
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    defaultcreds = new UsernamePasswordCredentials("admin", "admin");

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

    createTest3();
    try {
        uploadContent();
    } catch (FileNotFoundException e) {
        log.info("ERROR uploading File: " + e.toString());
        e.printStackTrace();
    }
    createContent();
}

From source file:org.iavante.sling.searcher.SearcherServiceTestIT.java

@org.junit.BeforeClass
static public void initialize() {
    try {/*from   w  ww  .  j a v a 2s .  co  m*/
        Thread.sleep(3000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    /* get env params */
    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.compareToIgnoreCase(HOSTVAR) == 0) {
            SLING_URL = SLING_URL + (String) envs.get(key);
            hashost = true;
            break;
        }
    }
    if (hashost == false)
        SLING_URL = SLING_URL + HOSTPREDEF;

    /* make http connection */
    client = new HttpClient();
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    defaultcreds = new UsernamePasswordCredentials("admin", "admin");
    PostMethod post_create_col;

    /* tests if the collection exists */
    GetMethod get_create_col = new GetMethod(SLING_URL + COLLECTIONS_URL + "/" + COLLECTION);

    get_create_col.setDoAuthentication(true);

    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    try {
        client.executeMethod(get_create_col);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    if (get_create_col.getStatusCode() != 404) {
        deletecontent();
    }

    /* create a collection */
    post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + "/*");

    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_create_col = { new NameValuePair("sling:resourceType", "gad/collection"),
            new NameValuePair("title", COLLECTION), new NameValuePair("subtitle", ""),
            new NameValuePair("schema", SCHEMA), new NameValuePair("jcr:created", ""),
            new NameValuePair("jcr:createdBy", ""), new NameValuePair("jcr:lastModified", ""),
            new NameValuePair("jcr:lastModifiedBy", "") };
    post_create_col.setRequestBody(data_create_col);
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    try {
        client.executeMethod(post_create_col);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals("Creando la coleccion", 201, post_create_col.getStatusCode());
    post_create_col.releaseConnection();
    // collection created
    // Get the content
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }
    /* create a content */
    post_create_col = new PostMethod(SLING_URL + COLLECTIONS_URL + "/" + COLLECTION + "/contents/*");

    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_create_col_content = { new NameValuePair("sling:resourceType", "gad/content"),
            new NameValuePair("title", TITLE_CONTENT), new NameValuePair("author", "test_autor@tests.com"),
            new NameValuePair("schema", SCHEMA), new NameValuePair("description", DESCRIPTION),
            new NameValuePair("origin", "final cut"), new NameValuePair("lang", "es"),
            new NameValuePair("tags", "recetas equilibradas"), new NameValuePair("tags@TypeHint", "String[]"),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };
    post_create_col.setRequestBody(data_create_col_content);
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    try {

        client.executeMethod(post_create_col);

    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assertEquals("Creando contenido", 201, post_create_col.getStatusCode());
    post_create_col.releaseConnection();
    // Content created
    // Get the content
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    /* create a source */
    post_create_col = new PostMethod(
            SLING_URL + COLLECTIONS_URL + "/" + COLLECTION + "/contents/tests_search_title/sources/*");

    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_create_col_source = { new NameValuePair("sling:resourceType", "gad/source"),
            new NameValuePair("title", SOURCE_TITLE), new NameValuePair("author", "test_autor@tests.com"),
            new NameValuePair("schema", SCHEMA), new NameValuePair("description", DESCRIPTION),
            new NameValuePair("jcr:created", ""), new NameValuePair("jcr:createdBy", ""),
            new NameValuePair("jcr:lastModified", ""), new NameValuePair("jcr:lastModifiedBy", "") };
    post_create_col.setRequestBody(data_create_col_source);
    // post.setDoAuthentication(true);
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    try {

        client.executeMethod(post_create_col);

    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Get the content

    assertEquals("Creando fuente", 201, post_create_col.getStatusCode());
    post_create_col.releaseConnection();
    // Source created

    /* send to review */
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }
    post_create_col = new PostMethod(
            SLING_URL + COLLECTIONS_URL + "/" + COLLECTION + "/contents/" + TITLE_CONTENT);

    post_create_col.setDoAuthentication(true);

    NameValuePair[] data_send_review = { new NameValuePair(":operation", "copy"),
            new NameValuePair(":dest", "/content/catalogo/pendientes/"), new NameValuePair("replace", "true") };
    post_create_col.setRequestBody(data_send_review);
    // post.setDoAuthentication(true);
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    try {

        client.executeMethod(post_create_col);

    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // test if sent

    assertEquals("Mandando a revision", 201, post_create_col.getStatusCode());
    post_create_col.releaseConnection();
    // send to review finished

}

From source file:org.iavante.sling.transcodingServer.impl.TranscodingManagerImpl.java

@SuppressWarnings("unchecked")
private String notificateTransformation(Node jobNode) {
    log.info("notificateTransformation: reading properties");
    String response = "";
    String source_location = "";
    String target_location = "";

    String notification_url = null;
    String gadUser = null;/*from   w w  w  .jav a  2  s  . co m*/
    String gadPassword = null;
    String source_file = null;
    String target_file = null;

    HttpClient client = null;
    List authPrefs = new ArrayList(2);
    client = new HttpClient();
    Credentials defaultcreds;
    // first of all. We have to take the useful data
    try {
        // source_location-->sourcefile
        // target_location-->targetfile
        // ds_custom_props-->ds_custom_props
        source_location = jobNode.getProperty("source_location").getValue().getString();
        String[] splitedSourceLocation = source_location.split("/");
        source_file = splitedSourceLocation[splitedSourceLocation.length - 1];

        target_location = jobNode.getProperty("target_location").getValue().getString();
        String[] splitedTargetLocation = target_location.split("/");
        target_file = splitedTargetLocation[splitedTargetLocation.length - 1];

        notification_url = jobNode.getProperty("notification_url").getValue().getString();

        gadUser = Constantes.getGADuser();
        gadPassword = Constantes.getGADpassword();

        log.info("notificateTransformation: notification_url:" + notification_url);
        log.info("notificateTransformation: target_file:" + target_file);
        log.info("notificateTransformation: source_file:" + source_file);

    } catch (ValueFormatException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (PathNotFoundException e) {
        e.printStackTrace();
    } catch (RepositoryException e) {
        e.printStackTrace();
    }
    // Using the hhtp client. This has to be authenticated
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    defaultcreds = new UsernamePasswordCredentials(gadUser, gadPassword);
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    // Using the POST Method
    PostMethod post_notification = new PostMethod(notification_url);
    post_notification.setDoAuthentication(true);
    NameValuePair[] data_notification = { new NameValuePair("sling:resourceType", "gad/transformation"),
            new NameValuePair("title", source_file),
            //
            new NameValuePair("file", target_file), new NameValuePair("jcr:lastModified", "") };
    post_notification.setRequestBody(data_notification);
    post_notification.setDoAuthentication(true);
    try {
        log.info("notificateTransformation: Notificating...");
        client.executeMethod(post_notification);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Response in Status
    int status = post_notification.getStatusCode();
    post_notification.releaseConnection();
    if (status == 200) {
        response = "OK. Notificated. Status =" + status;
        log.info(response);
    } else {
        response = "Error notificating. Status =" + status;
        log.error(response);
    }
    return response;
}

From source file:org.iavante.sling.transcodingServer.impl.TranscodingManagerImpl.java

@SuppressWarnings("unchecked")
private String notificateStatus(String mystatus, Node jobNode) {
    log.info("notificatingStatus: reading properties");
    String response = "";

    String notification_url = null;
    String gadUser = null;//from ww w  . j  a va2 s  . co m
    String gadPassword = null;

    HttpClient client = null;
    List authPrefs = new ArrayList(2);
    client = new HttpClient();
    Credentials defaultcreds;
    // first of all. We have to take the useful data
    try {

        notification_url = jobNode.getProperty("notification_url").getValue().getString();

        gadUser = Constantes.getGADuser();
        gadPassword = Constantes.getGADpassword();

    } catch (ValueFormatException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (PathNotFoundException e) {
        e.printStackTrace();
    } catch (RepositoryException e) {
        e.printStackTrace();
    }
    // Using the hhtp client. This has to be authenticated
    authPrefs.add(AuthPolicy.DIGEST);
    authPrefs.add(AuthPolicy.BASIC);
    defaultcreds = new UsernamePasswordCredentials(gadUser, gadPassword);
    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(AuthScope.ANY, defaultcreds);
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
    // Using the POST Method
    PostMethod post_notification = new PostMethod(notification_url);
    post_notification.setDoAuthentication(true);
    NameValuePair[] data_notification = { new NameValuePair("sling:resourceType", "gad/transformation"),
            new NameValuePair("state", mystatus) };
    post_notification.setRequestBody(data_notification);
    post_notification.setDoAuthentication(true);
    try {
        log.info("notificatingStatus...");
        client.executeMethod(post_notification);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Response in Status
    int status = post_notification.getStatusCode();
    post_notification.releaseConnection();
    if (status == 200) {
        response = "OK. Notificated. Status =" + status;
        log.info(response);
    } else {
        response = "Error notificating. Status =" + status;
        log.error(response);
    }
    return response;
}