Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.GetMethod


   public void testPostDataFormAuth() throws Exception
   {
      log.info("+++ testPostDataFormAuth");
      // Start by accessing the secured index.html of war1
      HttpClient httpConn = new HttpClient();
      GetMethod indexGet = new GetMethod(baseURLNoAuth+"form-auth/unsecure_form.html");
      int responseCode = httpConn.executeMethod(indexGet);
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
      // Submit the form to /restricted/SecuredPostServlet
      PostMethod servletPost = new PostMethod(baseURLNoAuth+"form-auth/restricted/SecuredPostServlet");
      servletPost.addParameter("checkParam", "123456");
      responseCode = httpConn.executeMethod(servletPost);

      String body = servletPost.getResponseBodyAsString();
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
      assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );

      HttpState state = httpConn.getState();
      Cookie[] cookies = state.getCookies();
      String sessionID = null;
      for(int c = 0; c < cookies.length; c ++)
      {
         Cookie k = cookies[c];
         if( k.getName().equalsIgnoreCase("JSESSIONID") )
            sessionID = k.getValue();
      }
      getLog().debug("Saw JSESSIONID="+sessionID);
      // Submit the login form
      PostMethod formPost = new PostMethod(baseURLNoAuth+"form-auth/j_security_check");
      formPost.addRequestHeader("Referer", baseURLNoAuth+"form-auth/unsecure_form.html");
      formPost.addParameter("j_username", "jduke");
      formPost.addParameter("j_password", "theduke");
      responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
         formPost, state);
      String response = formPost.getStatusText();
      getLog().debug("responseCode="+responseCode+", response="+response);
      assertTrue("Saw HTTP_MOVED_TEMP", responseCode == HttpURLConnection.HTTP_MOVED_TEMP);

      //  Follow the redirect to the SecureServlet
      Header location = formPost.getResponseHeader("Location");
      String indexURI = location.getValue();
      GetMethod war1Index = new GetMethod(indexURI);
      responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
         war1Index, state);
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
      body = war1Index.getResponseBodyAsString();
      if( body.indexOf("j_security_check") > 0 )
         fail("get of "+indexURI+" redirected to login page");
   }
View Full Code Here


      return doSecureGetWithLogin(path, "jduke", "theduke");
   }
   public PostMethod doSecureGetWithLogin(String path, String username, String password)
      throws Exception
   {
      GetMethod indexGet = new GetMethod(baseURLNoAuth+path);
      int responseCode = httpConn.executeMethod(indexGet);
      String body = indexGet.getResponseBodyAsString();
      assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
      assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );

      HttpState state = httpConn.getState();
      Cookie[] cookies = state.getCookies();
      String sessionID = null;
      for(int c = 0; c < cookies.length; c ++)
      {
         Cookie k = cookies[c];
         if( k.getName().equalsIgnoreCase("JSESSIONID") )
            sessionID = k.getValue();
      }
      getLog().debug("Saw JSESSIONID="+sessionID);

      // Submit the login form
      PostMethod formPost = new PostMethod(baseURLNoAuth+"form-auth/j_security_check");
      formPost.addRequestHeader("Referer", baseURLNoAuth+"form-auth/restricted/login.html");
      formPost.addParameter("j_username", username);
      formPost.addParameter("j_password", password);
      responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
         formPost, state);
      String response = formPost.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      assertTrue("Saw HTTP_MOVED_TEMP", responseCode == HttpURLConnection.HTTP_MOVED_TEMP);

      //  Follow the redirect to the SecureServlet
      Header location = formPost.getResponseHeader("Location");
      String indexURI = location.getValue();
      GetMethod war1Index = new GetMethod(indexURI);
      responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
         war1Index, state);
      response = war1Index.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
      body = war1Index.getResponseBodyAsString();
      if( body.indexOf("j_security_check") > 0 )
         fail("get of "+indexURI+" redirected to login page");
      return formPost;
   }
View Full Code Here

            sessionID = k.getValue();
      }
      getLog().debug("Saw JSESSIONID="+sessionID);

      // Submit the login form
      GetMethod indexGet = new GetMethod(baseURLNoAuth+path);
      int responseCode = httpConn.executeMethod(indexGet.getHostConfiguration(),
         indexGet, state);
      assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
   }
View Full Code Here

      }
     
      @Override
      public Integer call() throws Exception
      {
         GetMethod method = new GetMethod(String.format(URL, CleanShutdownTestCase.this.getHttpURLs()[this.server], this.sleep));
        
         try
         {
            return Integer.valueOf(CleanShutdownTestCase.this.client.executeMethod(method));
         }
         finally
         {
            method.releaseConnection();
         }
      }
View Full Code Here

     
      // Start by accessing the secured index.html of war1
      HttpClient httpConn = new HttpClient();
     
      // Try to access protected resource
      GetMethod indexGet = new GetMethod(url + "index.jsp");
      int responseCode = httpConn.executeMethod(indexGet);
      String body = indexGet.getResponseBodyAsString();
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
      assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );

      // Submit the login form
   
      PostMethod formPost = new PostMethod(url + "j_security_check");
      formPost.addRequestHeader("Referer", url + "login.html");
      formPost.addParameter("j_username", "admin");
      formPost.addParameter("j_password", "admin");
      responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
         formPost, httpConn.getState());
      assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
         responseCode == HttpURLConnection.HTTP_MOVED_TEMP);

      //  Follow the redirect to the index.html page
      Header location = formPost.getResponseHeader("Location");
      String indexURI = location.getValue();
      GetMethod warIndex = new GetMethod(indexURI);
      responseCode = httpConn.executeMethod(warIndex.getHostConfiguration(),
         warIndex, httpConn.getState());
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
      body = warIndex.getResponseBodyAsString();
      if( body.indexOf("j_security_check") > 0 )
         fail("get of "+indexURI+" redirected to login page");
   }
View Full Code Here

   protected String makeGet(HttpClient client, String url)
      throws IOException
   {
      getLog().debug("makeGet(): trying to get from url " +url);

      GetMethod method = new GetMethod(url);
      int responseCode = 0;
      try
      {
         responseCode = client.executeMethod(method);
      } catch (IOException e)
View Full Code Here

    */
   protected String makeGetWithState(HttpClient client, String url)
      throws IOException
   {
      getLog().debug("makeGetWithState(): trying to get from url " +url);
      GetMethod method = new GetMethod(url);
      int responseCode = 0;
      try
      {
         HttpState state = client.getState();
         responseCode = client.executeMethod(method.getHostConfiguration(), method, state);
      } catch (IOException e)
      {
         e.printStackTrace();
         fail("HttpClient executeMethod fails." +e.toString());
      }
View Full Code Here

      log.info("+++ testHttpRedirect, httpNoAuth="+httpNoAuth);
      // Start by accessing the secured index.html of war1
      HttpClient httpConn = new HttpClient();
      String url = httpNoAuth+"clientcert-auth/unrestricted/SecureServlet";
      log.info("Accessing: "+url);
      GetMethod get = new GetMethod(url);
      int responseCode = httpConn.executeMethod(get);
      String status = get.getStatusText();
      log.debug(status);
      assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
   }
View Full Code Here

      log.info("+++ doHttps, httpsNoAuth="+httpsNoAuth);
      // Start by accessing the secured index.html of war1
      HttpClient httpConn = new HttpClient();
      String url = httpsNoAuth+"clientcert-auth/unrestricted/SecureServlet";
      log.info("Accessing: "+url);
      GetMethod get = new GetMethod(url);
      int responseCode = httpConn.executeMethod(get);
      String status = get.getStatusText();
      log.debug(status);
      assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
   }
View Full Code Here

   protected String makeGet(HttpClient client, String url)
      throws IOException
   {
      getLog().debug("makeGet(): trying to get from url " +url);

      GetMethod method = new GetMethod(url);
      int responseCode = 0;
      try
      {
         responseCode = client.executeMethod(method);
      } catch (IOException e)
      {
         e.printStackTrace();
         fail("HttpClient executeMethod fails." +e.toString());
      }
      assertEquals("Get OK with url: " + url, HttpURLConnection.HTTP_OK, responseCode);

      // Read the response body.
      byte[] responseBody = method.getResponseBody();

      // Release the connection.
//      method.releaseConnection();

      // Deal with the response.
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.GetMethod

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.