Package org.apache.commons.httpclient.methods

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


   {
      HttpClient client = new HttpClient();
      {
         latch = new CountDownLatch(1);
         PostMethod method = createPostMethod("?asynch=true");
         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         long start = System.currentTimeMillis();
         int status = client.executeMethod(method);
         @SuppressWarnings("unused")
         long end = System.currentTimeMillis() - start;
         Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
         String jobUrl = method.getResponseHeader(HttpHeaders.LOCATION).getValue();
         System.out.println("JOB: " + jobUrl);
         GetMethod get = new GetMethod(jobUrl);
         status = client.executeMethod(get);
         Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
         Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));
         // there's a lag between when the latch completes and the executor
         // registers the completion of the call
         String existingQueryString = get.getQueryString();
         get.setQueryString((existingQueryString == null ? "" : "&") + "wait=1000");
         status = client.executeMethod(get);
         Assert.assertEquals(HttpServletResponse.SC_OK, status);
         Assert.assertEquals(get.getResponseBodyAsString(), "content");

         // test its still there
         status = client.executeMethod(get);
         Assert.assertEquals(HttpServletResponse.SC_OK, status);
         Assert.assertEquals(get.getResponseBodyAsString(), "content");

         // delete and test delete
         DeleteMethod delete = new DeleteMethod(jobUrl);
         status = client.executeMethod(delete);
         Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, status);

         status = client.executeMethod(get);
         Assert.assertEquals(HttpServletResponse.SC_GONE, status);

         method.releaseConnection();
      }

      {
         dispatcher.setMaxCacheSize(1);
         latch = new CountDownLatch(1);
         PostMethod method = createPostMethod("?asynch=true");
         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
         String jobUrl1 = method.getResponseHeader(HttpHeaders.LOCATION).getValue();
         Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));

         latch = new CountDownLatch(1);
         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         status = client.executeMethod(method);
         Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
         String jobUrl2 = method.getResponseHeader(HttpHeaders.LOCATION).getValue();
         Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));

         Assert.assertTrue(!jobUrl1.equals(jobUrl2));

         GetMethod get = new GetMethod(jobUrl1);
         status = client.executeMethod(get);
         Assert.assertEquals(HttpServletResponse.SC_GONE, status);

         // test its still there
         get = new GetMethod(jobUrl2);
         status = client.executeMethod(get);
         Assert.assertEquals(HttpServletResponse.SC_OK, status);
         Assert.assertEquals(get.getResponseBodyAsString(), "content");

         // delete and test delete
         DeleteMethod delete = new DeleteMethod(jobUrl2);
         status = client.executeMethod(delete);
         Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, status);

         status = client.executeMethod(get);
         Assert.assertEquals(HttpServletResponse.SC_GONE, status);

         method.releaseConnection();
      }
      // test readAndRemove
      {
         dispatcher.setMaxCacheSize(10);
         latch = new CountDownLatch(1);
         PostMethod method = createPostMethod("?asynch=true");
         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, status);
         String jobUrl2 = method.getResponseHeader(HttpHeaders.LOCATION).getValue();
         Assert.assertTrue(latch.await(3, TimeUnit.SECONDS));
View Full Code Here


      HttpClient client = new HttpClient();
      {
         PostMethod method = createPostMethod("/RESTEASY-109");
         try
         {
            method.setRequestEntity(new StringRequestEntity("name=jon&address1=123+Main+St&address2=&zip=12345",
                    MediaType.APPLICATION_FORM_URLENCODED, null));
            int status = client.executeMethod(method);
            Assert.assertEquals(status, 204);
         }
         catch (IOException e)
View Full Code Here

      {
         HttpClient client = new HttpClient();
         PostMethod method = createPostMethod("");
         try
         {
            method.setRequestEntity(new StringRequestEntity(
                    "<?xml version=\"1.0\"?><person><name>bill</name></person>",
                    "application/xml", null));
            int status = client.executeMethod(method);
            Assert.assertEquals(status, 204);
         }
         catch (IOException e)
         {
            throw new RuntimeException(e);
         }
      }
      {
         HttpClient client = new HttpClient();
         PostMethod method = createPostMethod("/kunde");
         try
         {
            method.setRequestEntity(new StringRequestEntity(kundeXml, "application/xml", null));
            int status = client.executeMethod(method);
            Assert.assertEquals(status, 204);
         }
         catch (IOException e)
         {
View Full Code Here

      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(generateBaseUrl());
      method.addRequestHeader(HttpHeaderNames.ACCEPT, "application/bar");
      try
      {
         method.setRequestEntity(new StringRequestEntity("content", "application/bar", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(status, HttpResponseCodes.SC_NOT_ACCEPTABLE);
      }
      catch (IOException e)
      {
View Full Code Here

   {
      HttpClient client = new HttpClient();
      PostMethod method = createPostMethod("/nocontent");
      try
      {
         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(status, HttpResponseCodes.SC_NO_CONTENT);
      }
      catch (IOException e)
      {
View Full Code Here

      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(generateBaseUrl());
      method.addRequestHeader(HttpHeaderNames.ACCEPT, "application/foo");
      try
      {
         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(status, HttpResponseCodes.SC_UNSUPPORTED_MEDIA_TYPE);
      }
      catch (IOException e)
      {
View Full Code Here

         Assert.assertEquals("basic", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         PutMethod method = new PutMethod("http://localhost:8080/test-war/basic");
         method.setRequestEntity(new StringRequestEntity("basic", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(204, status);
         method.releaseConnection();
      }
      {
View Full Code Here

         Assert.assertEquals("basic", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         PutMethod method = new PutMethod("http://localhost:8080/test-war/locating/basic");
         method.setRequestEntity(new StringRequestEntity("basic", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(204, status);
         method.releaseConnection();
      }
      {
View Full Code Here

        StringWriter writer = new StringWriter();
        marshaller.marshal(object, writer);

        RequestEntity entity =
            new StringRequestEntity(writer.toString(), MediaType.APPLICATION_XML.toString(), "UTF-8");
        postMethod.setRequestEntity(entity);

        httpClient.executeMethod(postMethod);

        return postMethod;
View Full Code Here

        StringWriter writer = new StringWriter();
        marshaller.marshal(object, writer);

        RequestEntity entity =
            new StringRequestEntity(writer.toString(), MediaType.APPLICATION_XML.toString(), "UTF-8");
        postMethod.setRequestEntity(entity);

        httpClient.executeMethod(postMethod);

        return postMethod;
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.StringRequestEntity

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.