Package org.apache.http.entity.mime.content

Examples of org.apache.http.entity.mime.content.ContentBody


     *   otherwise.
     */
    public long getTotalLength() {
        long contentLen = 0;
        for (final FormBodyPart part: getBodyParts()) {
            final ContentBody body = part.getBody();
            final long len = body.getContentLength();
            if (len >= 0) {
                contentLen += len;
            } else {
                return -1;
            }
View Full Code Here


    try {
      HttpPost post = new HttpPost("http://localhost:9998/controller/router");
      is = getClass().getResourceAsStream("/UploadTestFile.txt");

      MultipartEntityBuilder builder = MultipartEntityBuilder.create();
      ContentBody cbFile = new InputStreamBody(is,
          ContentType.create("text/plain"), "UploadTestFile.txt");
      builder.addPart("fileUpload", cbFile);
      builder.addPart("extTID", new StringBody("2", ContentType.DEFAULT_TEXT));
      builder.addPart("extAction", new StringBody("fileUploadController",
          ContentType.DEFAULT_TEXT));
View Full Code Here

     * @throws UnsupportedEncodingException
     */
    public void prepareParts(IBoxJSONParser parser) throws UnsupportedEncodingException, BoxJSONException {
        for (Map.Entry<String, ContentBodyOrStringEntity> entry : parts.entrySet()) {
            ContentBodyOrStringEntity value = entry.getValue();
            ContentBody contentBody;
            if (value.contentBody != null) {
                contentBody = value.contentBody;
            } else {
                contentBody = new StringBody(value.boxJSONStringEntity.toJSONString(parser), Charset.forName(CharEncoding.UTF_8));
            }
View Full Code Here

            // duetime    : maximum time that a peer should spent to create a result

            // send request
            Map<String, String> resultMap = null;
            String key = "";
            final ContentBody keyBody = parts.get("key");
            if (keyBody != null) {
                final ByteArrayOutputStream baos = new ByteArrayOutputStream(20);
                keyBody.writeTo(baos);
                key = baos.toString();
            }
            parts.put("myseed", UTF8.StringBody((mySeed == null) ? "" : mySeed.genSeedStr(key)));
            parts.put("count", UTF8.StringBody(Integer.toString(Math.max(10, count))));
            parts.put("time", UTF8.StringBody(Long.toString(Math.max(3000, time))));
View Full Code Here

   * Create image with given txid. Finalize and/or delete md5 file if specified.
   */
  private void createImage(long txid, boolean finalize, boolean removeMd5)
      throws IOException {
    // create image
    ContentBody cb = genContent(txid);
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost postRequest = TestJournalNodeImageUpload.createRequest(
        httpAddress, cb);
    UploadImageParam.setHeaders(postRequest, journalId,
        FAKE_NSINFO.toColonSeparatedString(), 0, txid, 0, 0, true);
View Full Code Here

    journal.transitionImage(FAKE_NSINFO, Transition.FORMAT, null);
  }

  @Test
  public void testMismatchEpoch() throws Exception {
    ContentBody cb = genContent();
    startUpload(cb, 100);
    // session - 0
    // next expected segment - 1
    // epoch - 0
View Full Code Here

    tryUploading(cb, journalId, 1, 0, 5, true, false);
  }

  @Test
  public void testMismatch() throws Exception {
    ContentBody cb = genContent();
    startUpload(cb, 100);
    // session - 0
    // next expected segment - 1
    // epoch - 0
View Full Code Here

  }

  @Test
  public void testBasic() throws Exception {
    long txid = 101;
    ContentBody cb = genContent();
    int iterations = 30;
    long sessionId = 0;
    for (int i = 0; i < iterations; i++) {
      HttpClient httpClient = new DefaultHttpClient();
      HttpPost postRequest = createRequest(httpAddress, cb);
View Full Code Here

  /**
   * Create a post request encapsulating bytes from the given
   * ByteArrayOutputStream.
   */
  private HttpPost setupRequest(ByteArrayOutputStream bos) {
    ContentBody cb = new ByteArrayBody(bos.toByteArray(), "image");
    HttpPost postRequest = new HttpPost(uri + "/uploadImage");
    MultipartEntity reqEntity = new MultipartEntity(
        HttpMultipartMode.BROWSER_COMPATIBLE);

    // add a single part to the request
View Full Code Here

TOP

Related Classes of org.apache.http.entity.mime.content.ContentBody

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.