Example usage for org.apache.commons.httpclient HttpMethodBase getResponseBodyAsString

List of usage examples for org.apache.commons.httpclient HttpMethodBase getResponseBodyAsString

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethodBase getResponseBodyAsString.

Prototype

@Override
public String getResponseBodyAsString() throws IOException 

Source Link

Document

Returns the response body of the HTTP method, if any, as a String .

Usage

From source file:org.apache.geronimo.javaee6.asynejb.test.AsynEJBTest.java

@Test
public void AsynEJBTest() throws Exception {
    String contextRoot = System.getProperty("appContext");
    HttpClient nclient = new HttpClient();
    String url = "http://localhost:8080/" + contextRoot + "/testServlet";
    HttpMethodBase httpMethod2;
    httpMethod2 = new PostMethod(url);
    int status = nclient.executeMethod(httpMethod2);
    Assert.assertEquals(200, status);/*  w  w w.  j  a  va 2s.c  o  m*/
    String result = null;
    if (status == 200) {
        String response = new String(httpMethod2.getResponseBodyAsString().getBytes("8859_1"));
        Matcher m = Pattern.compile("The notify process(.)+? testServlet.").matcher(response);

        while (m.find()) {
            result = m.group();
        }
    }
    Assert.assertEquals(result, "The notify process is undergoing at testServlet.");

    httpMethod2.releaseConnection();
}

From source file:org.apache.geronimo.javaee6.jndi.test.jndiEJBTest.java

@Test
public void AsynEJBTest() throws Exception {
    String VersionPara = System.getProperty("moduleVersion");
    String contextRoot = System.getProperty("appContext");

    HttpClient nclient = new HttpClient();
    String url = "http://localhost:8080/" + contextRoot + "/globalJNDITest?version=" + VersionPara;
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);

    int status = nclient.executeMethod(httpMethod);
    Assert.assertEquals(200, status);/*from   w  w  w  . j  a v a  2s.c  o  m*/

    String result1 = null;
    String result2 = null;
    String result3 = null;
    if (status == 200) {
        String response = new String(httpMethod.getResponseBodyAsString().getBytes("8859_1"));
        result1 = findRes("global (.)+? at testServlet.", response);
        result2 = findRes("app (.)+? at testServlet.", response);
        result3 = findRes("module (.)+? at testServlet.", response);
    }
    Assert.assertEquals(result1, "global says:hello at testServlet.");
    Assert.assertEquals(result2, "app says:hello at testServlet.");
    Assert.assertEquals(result3, "module says:hello at testServlet.");

    httpMethod.releaseConnection();
}

From source file:org.apache.geronimo.javaee6.jpa20.tests.JPATest.java

/**
 * Test 1//from   www  .  ja v  a  2 s  . c  o  m
 * Test 
 * Criteria Query feature.
 * @throws Exception
 */
@Test
public void addCourseTest() throws Exception {
    String contextroot = System.getProperty("appContext");
    root = "http://localhost:8080/" + contextroot;

    HttpClient nclient = new HttpClient();
    String url = root
            + "/CourseAdd?cid=1&cname=course1&classroom=course1&teacher=course1&assistTeacher=course1";
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);
    nclient.executeMethod(httpMethod);
    httpMethod.releaseConnection();

    url = root + "/ListQuery?cname=course1";
    HttpMethodBase httpMethod2;
    httpMethod2 = new PostMethod(url);
    int status = nclient.executeMethod(httpMethod2);
    Assert.assertEquals(status, 200);
    //      System.out.println("status:" + status);
    String response = null;
    if (status == 200) {
        response = new String(httpMethod2.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(response.contains("course name is :course1 from listQuery."));

    httpMethod2.releaseConnection();
}

From source file:org.apache.geronimo.javaee6.jpa20.tests.JPATest.java

/**
 * Test 2// w  w w . j a v  a 2s .co m
 * Test 
 * @ElementCollection annotation
 * */
@Test(dependsOnMethods = { "addCourseTest" })
public void addCommentTest() throws HttpException, Exception {
    HttpClient nclient = new HttpClient();
    String url = root + "/CommentAdd?cid=1";
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);
    nclient.executeMethod(httpMethod);
    httpMethod.releaseConnection();

    url = root + "/viewAllComments?cid=1";
    HttpMethodBase httpMethod2;
    httpMethod2 = new PostMethod(url);
    int status = nclient.executeMethod(httpMethod2);
    System.out.println("status:" + status);
    String response = null;
    if (status == 200) {
        response = new String(httpMethod2.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(response.contains("Comment:comment0 from viewAllComments"));

    httpMethod2.releaseConnection();
}

From source file:org.apache.geronimo.javaee6.jpa20.tests.JPATest.java

/**
 * Test 3/*www .j a  va  2 s  . c o  m*/
 * Test 
 * @Embedded annotation
 * @Embeddable annotation
 * @throws Exception 
 * @throws HttpException 
 */
@Test(dependsOnMethods = { "addCourseTest" })
public void AddStudentTest() throws HttpException, Exception {
    HttpClient nclient = new HttpClient();
    String url = root
            + "/StudentAdd?sid=1&sname=s1&country=country1&city=city1&street=street1&telephone=111111&age=11&score=0";
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);
    nclient.executeMethod(httpMethod);
    httpMethod.releaseConnection();

    url = root + "/viewStudents";
    HttpMethodBase httpMethod2;
    httpMethod2 = new PostMethod(url);
    nclient.executeMethod(httpMethod2);
    int status = nclient.executeMethod(httpMethod2);
    Assert.assertEquals(status, 200);
    //      System.out.println("status:" + status);

    String response = null;
    if (status == 200) {
        response = new String(httpMethod2.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(response.contains("Country:country1"));
    Assert.assertTrue(response.contains("City:city1"));
    Assert.assertTrue(response.contains("Street:street1"));
    httpMethod2.releaseConnection();
}

From source file:org.apache.geronimo.javaee6.jpa20.tests.JPATest.java

/**
 * Test 4//from w ww  .  j  av  a 2  s.  c o  m
 * Test
 * Foreign key function--add one ONE-TO-MANY record
 * @throws HttpException
 * @throws Exception
 */

@Test(dependsOnMethods = { "AddStudentTest" })
public void SelectCourseTest() throws HttpException, Exception {
    HttpClient nclient = new HttpClient();
    String url = root + "/viewSelect_CourseRelation?sid=1";
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);
    int status = nclient.executeMethod(httpMethod);
    //      System.out.println("status:" + status);
    String response = null;
    Assert.assertEquals(status, 200);
    if (status == 200) {
        response = new String(httpMethod.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(response.contains("Click Here to Select course1 from selectCourse"));
    httpMethod.releaseConnection();

    url = root + "/CourseSelect?cid=1&sid=1";
    httpMethod = new PostMethod(url);
    status = nclient.executeMethod(httpMethod);
    Assert.assertEquals(status, 200);
    //      System.out.println("status:" + status);
    response = null;
    if (status == 200) {
        response = new String(httpMethod.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(response.contains("Click Here to Unselect course1 from selectCourse"));
    httpMethod.releaseConnection();
}

From source file:org.apache.geronimo.javaee6.jpa20.tests.JPATest.java

/**
 * Test 5//from ww  w . ja  va2 s . co  m
 * Test
 * Foreign key function--delete one ONE-TO-MANY record
 * @throws HttpException
 * @throws Exception
 */
@Test(dependsOnMethods = { "SelectCourseTest" })
public void UnselectCourseTest() throws HttpException, Exception {
    String result = null;
    String response = null;
    HttpClient nclient = new HttpClient();
    String url = root + "/CourseUnselect?cid=1&sid=1";
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);
    int status = nclient.executeMethod(httpMethod);
    //      System.out.println("status:" + status);

    Assert.assertEquals(status, 200);

    if (status == 200) {
        response = new String(httpMethod.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(response.contains("Click Here to Select course1 from selectCourse"));
    httpMethod.releaseConnection();
}

From source file:org.apache.geronimo.javaee6.jpa20.tests.JPATest.java

/**
 * Test 6//  w  w  w  .  j a va2 s .c  o  m
 * Test
 * Insert and delete Student Record.
 * @throws HttpException
 * @throws Exception
 */
@Test
public void Insert_Del_Stu_Test() throws HttpException, Exception {
    String response = null;
    HttpClient nclient = new HttpClient();
    String url = root
            + "/StudentAdd?sid=2&sname=student2&country=country2&city=city2&street=street2&telephone=222222&age=22&score=0";
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);
    int status = nclient.executeMethod(httpMethod);
    //      System.out.println("status:" + status);
    Assert.assertEquals(status, 200);
    httpMethod.releaseConnection();

    url = root + "/viewAllStudents";
    HttpMethodBase httpMethod2;
    httpMethod2 = new PostMethod(url);
    status = nclient.executeMethod(httpMethod2);
    Assert.assertEquals(status, 200);
    if (status == 200) {
        response = new String(httpMethod2.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(response.contains("student2"));
    httpMethod2.releaseConnection();

    url = root + "/StudentDelete?sid=2";
    httpMethod = new PostMethod(url);
    status = nclient.executeMethod(httpMethod);
    Assert.assertEquals(status, 200);
    httpMethod.releaseConnection();

    url = root + "/viewAllStudents";
    httpMethod2 = new PostMethod(url);
    status = nclient.executeMethod(httpMethod2);
    Assert.assertEquals(status, 200);
    if (status == 200) {
        response = new String(httpMethod2.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(!response.contains("student2"));
    httpMethod2.releaseConnection();
}

From source file:org.apache.geronimo.javaee6.jpa20.tests.JPATest.java

/**
 * Test 7//from  w w  w.  j  a v a  2s.c  o  m
 * Test
 * NULLIF in JPQL
 * @throws HttpException
 * @throws Exception
 */
@Test
public void NullIf_JPQL_Test() throws HttpException, Exception {
    String response = null;
    HttpClient nclient = new HttpClient();
    String url = root
            + "/StudentAdd?sid=3&sname=student3&country=country3&city=city3&street=street3&telephone=333333&age=33&score=0";
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);
    int status = nclient.executeMethod(httpMethod);
    //      System.out.println("status:" + status);
    Assert.assertEquals(status, 200);
    httpMethod.releaseConnection();

    url = root + "/nullIfJPQL?sid=3";
    HttpMethodBase httpMethod2;
    httpMethod2 = new PostMethod(url);
    status = nclient.executeMethod(httpMethod2);
    Assert.assertEquals(status, 200);
    if (status == 200) {
        response = new String(httpMethod2.getResponseBodyAsString().getBytes("8859_1"));
    }
    Assert.assertTrue(response.contains("Nullif is sucess."));
    httpMethod2.releaseConnection();
}

From source file:org.apache.geronimo.testsuite.deployment.test.urlBindingTest.java

@Test
public void test() throws Exception {
    String contextRoot = System.getProperty("appContext");
    HttpClient nclient = new HttpClient();
    System.out.println("~~~~~~~~~~~~~~~~" + contextRoot);
    String url = "http://localhost:8080/" + contextRoot + "/testServlet";
    HttpMethodBase httpMethod;
    httpMethod = new PostMethod(url);
    int status = nclient.executeMethod(httpMethod);
    Assert.assertEquals(200, status);//w ww.  j av  a2 s  .  co  m
    String result = null;
    if (status == 200) {
        String response = new String(httpMethod.getResponseBodyAsString().getBytes("8859_1"));
        Assert.assertTrue(response.contains("http://geronimo.apache.org"));
    }
    httpMethod.releaseConnection();
}