Package org.apache.commons.httpclient.methods

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


   @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

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

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

   {
      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

   private boolean makeGet(HttpClient client, String url, boolean expectSuccess)
      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());
      }
      boolean ok = false;
      if (expectSuccess)
      {
        ok = responseCode == HttpURLConnection.HTTP_OK;
      }
      else
      {
        ok = 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

   {
      String index = "/farmD/index.html";

      HttpClient client = new HttpClient();

      GetMethod get = new GetMethod(getHttpURLs()[0] +index);
      assertEquals("farmD is unavailable on node0", HttpURLConnection.HTTP_NOT_FOUND, client.executeMethod(get));
      get = new GetMethod(getHttpURLs()[1] +index);
      assertEquals("farmD is unavailable on node1", HttpURLConnection.HTTP_NOT_FOUND, client.executeMethod(get));
   }
View Full Code Here

   private void checkAvailable(String url) throws Exception, IOException, HttpException
   {
      HttpClient client = new HttpClient();

      GetMethod get = new GetMethod(getHttpURLs()[0] +url);
      assertEquals(url + " is available on node0", HttpURLConnection.HTTP_OK, client.executeMethod(get));
      get = new GetMethod(getHttpURLs()[1] +url);
      assertEquals(url + " is available on node1", HttpURLConnection.HTTP_OK, client.executeMethod(get));
   }
View Full Code Here

    * @throws Exception
    */
   public void testFormAuthException() throws Exception
   {
      log.info("+++ testFormAuthException");
      GetMethod indexGet = new GetMethod(baseURLNoAuth+"form-auth/restricted/SecuredServlet");
      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 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();
      if( body.indexOf("j_security_check") > 0 )
         fail("get of "+indexURI+" 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.