Package org.apache.commons.httpclient.methods

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


      method = new GetMethod(url);
    } else if (methodType.equalsIgnoreCase("post")) {
      PostMethod postMethod = new PostMethod(url);
      if (args != null) {
        byte[] output = constructArgs(method, args);
        postMethod.setRequestEntity(new ByteArrayRequestEntity(output));
      }
      method = postMethod;
    } else if (methodType.equalsIgnoreCase("put")) {
      method = new PutMethod(url);
      if (args != null) {
        byte[] output = constructArgs(method, args);
        ((PutMethod) method)
            .setRequestEntity(new ByteArrayRequestEntity(output));
      }
    } else if (methodType.equalsIgnoreCase("delete")) {
      method = new DeleteMethod(url);
    }
View Full Code Here


   @Test
   public void test534() throws Exception
   {
      HttpClient client = new HttpClient();
      PostMethod post = new PostMethod(generateURL("/inputstream/test/json"));
      ByteArrayRequestEntity entity = new ByteArrayRequestEntity("hello world".getBytes(), null);
      post.setRequestEntity(entity);
      int status = client.executeMethod(post);
      Assert.assertEquals(204, status);
      post.releaseConnection();
   }
View Full Code Here

   public void testEchoDataSourceSmallData() throws Exception
   {
      HttpClient client = new HttpClient();
      byte[] input = "Hello World!".getBytes("utf-8");
      PostMethod method = new PostMethod(TEST_URI + "/echo");
      method.setRequestEntity(new ByteArrayRequestEntity(input, MediaType.APPLICATION_OCTET_STREAM));
      int status = client.executeMethod(method);
      Assert.assertEquals(HttpServletResponse.SC_OK, status);

      InputStream ris = null;
      InputStream bis = null;
View Full Code Here

        + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
        + "<xmlBean><myInt>27</myInt><myString>Lorem Ipsum</myString></xmlBean>\r\n"
        + "--boo--\r\n";
    HttpClient httpClient = new HttpClient();
    PostMethod postMethod = new PostMethod(TEST_URI + "/mime");
    postMethod.setRequestEntity(new ByteArrayRequestEntity(message
        .getBytes("utf-8"), "multipart/form-data; boundary=boo"));
    httpClient.executeMethod(postMethod);
    String response = postMethod.getResponseBodyAsString();
    Assert.assertEquals("Status code is wrong.", 20, postMethod
        .getStatusCode() / 10);
View Full Code Here

        + "Content-Disposition: form-data; name=\"foo\"\r\n"
        + "Content-Transfer-Encoding: 8bit\r\n\r\n" + "bar\r\n"
        + "--boo--\r\n";
    HttpClient httpClient = new HttpClient();
    PostMethod postMethod = new PostMethod(TEST_URI + "/mime");
    postMethod.setRequestEntity(new ByteArrayRequestEntity(message
        .getBytes("utf-8"), "multipart/form-data; boundary=boo"));
    httpClient.executeMethod(postMethod);
    String response = postMethod.getResponseBodyAsString();
    Assert.assertEquals("Status code is wrong.", 20, postMethod
        .getStatusCode() / 10);
View Full Code Here

         
         
          //log.debug(stringToPost);
         
          RequestEntity entity = new ByteArrayRequestEntity(stringToPost.getBytes(Charset.forName("ISO-8859-1")));
         
          //Prepare HTTP post
         
          post.getParams().setContentCharset("ISO-8859-1");
          post.getParams().setVersion(HttpVersion.HTTP_1_0);
View Full Code Here

                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final GZIPOutputStream gzipOut = new GZIPOutputStream(baos);
                gzipOut.write(p.getBytes("UTF-8"));
                gzipOut.close();
                final byte[] gzippedEncodedJson = baos.toByteArray();
                method.setRequestEntity(new ByteArrayRequestEntity(gzippedEncodedJson, "application/json"));
                lastRequestEncoding = "gzip";
            } else {
                // otherwise plaintext:
                method.setRequestEntity(new StringRequestEntity(p, "application/json", "UTF-8"));
                lastRequestEncoding = "plaintext";
View Full Code Here

        RequestEntity entity = in.getBody(RequestEntity.class);
        if (entity == null) {
            byte[] data = in.getBody(byte[].class);
            String contentType = in.getHeader("Content-Type", String.class);
            if (contentType != null) {
                return new ByteArrayRequestEntity(data, contentType);
            } else {
                return new ByteArrayRequestEntity(data);
            }
        }
        return entity;
    }
View Full Code Here

        PostMethod method = new PostMethod(redirectUrl);
        method.setQueryString("to=" + URIUtil.encodeWithinQuery(
                    client.getHostConfiguration().getHostURL() + "/"
                    + getWebappContext() + "/params?foo=bar&bar=foo"));
        byte[] body = EncodingUtil.getBytes(bodyStr, "ISO-8859-1");
        method.setRequestEntity(new ByteArrayRequestEntity(body));
       
        try {
            client.executeMethod(method);
        } catch (Throwable t) {
            t.printStackTrace();
View Full Code Here

            ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
            for (int c = 0; c < 5000000; ++c) {
                originalContent.write(c);
            }
            byte[] entity = originalContent.toByteArray();
            postMethod.setRequestEntity(new ByteArrayRequestEntity(entity, "text/xml"));
            client.executeMethod(postMethod);
            assertEquals(277, postMethod.getStatusCode());

            InputStream respStream = postMethod.getResponseBodyAsStream();
            for (int c = 0; c < entity.length; ++c) {
View Full Code Here

TOP

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

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.