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

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

Introduction

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

Prototype

@Override
public Header getResponseHeader(String headerName) 

Source Link

Document

Gets the response header associated with the given name.

Usage

From source file:org.jboss.test.web.test.AltDDUnitTestCase.java

/** Access the http://{host}/altdd-test/AltRequestInfoServlet to see
 * that the altenate uri for the RequestInfoServlet was used
 *///  w  ww  .  j a va  2 s  . c om
public void testAltRequestInfoServlet() throws Exception {
    URL url = new URL(baseURL + "altdd-test/AltRequestInfoServlet");
    HttpMethodBase request = HttpUtils.accessURL(url);
    Header errors = request.getResponseHeader("X-Exception");
    log.info("X-Exception: " + errors);
    assertTrue("X-Exception(" + errors + ") is null", errors == null);
}

From source file:org.jboss.test.web.test.AltDDUnitTestCase.java

/** Access the http://{host}/altdd-test/AltRequestInfoServlet2 to see
 * that the RequestInfoServlet2 was added
 *//*from w w  w .j  a  v a  2  s.  c om*/
public void testAltRequestInfoServlet2() throws Exception {
    URL url = new URL(baseURL + "altdd-test/AltRequestInfoServlet2");
    HttpMethodBase request = HttpUtils.accessURL(url);
    Header errors = request.getResponseHeader("X-Exception");
    log.info("X-Exception: " + errors);
    assertTrue("X-Exception(" + errors + ") is null", errors == null);
}

From source file:org.jboss.test.web.test.ClasspathUnitTestCase.java

/** Test of a war that accesses classes referred to via the war manifest
 * classpath. Access the http://{host}/manifest/classpath.jsp
 *//* w  w w . j  av  a  2 s . c  o  m*/
public void testWarManifest() throws Exception {
    URL url = new URL(baseURL + "manifest/classpath.jsp");
    HttpMethodBase request = HttpUtils.accessURL(url);
    Header errors = request.getResponseHeader("X-Exception");
    log.info("X-Exception: " + errors);
    assertTrue("X-Exception(" + errors + ") is null", errors == null);
}

From source file:org.jboss.test.web.test.ClasspathUnitTestCase.java

/** Access the http://{host}/manifest/ClassesServlet
 */// w  w w. j av a 2 s  .c o m
public void testClassesServlet() throws Exception {
    URL url = new URL(baseURL + "manifest/ClassesServlet?class=org.jboss.test.web.util2.ClassInUtil2");
    HttpMethodBase request = HttpUtils.accessURL(url);
    Header errors = request.getResponseHeader("X-Exception");
    log.info("X-Exception: " + errors);
    assertTrue("X-Exception(" + errors + ") is null", errors == null);
}

From source file:org.jboss.test.web.test.ClasspathUnitTestCase.java

/** Access the http://{host}/manifest/LibServlet
 */// w  w w. j  a  v  a2 s .co m
public void testLibServlet() throws Exception {
    URL url = new URL(baseURL + "manifest/LibServlet");
    HttpMethodBase request = HttpUtils.accessURL(url);
    Header errors = request.getResponseHeader("X-Exception");
    log.info("X-Exception: " + errors);
    assertTrue("X-Exception(" + errors + ") is null", errors == null);
}

From source file:org.jboss.test.web.test.CookieUnitTestCase.java

public void testCookieRetrievedCorrectly() throws Exception {
    URL url = new URL(baseURL + "jbosstest-cookie/CookieServlet");
    HttpClient httpClient = new HttpClient();
    HttpMethodBase request = HttpUtils.createMethod(url, HttpUtils.GET);
    int responseCode = httpClient.executeMethod(request);
    //assert that we are able to hit servlet successfully
    assertEquals(HttpURLConnection.HTTP_OK, responseCode);
    request.getResponseHeader("Set-Cookie");

    Cookie[] cookies = httpClient.getState().getCookies();
    //verify that expired cookie is not set by server
    assertTrue("sever did not set expired cookie on client", checkNoExpiredCookie(cookies));

    for (int i = 0; i < cookies.length; i++) {
        log.info("Cookie " + i + " : " + cookies[i].toExternalForm());
        if (cookies[i].getName().equals("simpleCookie")) {
            assertTrue("cookie value should be jboss", cookies[i].getValue().equals("jboss"));
            assertEquals("cookie path", "/jbosstest-cookie", cookies[i].getPath());
            assertEquals("cookie persistence", false, cookies[i].isPersistent());
        } else if (cookies[i].getName().equals("withSpace"))
            assertEquals("should be no quote in cookie with space", cookies[i].getValue().indexOf("\""), -1);
        else if (cookies[i].getName().equals("comment")) {
            log.info("comment in cookie: " + cookies[i].getComment());
            //RFC2109:Note that there is no Comment attribute in the Cookie request header
            //corresponding to the one in the Set-Cookie response header.  The user
            //agent does not return the comment information to the origin server.

            assertTrue(cookies[i].getComment() == null);
        } else if (cookies[i].getName().equals("withComma")) {
            assertTrue("should contain a comma", cookies[i].getValue().indexOf(",") != -1);
        } else if (cookies[i].getName().equals("expireIn10Sec")) {
            log.info("will sleep for 5 seconds to see if cookie expires");
            Thread.sleep(5000);// w w  w.  j a  v  a2  s.  c o  m
            assertTrue("cookies should not be expired by now", !cookies[i].isExpired());
            log.info("will sleep for 5 more secs and it should expire");
            Thread.sleep(5000);
            assertTrue("cookies should be expired by now", cookies[i].isExpired());
        }

    }
}

From source file:org.jboss.test.web.test.CustomErrorsUnitTestCase.java

/** Test that the custom 404 error page is seen
 * //from   w ww  . j a v  a 2  s.  c  o  m
 * @throws Exception
 */
public void test404Error() throws Exception {
    log.info("+++ test404Error");
    int errorCode = HttpURLConnection.HTTP_NOT_FOUND;
    URL url = new URL(baseURLNoAuth + "error-producer/ErrorGeneratorServlet?errorCode=" + errorCode);
    HttpMethodBase request = HttpUtils.accessURL(url, "Realm", HttpURLConnection.HTTP_NOT_FOUND);
    Header errors = request.getResponseHeader("X-CustomErrorPage");
    log.info("X-CustomErrorPage: " + errors);
    assertTrue("X-CustomErrorPage(" + errors + ") is 404.jsp", errors.getValue().equals("404.jsp"));
}

From source file:org.jboss.test.web.test.CustomErrorsUnitTestCase.java

/** Test that the custom 500 error page is seen
 * /*from ww w . j a  v  a 2  s  .  co  m*/
 * @throws Exception
 */
public void test500Error() throws Exception {
    log.info("+++ test500Error");
    int errorCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
    URL url = new URL(baseURLNoAuth + "error-producer/ErrorGeneratorServlet?errorCode=" + errorCode);
    HttpMethodBase request = HttpUtils.accessURL(url, "Realm", HttpURLConnection.HTTP_INTERNAL_ERROR);
    Header errors = request.getResponseHeader("X-CustomErrorPage");
    log.info("X-CustomErrorPage: " + errors);
    assertTrue("X-CustomErrorPage(" + errors + ") is 500.jsp", errors.getValue().equals("500.jsp"));
}

From source file:org.jboss.test.web.test.CustomErrorsUnitTestCase.java

/** Test that the custom 500 error page is seen for an exception
 * /*from   w  ww .j  a  v a2s . com*/
 * @throws Exception
 */
public void testExceptionError() throws Exception {
    log.info("+++ testExceptionError");
    URL url = new URL(baseURLNoAuth + "error-producer/ErrorGeneratorServlet");
    HttpMethodBase request = HttpUtils.accessURL(url, "Realm", HttpURLConnection.HTTP_INTERNAL_ERROR);
    Header page = request.getResponseHeader("X-CustomErrorPage");
    log.info("X-CustomErrorPage: " + page);
    assertTrue("X-CustomErrorPage(" + page + ") is 500.jsp", page.getValue().equals("500.jsp"));
    Header errors = request.getResponseHeader("X-ExceptionType");
    log.info("X-ExceptionType: " + errors);
    assertTrue("X-ExceptionType(" + errors + ") is 500.jsp",
            errors.getValue().equals("java.lang.IllegalStateException"));
}

From source file:org.jboss.test.web.test.EncAnnotationsUnitTestCase.java

/** Access the http://{host}/simple-annonly/ENCServlet
 *//*from   w  w  w.j  av a 2 s .c  o m*/
public void testAltRequestInfoServlet() throws Exception {
    URL url = new URL(baseURL + "simple-annonly/ENCServlet");
    HttpMethodBase request = HttpUtils.accessURL(url);
    Header errors = request.getResponseHeader("X-Exception");
    log.info("X-Exception: " + errors);
    assertTrue("X-Exception(" + errors + ") is null", errors == null);
}