Examples of MultipartRequestEntity


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

            }

            // Set the multipart for the post
            int partNo = partlist.size();
            Part[] parts = 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

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

        }
            File f = new File(fileInfo.getLocation());
            if (f.isFile()) {
                parts.add(new FilePart(fileInfo.getName(), f));
            }
            post.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post
                    .getParams()));
        httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(),repositoryInfo.getPassword()));
        httpClient.getParams().setAuthenticationPreemptive(true);
        int responseStatus=httpClient.executeMethod(post);
       
View Full Code Here

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

    @Override
    public Result<Void> execute() {
        PostMethod post = new PostMethod(getPath());
      try{
        Part[] parts ={new StringPart(":operation", "delete")};
        post.setRequestEntity(new MultipartRequestEntity(parts,post.getParams()));
        httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(),repositoryInfo.getPassword()));
        httpClient.getParams().setAuthenticationPreemptive(true);
        int responseStatus=httpClient.executeMethod(post);
       
        return resultForResponseStatus(responseStatus);
View Full Code Here

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

            partList.add(new FilePart("bundlefile", partSource));
            partList.add(new StringPart("bundlestart", "start"));

            Part[] parts = partList.toArray(new Part[partList.size()]);

            filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

            int status = getHttpClient().executeMethod(filePost);
            if (status != 200) {
                throw new OsgiClientException("Method execution returned status " + status);
            }
View Full Code Here

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

            @Override
            void configureRequest(PostMethod method) throws IOException {

                Part[] parts = new Part[] { new FilePart("bundle", new ByteArrayPartSource("bundle.jar",
                        IOUtils.toByteArray(jarredBundle))) };
                method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
            }
        }.installBundle();       
    }
View Full Code Here

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

                partList.add(new StringPart("refreshPackages", "true"));
            }

            Part[] parts = partList.toArray(new Part[partList.size()]);

            filePost.setRequestEntity(new MultipartRequestEntity(parts,
                filePost.getParams()));

            int status = getHttpClient().executeMethod(filePost);
            if (status == HttpStatus.SC_OK) {
                getLog().info("Bundle installed");
View Full Code Here

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

        PostMethod filePost = new PostMethod(targetURL);
        try {
            Part[] parts = {
                new FilePart(file.getName(), new FilePartSource(file.getName(),
                    file)), new StringPart("_noredir_", "_noredir_") };
            filePost.setRequestEntity(new MultipartRequestEntity(parts,
                filePost.getParams()));
            HttpClient client = new HttpClient();
            client.getHttpConnectionManager().getParams().setConnectionTimeout(
                5000);
            int status = client.executeMethod(filePost);
View Full Code Here

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

                    if (typeHint != null) {
                      partList.add(new StringPart(fieldName + "@TypeHint", typeHint));
                    }
                }
                final Part [] parts = partList.toArray(new Part[partList.size()]);
                post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
            } else {
              post.getParams().setContentCharset("UTF-8");
                for(NameValuePair e : nodeProperties) {
                    post.addParameter(e.getName(),e.getValue());
                }
View Full Code Here

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

        if (typeHint != null) {
            parts[1] = new StringPart(fieldName + "@TypeHint", typeHint);
        }
        final PostMethod post = new PostMethod(url);
        post.setFollowRedirects(false);
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

        final int status = httpClient.executeMethod(post);
        final int expected = 200;
        if(status!=expected) {
            throw new HttpStatusCodeException(expected, status, "POST", HttpTestBase.getResponseBodyAsStream(post, 0));
View Full Code Here

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

    }

        final Part[] parts = partsList.toArray(new Part[partsList.size()]);
        final PostMethod post = new PostMethod(url);
        post.setFollowRedirects(false);
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

        final int expected = 200;
        final int status = httpClient.executeMethod(post);
        if(status!=expected) {
            throw new HttpStatusCodeException(expected, status, "POST", HttpTestBase.getResponseBodyAsStream(post, 0));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.