Package org.apache.commons.httpclient.methods.multipart

Examples of org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity


         
          //
          // Add test binary file to POST
          //
          Part[] parts = { new FilePart(file.getName(), file) };
          post.setRequestEntity(new MultipartRequestEntity(parts, post
              .getParams()));

          client.executeMethod(post);  
          int code = post.getStatusCode();
          // should be 400 - bad wgt package
View Full Code Here


         
          //
          // Add test binary file to POST
          //
          Part[] parts = { new FilePart(file.getName(), file) };
          post.setRequestEntity(new MultipartRequestEntity(parts, post
              .getParams()));

          client.executeMethod(post);  
          int code = post.getStatusCode();
          // should be 400 - bad wgt package
View Full Code Here

         
          //
          // Add test binary file to POST
          //
          Part[] parts = { new FilePart(file.getName(), file) };
          post.setRequestEntity(new MultipartRequestEntity(parts, post
              .getParams()));

          client.executeMethod(post);  
          int code = post.getStatusCode();
          // should be 400 - bad wgt package
View Full Code Here

         
          //
          // Add test binary file to POST
          //
          Part[] parts = { new FilePart(file.getName(), file) };
          post.setRequestEntity(new MultipartRequestEntity(parts, post
              .getParams()));

          client.executeMethod(post);  
          int code = post.getStatusCode();
          // should be 200
View Full Code Here

    public void testPostStringPart() throws Exception {
       
        this.server.setHttpService(new EchoService());
       
        PostMethod method = new PostMethod();
        MultipartRequestEntity entity = new MultipartRequestEntity(
            new Part[] { new StringPart("param", "Hello", "ISO-8859-1") },
            method.getParams());
        method.setRequestEntity(entity);
        client.executeMethod(method);
View Full Code Here

       
        this.server.setHttpService(new EchoService());

        PostMethod method = new PostMethod();
        byte[] content = "Hello".getBytes();
        MultipartRequestEntity entity = new MultipartRequestEntity(
            new Part[] {
                new FilePart(
                    "param1",
                    new ByteArrayPartSource("filename.txt", content),
                    "text/plain",
View Full Code Here

        this.server.setHttpService(new EchoService());

        String enc = "ISO-8859-1";
        PostMethod method = new PostMethod();
        byte[] content = "Hello".getBytes(enc);
        MultipartRequestEntity entity = new MultipartRequestEntity(
            new Part[] {
                new FilePart(
                    "param1",
                    new TestPartSource("filename.txt", content),
                     "text/plain",
View Full Code Here

            } else {
                // other parts are present -> add the diff part
                addPart(PARAM_DIFF, buf.toString());
                // ... and create multipart-entity (and set it to method)
                Part[] partArr = parts.toArray(new Part[parts.size()]);
                RequestEntity entity = new MultipartRequestEntity(partArr, method.getParams());
                method.setRequestEntity(entity);
            }

            HttpClient client = getClient(sessionInfo);
            try {
View Full Code Here

            }

            // Set the multipart for the post
            int partNo = partlist.size();
            Part[] parts = (Part[])partlist.toArray(new Part[partNo]);
            MultipartRequestEntity multiPart = new MultipartRequestEntity(parts, post.getParams());
            post.setRequestEntity(multiPart);

            // Set the content type
            String multiPartContentType = multiPart.getContentType();
            post.setRequestHeader(HEADER_CONTENT_TYPE, multiPartContentType);

            // If the Multipart is repeatable, we can send it first to
            // our own stream, without the actual file content, so we can return it
            if(multiPart.isRepeatable()) {
                // For all the file multiparts, we must tell it to not include
                // the actual file content
                for(int i = 0; i < partNo; i++) {
                    if(parts[i] instanceof ViewableFilePart) {
                        ((ViewableFilePart) parts[i]).setHideFileData(true); // .sendMultipartWithoutFileContent(bos);
                    }
                }
                // Write the request to our own stream
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                multiPart.writeRequest(bos);
                bos.flush();
                // We get the posted bytes using the encoding used to create it
                postedBody.append(new String(bos.toByteArray(),
                        contentEncoding == null ? "US-ASCII" // $NON-NLS-1$ this is the default used by HttpClient
                        : contentEncoding));
View Full Code Here

        post.setRequestHeader("Content-Type", ct);
        Part[] parts = new Part[1];
        parts[0] = new FilePart("image",
                new ByteArrayPartSource("testfile.png", new byte[1024 * 11]),
                "image/png", null);
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

        HttpClient httpclient = new HttpClient();

        try {
            int result = httpclient.executeMethod(post);
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity

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.