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

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

Introduction

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

Prototype

String AUTH_SCHEME_PRIORITY

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

Click Source Link

Usage

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

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

    /*//ww w . j  a  v  a2  s.  co  m
     * Empty search key ascii: calksmdasda87sd98asdklajsh key base64:
     * Y2Fsa3NtZGFzZGE4N3NkOThhc2RrbGFqc2g=
     */

    String param = "?key=Y2Fsa3NtZGFzZGE4N3NkOThhc2RrbGFqc2g=&encoding=base64";
    String body = null;
    GetMethod empty_search = new GetMethod(SLING_URL + SEARCH_URL + param);

    empty_search.setDoAuthentication(true);

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

    try {
        client.executeMethod(empty_search);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, empty_search.getStatusCode());
    try {
        body = empty_search.getResponseBodyAsString();
        assertTrue("Empty search with base64", body.contains("[]"));
    } catch (IOException e) {
        assert false;
        e.printStackTrace();
    }

    empty_search.releaseConnection();

}

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

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

    // Empty search
    String param = "?key=" + SEARCH_KEY + "&type=" + TYPE_CONTENT;
    String body = null;//from  ww  w  . j a  va 2 s . c  o  m
    GetMethod empty_search = new GetMethod(SLING_URL + SEARCH_URL + param);

    empty_search.setDoAuthentication(true);

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

    try {
        client.executeMethod(empty_search);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, empty_search.getStatusCode());
    try {
        body = empty_search.getResponseBodyAsString();
        assertTrue("SearchAscii comparing response path", body.contains(
                "{\"Result\":{\"counter\":\"1\",\"results\":[{\"path\":\"/content/colecciones/admin/contents/tests_search_title\",\"extract\":"));
        assertTrue("SearchAscii comparing response resourcetype", body.contains("\"gad/content\""));
    } catch (IOException e) {
        assertFalse(true);

    }

    empty_search.releaseConnection();

}

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

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

    // Empty search
    String param = "?key=" + SEARCH_KEY_BASE64 + "&encoding=base64" + "&type=" + TYPE_CONTENT;
    String body = null;//from w  ww.  jav a2 s.com
    GetMethod empty_search = new GetMethod(SLING_URL + SEARCH_URL + param);

    empty_search.setDoAuthentication(true);

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

    try {
        client.executeMethod(empty_search);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, empty_search.getStatusCode());
    try {
        body = empty_search.getResponseBodyAsString();
        assertTrue("SearchBase64 comparing response path", body.contains(
                "{\"Result\":{\"counter\":\"1\",\"results\":[{\"path\":\"/content/colecciones/admin/contents/tests_search_title\",\"extract\":"));
        assertTrue("SearchBase64 comparing response resource type",
                body.contains("\"resourceType\":\"gad/content\"}]"));
    } catch (IOException e) {
        assertFalse(true);

    }

    empty_search.releaseConnection();

}

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

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

    // Empty search
    String param = "?key=fuente&type=" + TYPE_CONTENT + "&path=/content/colecciones";
    String body = null;//from w w w. java2  s.  c o  m
    GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param);

    searchmethod.setDoAuthentication(true);

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

    try {
        client.executeMethod(searchmethod);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, searchmethod.getStatusCode());
    try {
        body = searchmethod.getResponseBodyAsString();
        assertTrue("SearchContent comparing response path", body.contains(
                "\"Result\":{\"counter\":\"1\",\"results\":[{\"path\":\"/content/colecciones/admin/contents/tests_search_title"));
        assertTrue("SearchContent comparing response resource type",
                body.contains("\"resourceType\":\"gad/content\"}]"));
    } catch (IOException e) {
        assertFalse(true);

    }

    searchmethod.releaseConnection();

}

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

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

    // Empty search
    String param = "?key=" + SOURCE_TITLE + "&type=" + TYPE_SOURCE;
    String body = null;/*from   w  w w  .j a  v  a2s . c  o m*/
    GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param);

    searchmethod.setDoAuthentication(true);

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

    try {
        client.executeMethod(searchmethod);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, searchmethod.getStatusCode());
    try {
        body = searchmethod.getResponseBodyAsString();
        assertTrue("SearchSource comparing response path", body.contains("[{\"path\":\"/content/colecciones/"
                + COLLECTION + "/contents/tests_search_title/sources/fuente1\""));
        assertTrue("SearchSource comparing response resourcetype",
                body.contains("\"resourceType\":\"gad/source\"}]"));
    } catch (IOException e) {
        assertFalse(true);

    }

    searchmethod.releaseConnection();

}

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

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

    // Empty search
    String param = "?key=" + SEARCH_KEY + "&type=" + TYPE_SOURCE + "&path=" + SOURCEPATH;
    String body = null;//from ww  w.  j a va 2 s. c  o  m
    GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param);

    searchmethod.setDoAuthentication(true);

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

    try {
        client.executeMethod(searchmethod);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, searchmethod.getStatusCode());
    try {
        body = searchmethod.getResponseBodyAsString();
        assertTrue("SearchSource comparing response", body.contains("[]"));
    } catch (IOException e) {
        assertFalse(true);

    }

    searchmethod.releaseConnection();

}

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

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

    // Empty search
    String param = "?key=" + SEARCH_KEY + "&format=xml";
    String body = null;//from   w ww  . j  a v a2  s . com
    GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param);

    searchmethod.setDoAuthentication(true);

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

    try {
        client.executeMethod(searchmethod);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, searchmethod.getStatusCode());
    try {
        body = searchmethod.getResponseBodyAsString();
        assertTrue("SearchSource comparing response 1", body.contains("<?xml version=\"1.0\"?>"));
        assertTrue("SearchSource comparint response 2", body.contains(
                "<path>/content/colecciones/admin/contents/tests_search_title/sources/fuente1</path>"));
        assertTrue("SearchSource comparint response 3",
                body.contains("<resourceType>gad/source</resourceType>"));
        assertTrue("SearchSource comparint response 4", body.contains("<extract><![CDATA["));
        assertTrue("SearchSource comparint response 5", body.contains("<counter>2</counter>"));
    } catch (IOException e) {
        assertFalse(true);

    }
    searchmethod.releaseConnection();
}

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

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

    // Empty search
    String param = "?key=" + SEARCH_KEY + "&format=xml&type=" + TYPE_CONTENT;
    String body = null;/*w  w  w .j  av a2s.c  om*/
    GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param);

    searchmethod.setDoAuthentication(true);

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

    try {
        client.executeMethod(searchmethod);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, searchmethod.getStatusCode());
    try {
        body = searchmethod.getResponseBodyAsString();
        assertTrue("SearchSource comparing response 1", body.contains("<?xml version=\"1.0\"?>"));
        assertTrue("SearchSource comparint response 2",
                body.contains("<path>/content/colecciones/admin/contents/tests_search_title</path>"));
        assertTrue("SearchSource comparint response 3",
                body.contains("<resourceType>gad/content</resourceType>"));
        assertTrue("SearchSource comparint response 4", body.contains("<extract><![CDATA["));
        assertTrue("SearchSource comparint response 5", body.contains("<counter>1</counter>"));
    } catch (IOException e) {
        assertFalse(true);

    }
    searchmethod.releaseConnection();
}

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

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

    // Empty search
    String param = "?key=" + SEARCH_KEY + "&type=" + TYPE_CONTENT + "&fullinfo=true&offset=0";
    String body = null;//w ww  .j  a  va 2 s  .c om
    GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param);

    searchmethod.setDoAuthentication(true);

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

    try {
        client.executeMethod(searchmethod);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, searchmethod.getStatusCode());
    try {
        body = searchmethod.getResponseBodyAsString();
        assertTrue("SearchSource assert hits", body.contains("hits"));
        assertTrue("SearchSource assert schema", body.contains("schema"));
    } catch (IOException e) {
        assertFalse(true);

    }
    searchmethod.releaseConnection();
}

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

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

    // Empty search
    String param = "?key=" + SEARCH_KEY + "&items=1&format=xml";
    String body = null;//w w  w .ja v a2 s  .  c om
    GetMethod searchmethod = new GetMethod(SLING_URL + SEARCH_URL + param);

    searchmethod.setDoAuthentication(true);

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

    try {
        client.executeMethod(searchmethod);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(200, searchmethod.getStatusCode());
    try {
        body = searchmethod.getResponseBodyAsString();
        assertTrue("SearchItems 1", body.contains("<counter>1</counter>"));
        assertTrue("SearchItems 2", body.contains(
                "<path>/content/colecciones/admin/contents/tests_search_title/sources/fuente1</path>"));
        assertTrue("SearchItems 3", body.contains("<?xml version=\"1.0\"?>"));

    } catch (IOException e) {
        assertFalse(true);

    }
    searchmethod.releaseConnection();
}