Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpClient


    * @param virtualHost the virtual host
    * @throws Exception
    */
   protected void testHost(URL url, String virtualHost) throws Exception
   {
      HttpClient httpConn = new HttpClient();
      HttpMethodBase request = new OverrideGetMethod(url.toString(), virtualHost);
      int responseCode = httpConn.executeMethod(request);
     
      if( responseCode != HttpURLConnection.HTTP_OK )
      {
         throw new IOException("Expected reply code:"+ HttpURLConnection.HTTP_OK
            +", actual="+responseCode);
View Full Code Here


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

      // Set the session attribute first
      makeGet(client, baseURL0_ +setUrl_);

      // Create a method instance.
View Full Code Here

   public void testFormAuthentication() throws Exception {

      String url = baseURLNoAuth + "/http-formauth-persistent/";
     
      // 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

   private void doHttpRedirect(String httpNoAuth) throws Exception
   {
      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

   }
   public void doHttps(String httpsNoAuth) throws Exception
   {
      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

    */
   public void testFormAuthSubject() throws Exception
   {
      log.info("+++ testFormAuthSubject");
      // Start by accessing the secured index.html of war1
      HttpClient httpConn = new HttpClient();
      GetMethod indexGet = new GetMethod(baseURLNoAuth+"form-auth/restricted/SecuredServlet");
      indexGet.setQueryString("validateSubject=true");
      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 );

      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", "jduke");
      formPost.addParameter("j_password", "theduke");
      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();
View Full Code Here

    */
   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

    */
   public void testCustomPrincipalTransmissionInVM() throws Exception
   {
     // JBAS-8540
      String baseURLNoAuth = "http://" + getServerHostForURL() + ":" + Integer.getInteger("web.port", 8080) + "/";
      HttpClient httpConn = new HttpClient();
      GetMethod indexGet = new GetMethod(baseURLNoAuth + "custom-principal/");
      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 + "custom-principal/j_security_check");
      formPost.addRequestHeader("Referer", baseURLNoAuth + "custom-principal/login.jsp");
      formPost.addParameter("j_username", this.username);
      formPost.addParameter("j_password", new String(password));
      responseCode = httpConn.executeMethod(formPost.getHostConfiguration(), formPost, state);
      String loginResult = formPost.getResponseBodyAsString();
      if( loginResult.indexOf("Encountered a login error") > 0 )
         fail("Login Failed");

      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 index.jsp
      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();
View Full Code Here

      String warA1 = serverA + "/" + firstWar +"/";
      String warB1 = serverB + "/" + firstWar +"/";
      String warB2 = serverB + "/" + secondWar +"/";
     
      // Start by accessing the secured index.html of war1
      HttpClient httpConn = new HttpClient();
      SSOBaseCase.checkAccessDenied(httpConn,  warA1 + "index.html");

      HttpState state = httpConn.getState();
     
      log.debug("Saw JSESSIONID="+SSOBaseCase.getSessionIdValueFromState(state));
     
      // Submit the login form
      SSOBaseCase.executeFormLogin(httpConn, warA1);
View Full Code Here

      String warA3 = serverA + "/war3/";
      String warB3 = serverB + "/war3/";
     
      // First create an SSO that we won't use again -- we later test that it
      // gets cleaned up from the cache
      HttpClient httpConn1 = new HttpClient();
      SSOBaseCase.checkAccessDenied(httpConn1, warA3 + "index.jsp");
      SSOBaseCase.executeFormLogin(httpConn1, warA3);
      HttpState state = httpConn1.getState();     
      String sessionID1 = SSOBaseCase.getSessionIdValueFromState(state);
     
      // Now the standard SSO tests
      HttpClient httpConn = new HttpClient();
      SSOBaseCase.checkAccessDenied(httpConn, warA3 + "index.jsp");
      state = httpConn.getState();     
      log.debug("Saw JSESSIONID="+SSOBaseCase.getSessionIdValueFromState(state));
      SSOBaseCase.executeFormLogin(httpConn, warA3);
      String ssoID = SSOBaseCase.processSSOCookie(state, serverA, serverB);
      log.debug("Saw JSESSIONIDSSO="+ssoID);
      log.info("stage1, sleep for 15 seconds");
View Full Code Here

TOP

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

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.