Package org.apache.commons.httpclient.methods

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


    System.out.println("testServerMultiFile");
         
      HttpServer server = new HttpServer(new RequestHandler());
      server.start();
         
      PostMethod filePost = new PostMethod("http://localhost:" + server.getLocalPort() + "/");
      org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
     
      File file1 = QAUtil.createTestfile_40k();
      File file2 = QAUtil.createTestfile_4k();
     
      Part part1 = new FilePart("file40k", file1);
      Part part2 = new FilePart("file4k", file2);
         
      HttpMethodParams params = new HttpMethodParams();
      params.setBooleanParameter("testb", false);
      filePost.setRequestEntity(new MultipartRequestEntity(new Part[] {part1, part2 }, params));
         
      client.executeMethod(filePost);
     
      if (filePost.getStatusCode() != 200) {
          Assert.fail("error occured");
      }

      file1.delete();
      file2.delete();
View Full Code Here


      System.out.println("testServerMultiStringPartFile");
     
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
           
        PostMethod filePost = new PostMethod("http://localhost:" + server.getLocalPort() + "/");
        org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
           
        Part part1 = new StringPart("part1", "0123456789\r\n");
        Part part2 = new StringPart("part2", "567890\r\n");
        Part part3 = new StringPart("part3", "3456\r\n");
       
        HttpMethodParams params = new HttpMethodParams();
        params.setBooleanParameter("testb", false);
        filePost.setRequestEntity(new MultipartRequestEntity(new Part[] {part1, part2, part3 }, params));
           
        client.executeMethod(filePost);
       
        if (filePost.getStatusCode() != 200) {
            Assert.fail("error occured");
        }
           
        server.close();
    }
View Full Code Here

  @Test
  public void testApacheClient() throws Exception {

    org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
   
    PostMethod postMethod = new PostMethod(url);
    postMethod.addParameter(new org.apache.commons.httpclient.NameValuePair("file", new String(HttpUtils.encodeBase64(data), "US-ASCII")));

    httpClient.executeMethod(postMethod);
     
      Assert.assertEquals(200, postMethod.getStatusCode());
      Assert.assertTrue(QAUtil.isEquals(file, postMethod.getResponseBody()));
     
      postMethod.releaseConnection();
  }     
View Full Code Here


        org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
        httpClient.getParams().setParameter("http.protocol.expect-continue", true);

        PostMethod meth = new PostMethod("http://localhost:" + server.getLocalPort() + "/test");
        meth.setRequestBody("OK");

        httpClient.executeMethod(meth);
       
        Assert.assertEquals(200, meth.getStatusCode());
        Assert.assertEquals("OK", meth.getResponseBodyAsString());
       
        meth.releaseConnection();
       
        server.close();
    }
View Full Code Here

        + "Content-Transfer-Encoding: 8bit\r\n\r\n"
        + "<?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);
    Assert.assertEquals("Response text is wrong", "27", response);
  }
View Full Code Here

    String message = "--boo\r\n"
        + "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);
    Assert.assertEquals("Response text is wrong", MediaType
        .valueOf(TEXT_PLAIN_WITH_CHARSET_UTF_8), MediaType
        .valueOf(response));
  }
View Full Code Here

        Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());

        NameValuePair[] nameValuePairs = new NameValuePair[1];
        nameValuePairs[0] = new NameValuePair("tags", tagName);

        PostMethod postMethod =
            executePostForm(String.format("%s?method=PUT", getUriBuilder(PageTagsResource.class).build(getWiki(),
                TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString()), nameValuePairs, "Admin",
                "admin");
        Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.getStatusCode());

        getMethod =
            executeGet(getUriBuilder(PageTagsResource.class).build(getWiki(), TestConstants.TEST_SPACE_NAME,
                TestConstants.TEST_PAGE_NAME).toString());
        Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
View Full Code Here

    server.start();
   
   
   
    HttpClient httpClient = new HttpClient();
    PostMethod meth = new PostMethod("http://localhost:" + server.getLocalPort() + "/");
    meth.setRequestBody("test123456");

    httpClient.executeMethod(meth);
   
    String body = meth.getResponseBodyAsString();
    Assert.assertEquals("Hello", body);
 
    meth.releaseConnection();
    server.close();
  }
View Full Code Here

        NameValuePair[] nameValuePairs = new NameValuePair[2];
        nameValuePairs[0] = new NameValuePair("title", TITLE);
        nameValuePairs[1] = new NameValuePair("content", CONTENT);

        PostMethod postMethod =
            executePostForm(String.format("%s?method=PUT", link.getHref()), nameValuePairs, "Admin", "admin");
        Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.getStatusCode());

        Page modifiedPage = (Page) unmarshaller.unmarshal(postMethod.getResponseBodyAsStream());

        Assert.assertEquals(modifiedPage.getContent(), CONTENT);
        Assert.assertEquals(modifiedPage.getTitle(), TITLE);
    }
View Full Code Here

        int numberOfComments = comments.getComments().size();

        Comment comment = objectFactory.createComment();
        comment.setText("Comment");

        PostMethod postMethod = executePostXml(commentsUri, comment, "Admin", "admin");
        Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode());

        getMethod = executeGet(commentsUri);
        Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());

        comments = (Comments) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
View Full Code Here

TOP

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

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.