Package org.apache.commons.httpclient.methods

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


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

      GetMethod method = new GetMethod(url);
      int responseCode = 0;
      try
      {
         responseCode = client.executeMethod(method);
      } catch (IOException e)
      {
         e.printStackTrace();
      }
      assertTrue("Should not be OK code with url: " +url + " responseCode: " +responseCode
        , responseCode != HttpURLConnection.HTTP_OK);

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

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

      // Deal with the response.
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());
      }
      assertEquals("Get OK", HttpURLConnection.HTTP_OK, responseCode);

      // Read the response body.
      byte[] responseBody = method.getResponseBody();
      /* Validate that the attribute was actually seen. An absence of the
         header is treated as true since there are pages used that done't
         add it.
      */
      Header hdr = method.getResponseHeader("X-SawTestHttpAttribute");
      Boolean sawAttr = hdr != null ? Boolean.valueOf(hdr.getValue()) : Boolean.TRUE;
      String attr = null;
      if( sawAttr.booleanValue() )
         attr = new String(responseBody);
      // Release the connection.
View Full Code Here

      baseURLNoAuth = "http://" + getServerHostForURL() + ":" + Integer.getInteger("web.port", 8080) + "/";
   }
  
   public void testFormAuthSuccess() throws Exception
   {
      GetMethod indexGet = new GetMethod(baseURLNoAuth+"jaspi-web-form/");
      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+"jaspi-web-form/j_security_check");
      formPost.addRequestHeader("Referer", baseURLNoAuth+"jaspi-web-form/login.jsp");
      formPost.addParameter("j_username", username);
      formPost.addParameter("j_password", password);
      responseCode = httpConn.executeMethod(formPost);
      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);
      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");
      if( body.indexOf("Hi Anil") < 0 )
         fail("index.html not seen");
   }
View Full Code Here

   }
  
   public void testFormAuthFailure() throws Exception
   {
      log.info("+++ testFormAuthFailure");
      GetMethod indexGet = new GetMethod(baseURLNoAuth+"jaspi-web-form/");
      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();
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();
      log.debug("Final result obtained:"+body);
      if( body.indexOf("j_security_check") > 0 )
         fail("get of "+indexURI+" redirected to login page");
      if( body.indexOf("Propagation Success") < 0 )
         fail("Propagation of custom principal within VM failed")
View Full Code Here

      super(name);
   }

   protected String get(String spec) throws IOException
   {
      HttpMethodBase request = new GetMethod(HttpUtils.getBaseURL() + spec);
      client.executeMethod(request);

      String responseBody = request.getResponseBodyAsString();
      request.releaseConnection();
      return responseBody;
   }
View Full Code Here

   protected String checkDeserialization(HttpClient client, String url, boolean expectDeserialized)
      throws IOException
   {
      getLog().debug("checkDeserialization(): 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);
     
      Header header = method.getResponseHeader("X-SessionDeserialized");
      assertNotNull("Test existence of X-SessionDeserialized response header", header);
      Boolean headerValue = Boolean.valueOf(header.getValue());
      assertEquals("Validate X-SessionDeserialized header: " + header.getValue(), expectDeserialized, headerValue.booleanValue());
     
      // Read the response body.
      byte[] responseBody = method.getResponseBody();

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

      // Deal with the response.
View Full Code Here

   }
  
   // makes default GetMethod request for index.jsf
   private GetMethod makeRequest(String warName)
   {
      return new GetMethod(makeRequestString(warName, "index.jsf"));
   }
View Full Code Here

    */
   protected boolean checkNew(HttpClient client, String url)
   {
      getLog().info("checkNew(): 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());
      }
      assertTrue("Get OK with url: " +url + " responseCode: " +responseCode
        , responseCode == HttpURLConnection.HTTP_OK);

      Header hdr = method.getResponseHeader("X-SessionIsNew");
      assertNotNull("Got X-SessionIsNew header", hdr);
      String value = hdr.getValue();
      assertNotNull("Got non-nullX-SessionIsNew header", value);
     
      return Boolean.valueOf(value).booleanValue();
View Full Code Here

   }

   public static void executeLogout(HttpClient httpConn, String warURL) throws IOException, HttpException
   {
      GetMethod logout = new GetMethod(warURL + "Logout");
      logout.setFollowRedirects(false);
      int responseCode = httpConn.executeMethod(logout.getHostConfiguration(),
         logout, httpConn.getState());
      assertTrue("Logout: Saw HTTP_MOVED_TEMP("+responseCode+")",
         responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
      Header location = logout.getResponseHeader("Location");
      String indexURI = location.getValue();
      if( indexURI.indexOf("index.html") < 0 )
         fail("get of " + warURL + "Logout not redirected to login page");
   }
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.