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

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

Introduction

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

Prototype

public void addParameter(String paramString1, String paramString2) throws IllegalArgumentException 

Source Link

Usage

From source file:org.jahia.bin.FindPrincipalTest.java

@After
public void tearDown() throws Exception {

    PostMethod logoutMethod = new PostMethod(getLogoutServletURL());
    logoutMethod.addParameter("redirectActive", "false");

    int statusCode = client.executeMethod(logoutMethod);
    if (statusCode != HttpStatus.SC_OK) {
        logger.error("Method failed: " + logoutMethod.getStatusLine());
    }/*ww w.j  a  v a2  s.c  om*/

    logoutMethod.releaseConnection();

}

From source file:org.jahia.bin.FindPrincipalTest.java

@Test
public void testFindUsers() throws IOException, JSONException, JahiaException {

    PostMethod method = new PostMethod(getFindPrincipalServletURL());
    method.addParameter("principalType", "users");
    method.addParameter("wildcardTerm", "*root*");

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    // Execute the method.
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        logger.error("Method failed: " + method.getStatusLine());
    }/*from  w w  w .j  a v a2  s . c  o  m*/

    // Read the response body.
    String responseBody = method.getResponseBodyAsString();

    JSONArray jsonResults = new JSONArray(responseBody);

    assertNotNull("A proper JSONObject instance was expected, got null instead", jsonResults);

    // @todo we need to add more tests to validate results.

}

From source file:org.jahia.bin.FindPrincipalTest.java

@Test
public void testFindGroups() throws IOException, JSONException {

    PostMethod method = new PostMethod(getFindPrincipalServletURL());
    method.addParameter("principalType", "groups");
    method.addParameter("siteKey", TESTSITE_NAME);
    method.addParameter("wildcardTerm", "*administrators*");

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    // Execute the method.
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        logger.error("Method failed: " + method.getStatusLine());
    }//from  w  w w.  j a  va2s . co m

    // Read the response body.
    String responseBody = method.getResponseBodyAsString();

    JSONArray jsonResults = new JSONArray(responseBody);

    assertNotNull("A proper JSONObject instance was expected, got null instead", jsonResults);

    // @todo we need to add more tests to validate results.

}

From source file:org.jahia.bin.FindTest.java

@Before
public void setUp() throws Exception {
    // Create an instance of HttpClient.
    client = new HttpClient();

    PostMethod loginMethod = new PostMethod(getLoginServletURL());
    loginMethod.addParameter("username", "root");
    loginMethod.addParameter("password", "root1234");
    loginMethod.addParameter("redirectActive", "false");
    // the next parameter is required to properly activate the valve check.
    loginMethod.addParameter(LoginEngineAuthValveImpl.LOGIN_TAG_PARAMETER, "1");

    int statusCode = client.executeMethod(loginMethod);
    if (statusCode != HttpStatus.SC_OK) {
        logger.error("Method failed: " + loginMethod.getStatusLine());
    }/*  w ww  .  j  a  v  a 2 s.  c o m*/
}

From source file:org.jahia.bin.FindTest.java

@After
public void tearDown() throws Exception {

    PostMethod logoutMethod = new PostMethod(getLogoutServletURL());
    logoutMethod.addParameter("redirectActive", "false");

    int statusCode = client.executeMethod(logoutMethod);
    if (statusCode != HttpStatus.SC_OK) {
        logger.error("Method failed: " + logoutMethod.getStatusLine());
    }//from  w  w w  . ja  v a  2 s  .  co  m

    logoutMethod.releaseConnection();
}

From source file:org.jahia.bin.FindTest.java

@Test
public void testFindEscapingWithXPath() throws IOException, JSONException, JahiaException {

    PostMethod method = new PostMethod(getFindServletURL() + "/" + Constants.EDIT_WORKSPACE + "/en");
    method.addParameter("query",
            "/jcr:root" + SITECONTENT_ROOT_NODE + "//element(*, nt:base)[jcr:contains(.,'{$q}')]");
    method.addParameter("q", COMPLEX_QUERY_VALUE); // to test if the reserved characters work correctly.
    method.addParameter("language", javax.jcr.query.Query.XPATH);
    method.addParameter("propertyMatchRegexp", "{$q}.*");
    method.addParameter("removeDuplicatePropValues", "true");
    method.addParameter("depthLimit", "1");

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    // Execute the method.
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        logger.error("Method failed: " + method.getStatusLine());
    }/*ww  w  . j a v a 2  s.c o m*/

    // Read the response body.
    String responseBody = method.getResponseBodyAsString();

    logger.debug("Status code=" + statusCode + " JSON response=[" + responseBody + "]");

    JSONArray jsonResults = new JSONArray(responseBody);

    assertNotNull("A proper JSONObject instance was expected, got null instead", jsonResults);

    assertTrue("Result should not be empty !", (jsonResults.length() > 0));

    validateFindJSONResults(jsonResults, COMPLEX_QUERY_VALUE);

}

From source file:org.jahia.bin.FindTest.java

@Test
public void testSimpleFindWithSQL2() throws IOException, JSONException {

    PostMethod method = new PostMethod(getFindServletURL() + "/" + Constants.EDIT_WORKSPACE + "/en");
    method.addParameter("query", "select * from [nt:base] as base where isdescendantnode(["
            + SITECONTENT_ROOT_NODE + "/]) and contains(base.*,'{$q}*')");
    method.addParameter("q", INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
    method.addParameter("language", javax.jcr.query.Query.JCR_SQL2);
    method.addParameter("propertyMatchRegexp", "{$q}.*");
    method.addParameter("removeDuplicatePropValues", "true");
    method.addParameter("depthLimit", "1");
    method.addParameter("getNodes", "true");

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    // Execute the method.
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        logger.error("Method failed: " + method.getStatusLine());
    }//  www.  ja  va2 s . c  o  m

    // Read the response body.
    String responseBody = method.getResponseBodyAsString();

    logger.debug("Status code=" + statusCode + " JSON response=[" + responseBody + "]");

    JSONArray jsonResults = new JSONArray(responseBody);

    assertNotNull("A proper JSONObject instance was expected, got null instead", jsonResults);

    assertTrue("Result should not be empty !", (jsonResults.length() > 0));

    validateFindJSONResults(jsonResults, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);

}

From source file:org.jahia.bin.FindTest.java

@Test
public void testFindEscapingWithSQL2() throws IOException, JSONException {

    PostMethod method = new PostMethod(getFindServletURL() + "/" + Constants.EDIT_WORKSPACE + "/en");
    method.addParameter("query", "select * from [nt:base] as base where isdescendantnode(["
            + SITECONTENT_ROOT_NODE + "/]) and contains(base.*,'{$q}')");
    method.addParameter("q", COMPLEX_QUERY_VALUE); // to test if the reserved characters work correctly.
    method.addParameter("language", javax.jcr.query.Query.JCR_SQL2);
    method.addParameter("propertyMatchRegexp", "{$q}.*");
    method.addParameter("removeDuplicatePropValues", "true");
    method.addParameter("depthLimit", "1");
    method.addParameter("getNodes", "true");

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    // Execute the method.
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        logger.error("Method failed: " + method.getStatusLine());
    }/*from ww w . ja v  a  2 s. c  o  m*/

    // Read the response body.
    String responseBody = method.getResponseBodyAsString();

    logger.debug("Status code=" + statusCode + " JSON response=[" + responseBody + "]");

    JSONArray jsonResults = new JSONArray(responseBody);

    assertNotNull("A proper JSONObject instance was expected, got null instead", jsonResults);

    assertTrue("Result should not be empty !", (jsonResults.length() > 0));

    validateFindJSONResults(jsonResults, COMPLEX_QUERY_VALUE);

}

From source file:org.jahia.bin.RenderTest.java

@Before
public void setUp() throws Exception {
    try {/*  w  w w  .j  a  v a 2s  . c  o m*/
        site = TestHelper.createSite(TESTSITE_NAME, "localhost" + System.currentTimeMillis(),
                TestHelper.INTRANET_TEMPLATES);
        assertNotNull(site);
    } catch (Exception ex) {
        logger.warn("Exception during test setUp", ex);
    }

    // Create an instance of HttpClient.
    client = new HttpClient();

    // todo we should really insert content to test the find.

    PostMethod loginMethod = new PostMethod("http://localhost:8080" + Jahia.getContextPath() + "/cms/login");
    loginMethod.addParameter("username", "root");
    loginMethod.addParameter("password", "root1234");
    loginMethod.addParameter("redirectActive", "false");
    // the next parameter is required to properly activate the valve check.
    loginMethod.addParameter(LoginEngineAuthValveImpl.LOGIN_TAG_PARAMETER, "1");

    int statusCode = client.executeMethod(loginMethod);
    if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + loginMethod.getStatusLine());
    }
}

From source file:org.jahia.bin.RenderTest.java

@After
public void tearDown() throws Exception {

    try {//from www  .j  a v  a  2 s .  co m
        TestHelper.deleteSite(TESTSITE_NAME);
    } catch (Exception ex) {
        logger.warn("Exception during test tearDown", ex);
    }
    JCRSessionFactory.getInstance().closeAllSessions();

    PostMethod logoutMethod = new PostMethod("http://localhost:8080" + Jahia.getContextPath() + "/cms/logout");
    logoutMethod.addParameter("redirectActive", "false");

    int statusCode = client.executeMethod(logoutMethod);
    if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + logoutMethod.getStatusLine());
    }

    logoutMethod.releaseConnection();
}