Examples of GetMethod


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

    *
    * @throws Exception if an error occurs when running the test.
    */
   public void testRegularFormAuth() throws Exception
   {
      GetMethod getMethod = new GetMethod(this.testAppBaseURL + this.securedServletPath);
      // execute a plain request to the SecureServlet
      try
      {
         int responseCode = this.httpClient.executeMethod(getMethod);
         String body = getMethod.getResponseBodyAsString();
         // check the response code and assert the redirection to the login page
         assertTrue("Unexpected response code received: " + responseCode, responseCode == HttpURLConnection.HTTP_OK);
         assertTrue("Failed to redirect the request to the login page", body.indexOf("j_security_check") > 0);
      }
      finally
      {
         getMethod.releaseConnection();
      }

      HttpState state = this.httpClient.getState();
      // fill in the login form and submit it
      PostMethod postMethod = new PostMethod(this.testAppBaseURL + "j_security_check");
      postMethod.addRequestHeader("Referer", this.testAppBaseURL + "restricted/login.html");
      postMethod.addParameter("j_username", "jduke");
      postMethod.addParameter("j_password", "theduke");
      Header location = null;
      try
      {
         int responseCode = this.httpClient.executeMethod(postMethod.getHostConfiguration(), postMethod, state);
         log.debug("responseCode=" + responseCode + ", response=" + postMethod.getStatusText());
         // check the response code received and the presence of a location header in the response
         assertTrue("Unexpected response code received: " + responseCode,
               responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
         location = postMethod.getResponseHeader("Location");
         assertNotNull("Location header not found in response", location);
      }
      finally
      {
         postMethod.releaseConnection();
      }

      // follow the redirect as defined by the location header
      String indexURI = location.getValue();
      getMethod = new GetMethod(indexURI);
      try
      {
         int responseCode = this.httpClient.executeMethod(getMethod.getHostConfiguration(), getMethod, state);
         log.debug("responseCode=" + responseCode + ", response=" + getMethod.getStatusText());
         // check the reponse code received
         assertTrue("Unexpected response code received: " + responseCode, responseCode == HttpURLConnection.HTTP_OK);
         String body = getMethod.getResponseBodyAsString();
         // assert the redirection of to the SecureServlet
         assertTrue("Redirect to SecureServlet has failed", body.indexOf("SecureServlet") > 0);
      }
      finally
      {
         getMethod.releaseConnection();
      }
   }
View Full Code Here

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

    * @param usecase a <code>String</code> representing the name of the use case being tested.
    * @throws Exception if an error occurs when authenticating the user.
    */
   private void performHeaderAuth(String headerId, Cookie cookie, String usecase) throws Exception
   {
      GetMethod method = new GetMethod(this.testAppBaseURL + this.securedServletPath);
      // add the headerId and cookie objects to the request
      method.addRequestHeader(headerId, "jduke");
      this.httpClient.getState().addCookie(cookie);
      // execute the request
      try
      {
         int responseCode = this.httpClient.executeMethod(method);
         // check the response code received
         log.debug("Response from " + usecase + " case:" + method.getStatusText());
         assertTrue("Unexpected response code received: " + responseCode, responseCode == HttpURLConnection.HTTP_OK);
         // check that access to the secure servlet has been granted
         String body = method.getResponseBodyAsString();
         assertTrue("Access to SecureServlet has not been granted", body.indexOf("SecureServlet") > 0);
      }
      finally
      {
         // release the connection
         method.releaseConnection();
      }
   }
View Full Code Here

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

   public void testWeb() throws Exception
   {
      String baseURLNoAuth = "http://" + getServerHostForURL() +
                     ":" + Integer.getInteger("web.port", 8080) + "/";
      HttpClient httpConn = new HttpClient();
      GetMethod indexGet = new GetMethod(baseURLNoAuth + "sdtolerate/");
      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 + "sdtolerate/j_security_check");
      formPost.addRequestHeader("Referer", baseURLNoAuth + "sdtolerate/login.jsp");
      formPost.addParameter("j_username", this.username);
      formPost.addParameter("j_password", new String(password));
      responseCode = httpConn.executeMethod(formPost);
      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);
      response = war1Index.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
   }
View Full Code Here

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

   {
      HttpMethodBase request = null;
      switch( type )
      {
         case GET:
            request = new GetMethod(url.toString());
            break;
         case POST:
            request = new PostMethod(url.toString());
            break;
         case HEAD:
View Full Code Here

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

      this.deploy("jbosssx-jaspi-web.war");
      try
      {
         //Check successful validation
         String str = "jbosssx-jaspi-web/DebugServlet?user=jduke&pass=theduke";
         GetMethod indexGet = new GetMethod(baseURLNoAuth+str);
         int responseCode = httpConn.executeMethod(indexGet);
         assertTrue("Response code == 200?", responseCode == 200);
         //Test unsuccessful validation
         str = "jbosssx-jaspi-web/DebugServlet?user=jduke&pass=bad";
         indexGet = new GetMethod(baseURLNoAuth+str);
         responseCode = httpConn.executeMethod(indexGet);
         assertTrue("Response code == 500?", responseCode == 500);   
      }
      catch(Throwable t)
      {
View Full Code Here

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

    */
   public void testWebAccess() throws Exception
   {
      baseURLNoAuth = "http://" + getServerHostForURL()
            + ":" + Integer.getInteger("web.port", 8080) + "/";
      GetMethod indexGet = new GetMethod(baseURLNoAuth+"web-role-map/Secured.jsp");
      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+"web-role-map/j_security_check");
      formPost.addRequestHeader("Referer", baseURLNoAuth+"web-role-map/login.html");
      formPost.addParameter("j_username", "user");
      formPost.addParameter("j_password", "pass");
      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");
   }
View Full Code Here

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

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

      {
         GetMethod method = new GetMethod("http://localhost:8080/resteasy/basic");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("basic", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         // I'm testing unknown content-length here
         GetMethod method = new GetMethod("http://localhost:8080/resteasy/xml");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         String result = method.getResponseBodyAsString();
         JAXBContext ctx = JAXBContext.newInstance(Customer.class);
         Customer cust = (Customer) ctx.createUnmarshaller().unmarshal(new StringReader(result));
         Assert.assertEquals("Bill Burke", cust.getName());
         method.releaseConnection();
      }

   }
View Full Code Here

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

   @Test
   public void testGzip() throws Exception
   {
      HttpClient client = new HttpClient();
      {
         GetMethod get = new GetMethod("http://localhost:8080/resteasy/gzip");
         get.addRequestHeader("Accept-Encoding", "gzip, deflate");
         int status = client.executeMethod(get);
         Assert.assertEquals(200, status);
         Assert.assertEquals("gzip", get.getResponseHeader("Content-Encoding").getValue());
         GZIPInputStream gzip = new GZIPInputStream(get.getResponseBodyAsStream());
         String response = readString(gzip);


         // test that it is actually zipped
         Assert.assertEquals(response, "HELLO WORLD");
View Full Code Here

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

   @Test
   public void testNewInstanceCreatedForEveryRequest()
   {
      HttpClient client = new HttpClient();
      GetMethod get1 = new GetMethod(BASE_URI + getTestPrefix() + "toString");
      get1.addRequestHeader("Accept", "text/plain");
      GetMethod get2 = new GetMethod(BASE_URI + getTestPrefix() + "toString");
      get2.addRequestHeader("Accept", "text/plain");
      try
      {
         int status1 = client.executeMethod(get1);
         assertEquals(status1, 200);
         String response1 = get1.getResponseBodyAsString();
         get1.releaseConnection();
         int status2 = client.executeMethod(get2);
         assertEquals(status2, 200);
         String response2 = get2.getResponseBodyAsString();
         get2.releaseConnection();
         assertFalse(response1.equals(response2));
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
View Full Code Here

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

public class AppConfigTest
{
   private void _test(HttpClient client, String uri, String body)
   {
      {
         GetMethod method = new GetMethod(uri);
         try
         {
            method.addRequestHeader("Accept", "text/quoted");
            int status = client.executeMethod(method);
            Assert.assertEquals(status, HttpResponseCodes.SC_OK);
            Assert.assertEquals(body, method.getResponseBodyAsString());
         }
         catch (IOException e)
         {
            throw new RuntimeException(e);
         }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.