Package org.apache.commons.httpclient.methods

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


   private HttpMethodBase createHttpMethod(String url, String restVerb)
   {
      if ("GET".equals(restVerb))
      {
         return new GetMethod(url);
      }
      else if ("POST".equals(restVerb))
      {
         return new PostMethod(url);
      }
View Full Code Here

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

      {
         GetMethod method = new GetMethod("http://localhost:8080/basic-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/basic-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/basic-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/basic-integration-test/uriParam/1234");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("1234", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         // I'm testing unknown content-length here
         GetMethod method = new GetMethod("http://localhost:8080/basic-integration-test/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

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

      {
         GetMethod method = new GetMethod("http://localhost:8080/basic-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/basic-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/basic-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/basic-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

      @Test
      public void testGet() throws Exception
      {
         HttpClient client = new HttpClient();
         {
            GetMethod method = new GetMethod("http://localhost:8080/basic-integration-test/simple/"+encodedPart);
            method.setQueryString("foo="+encodedPart);
            System.out.println(method.getURI());
            try
            {
               int status = client.executeMethod(method);
               Assert.assertEquals(HttpResponseCodes.SC_OK, status);
               String body = method.getResponseBodyAsString();
               Assert.assertEquals(decodedPart, body);
            }
            catch (Exception e)
            {
               throw new RuntimeException(e);
View Full Code Here

          //new AuthScope(null, 8080, "Test"),
          new AuthScope(AuthScope.ANY),
          new UsernamePasswordCredentials("bill", "password")
      );
      {
         GetMethod method = new GetMethod("http://localhost:8080/basic-integration-test/security");
         method.setDoAuthentication(true);
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("Wild", method.getResponseBodyAsString());
         method.releaseConnection();
      }
   }
View Full Code Here

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

      {
         GetMethod method = new GetMethod("http://localhost:8080/basic-integration-test/security");
         int status = client.executeMethod(method);
         Assert.assertEquals(401, status);
         method.releaseConnection();
      }
   }
View Full Code Here

   @Test
   public void testAtomFeed() throws Exception
   {
      HttpClient client = new HttpClient();
      GetMethod get = createGetMethod("/atom/feed");
      int status = client.executeMethod(get);
      Assert.assertEquals(200, status);
      System.out.println(get.getResponseBodyAsString());

      AtomServerInterface intf = createProxy(AtomServerInterface.class);
      Feed feed = intf.postFeed(RFC_COMPLEX_XML);
      assertFeed(feed);
View Full Code Here

   @Test
   public void testAtomEntry() throws Exception
   {
      HttpClient client = new HttpClient();
      GetMethod get = createGetMethod("/atom/entry");
      int status = client.executeMethod(get);
      Assert.assertEquals(200, status);
      System.out.println(get.getResponseBodyAsString());
   }
View Full Code Here

         PutMethod method = new PutMethod("http://localhost:9095/resource?oneway=true");
         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(202, status);
         Thread.sleep(1500);
         GetMethod get = new GetMethod("http://localhost:9095/resource");
         status = client.executeMethod(get);
         Assert.assertEquals(Integer.toString(1), get.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.