Package org.apache.commons.httpclient.methods

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


         fail("get of " + warURL + "Logout not redirected to login page");
   }

   public static void checkAccessAllowed(HttpClient httpConn, String url) throws IOException, HttpException
   {
      GetMethod war2Index = new GetMethod(url);
      int responseCode = httpConn.executeMethod(war2Index.getHostConfiguration(),
         war2Index, httpConn.getState());
      assertTrue("expected response code == OK but got " + responseCode+" for request=" + url, responseCode == HttpURLConnection.HTTP_OK);
      String body = war2Index.getResponseBodyAsString();
      if( body.indexOf("j_security_check") > 0 )
         fail("get of " + url + " redirected to login page");
   }
View Full Code Here


         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);
      String body = warIndex.getResponseBodyAsString();
      if( body.indexOf("j_security_check") > 0 )
         fail("get of "+indexURI+" redirected to login page");
   }
View Full Code Here

         fail("get of "+indexURI+" redirected to login page");
   }

   public static void checkAccessDenied(HttpClient httpConn, String url) throws IOException, HttpException
   {
      GetMethod indexGet = new GetMethod(url);
      int responseCode = httpConn.executeMethod(indexGet);
      String body = indexGet.getResponseBodyAsString();
      assertTrue("Expected response code ==  OK but got "+responseCode+" for request=" + url, responseCode == HttpURLConnection.HTTP_OK);
      assertTrue("Redirected to login page for request=" + url +", body=[" +body+"]", body.indexOf("j_security_check") > 0 );
   }
View Full Code Here

   public void testStatusServlet() throws Exception
   {
      HttpClient httpConn = new HttpClient();
      String url = "http://" + getServerHost() + ":" + Integer.getInteger("web.port", 8080) + "/status?full=true";
      GetMethod getMethod = new GetMethod(url);
      int responseCode = httpConn.executeMethod(getMethod);
      assertEquals("GET " + url + " OK", HttpURLConnection.HTTP_OK, responseCode);
   }
View Full Code Here

   {
      boolean node0OK = false;
      boolean node1OK = false;
     
      String[] hosts = getHttpURLs();
      GetMethod get0 = new GetMethod(hosts[0] + relativePath);
      GetMethod get1 = new GetMethod(hosts[1] + relativePath);
     
//      long deadline = System.currentTimeMillis() + timeout;
      do
      {
         if (!node0OK)
View Full Code Here

      String path = "war1/TestServlet";
      // try to perform programmatic auth without supplying login information.
      HttpMethod indexGet = null;
      try
      {
         indexGet = new GetMethod(baseURLNoAuth + path + "?operation=login");
         int responseCode = httpConn.executeMethod(indexGet);
         assertTrue("Get Error(" + responseCode + ")",
               responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR);
         // assert access to the restricted area of the first application is denied.
         SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth +
               "war1/restricted/restricted.html");
         // assert access to the second application is not granted, as no successful login
         // was performed (and therefore no ssoid has been set).
         SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth + "war2/index.html");
      }
      finally
      {
         if(indexGet != null)
           indexGet.releaseConnection();
      }
      // try to perform programmatic auth with no valid username/password.
      path = path + "?operation=login&username=dummy&pass=dummy";
      try
      {
         indexGet = new GetMethod(baseURLNoAuth + path);
         int responseCode = httpConn.executeMethod(indexGet);
         assertTrue("Get Error(" + responseCode + ")",
               responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR);
         // assert access to the restricted applications remains denied.
         SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth +
View Full Code Here

      String path1 = "war1/TestServlet?operation=login&username=jduke&pass=theduke";
      HttpMethod indexGet = null;
      HttpMethod indexGet2 = null;
      try
      {
         indexGet = new GetMethod(baseURLNoAuth + path1);
         int responseCode = httpConn.executeMethod(indexGet);
         assertTrue("Get OK(" + responseCode + ")", responseCode == HttpURLConnection.HTTP_OK);
         // assert access to the restricted are of the first application is now allowed.
         SSOBaseCase.checkAccessAllowed(this.httpConn, baseURLNoAuth +
               "war1/restricted/restricted.html");
         // assert the sso cookie has been created.
         SSOBaseCase.processSSOCookie(this.httpConn.getState(), baseURLNoAuth, baseURLNoAuth);
         // assert access to the second application is allowed.
         SSOBaseCase.checkAccessAllowed(this.httpConn, baseURLNoAuth + "war2/index.html");

         // perform a programmatic logout and assert access is not allowed anymore.
         indexGet2 = new GetMethod(baseURLNoAuth + "war1/TestServlet?operation=logout");
         responseCode = httpConn.executeMethod(indexGet2);
         assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
         SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth +
               "war1/restricted/restricted.html");
         SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth + "war2/index.html");
View Full Code Here

      log.info("+++ testJASPIClientCert, httpsNoAuth="+httpsNoAuth);
      // Start by accessing the secured index.html of war1
      HttpClient httpConn = new HttpClient();
      String url = httpsNoAuth+"clientcert-jaspi/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 testNoDefaultsResource() throws Exception
   {
      HttpClient client = new HttpClient();

      {
         GetMethod method = new GetMethod("http://localhost:8080/spring-integration-test/basic");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("basic", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         PutMethod method = new PutMethod("http://localhost:8080/spring-integration-test/basic");
         method.setRequestEntity(new StringRequestEntity("basic", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(204, status);
         method.releaseConnection();
      }
      {
         GetMethod method = new GetMethod("http://localhost:8080/spring-integration-test/queryParam");
         NameValuePair[] params = {new NameValuePair("param", "hello world")};
         method.setQueryString(params);
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("hello world", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         GetMethod method = new GetMethod("http://localhost:8080/spring-integration-test/uriParam/1234");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("1234", method.getResponseBodyAsString());
         method.releaseConnection();
      }
   }
View Full Code Here

   public void testLocatingResource() throws Exception
   {
      HttpClient client = new HttpClient();

      {
         GetMethod method = new GetMethod("http://localhost:8080/spring-integration-test/locating/basic");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("basic", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         PutMethod method = new PutMethod("http://localhost:8080/spring-integration-test/locating/basic");
         method.setRequestEntity(new StringRequestEntity("basic", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(204, status);
         method.releaseConnection();
      }
      {
         GetMethod method = new GetMethod("http://localhost:8080/spring-integration-test/locating/queryParam");
         NameValuePair[] params = {new NameValuePair("param", "hello world")};
         method.setQueryString(params);
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("hello world", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         GetMethod method = new GetMethod("http://localhost:8080/spring-integration-test/locating/uriParam/1234");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("1234", method.getResponseBodyAsString());
         method.releaseConnection();
      }
   }
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.