Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpMethodBase


    */
   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);     
   }
View Full Code Here


  public void testCookieSetCorrectly() throws Exception
  {
    log.info("testCookieSetCorrectly");
    URL url = new URL(baseURL+"jbosstest-cookie/CookieReadServlet");
    HttpClient httpClient = new HttpClient();       
    HttpMethodBase request = HttpUtils.createMethod(url,HttpUtils.GET);
    //sending a blank request
    httpClient.executeMethod(request);
   
    log.info("sending request with cookie");   
    request = HttpUtils.createMethod(url,HttpUtils.POST);
View Full Code Here

 
  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));
   
View Full Code Here

   private String getResponseBody(String warName) throws Exception
   {
      HttpClient client = new HttpClient();
      client.executeMethod(makeRequest(warName));
     
      HttpMethodBase result = makeRequest(warName);

      // need to hit it twice with the same session for test to pass
      client.executeMethod(result);

      String responseBody = result.getResponseBodyAsString();
      if (responseBody == null) {
         throw new Exception("Unable to get response from server.");
      }
     
      return responseBody;
View Full Code Here

   }

   public void testMCAwareServlet() throws Exception
   {
      URL url = new URL(baseURL+"mcaware/MCAwareServlet");
      HttpMethodBase request = HttpUtils.accessURL(url);
   }
View Full Code Here

      try
      {
         deploy(deploymentUnit);
         try
         {
            HttpMethodBase request = new GetMethod(baseURL);
            client.executeMethod(request);

            String responseBody = request.getResponseBodyAsString();
            if (responseBody == null) {
               throw new Exception("Unable to get response from server.");
            }

            return responseBody;
View Full Code Here

    * through the classloading service.
    */
   public void testHttpRequestRevealInstallationDirectory() throws Exception
   {
      URL url = new URL(baseURL + "org.jboss.web.WebServer.class");
      HttpMethodBase request = HttpUtils.accessURL(url, null, HttpURLConnection.HTTP_NOT_FOUND);
      String statusText = request.getStatusText();
     
      if (statusText.indexOf(".jar") > 0)
         fail("Status text reveals installation directory information: " + statusText);
   }
View Full Code Here

   }

   public String accessURL(String url) throws Exception
   {
      HttpClient httpConn = new HttpClient();
      HttpMethodBase request = new GetMethod(baseURL + url);
      log.debug("RequestURI: " + request.getURI());
      int responseCode = httpConn.executeMethod(request);
      String response = request.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      String content = request.getResponseBodyAsString();
      log.debug(content);
      assertEquals(HttpURLConnection.HTTP_OK, responseCode);
      return content;
   }
View Full Code Here

   public static HttpMethodBase accessURL(URL url, String realm,
      int expectedHttpCode, Header[] hdrs, int type)
      throws Exception
   {
      HttpClient httpConn = new HttpClient();
      HttpMethodBase request = createMethod(url, type);
      int hdrCount = hdrs != null ? hdrs.length : 0;
      for(int n = 0; n < hdrCount; n ++)
         request.addRequestHeader(hdrs[n]);
      try
      {
         log.debug("Connecting to: "+url);
         String userInfo = url.getUserInfo();
         if( userInfo != null )
         {
            UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo);
            httpConn.getState().setCredentials(realm, url.getHost(), auth);
         }
         log.debug("RequestURI: "+request.getURI());
         int responseCode = httpConn.executeMethod(request);
         String response = request.getStatusText();
         log.debug("responseCode="+responseCode+", response="+response);
         String content = request.getResponseBodyAsString();
         log.debug(content);
         // Validate that we are seeing the requested response code
         if( responseCode != expectedHttpCode )
         {
            throw new IOException("Expected reply code:"+expectedHttpCode
View Full Code Here

      return request;
   }

   public static HttpMethodBase createMethod(URL url, int type)
   {
      HttpMethodBase request = null;
      switch( type )
      {
         case GET:
            request = new GetMethod(url.toString());
            break;
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.HttpMethodBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.