Package org.apache.http.entity

Examples of org.apache.http.entity.FileEntity


        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        DefaultConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();

        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, httpHost);
        FileEntity fileEntity = null;
        if (!file.equals("--end--")) {
            log.info("开始传输文件:" + file, true);
            fileEntity = new FileEntity(new File(folder + file), "UTF-8");
            try {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(httpHost.getHostName(), httpHost.getPort());
                    conn.bind(socket, params);
                }
                BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", file);
                request.setEntity(fileEntity);
                context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
                request.setParams(params);
                httpexecutor.preProcess(request, httpproc, context);
                HttpResponse response = httpexecutor.execute(request, conn, context);
                if (!connStrategy.keepAlive(response, context)) {
                    conn.close();
                }
            } catch (Exception e) {
                log.error(e.getMessage(), true);
            } finally {
                try {
                    conn.close();
                } catch (Exception e) {
                    log.error(e.getMessage(), true);
                }
                log.info("传输文件:" + file + "完毕。", true);
            }
        } else {
            File f = new File("end");
            try {
                f.createNewFile();
                fileEntity = new FileEntity(f, "UTF-8");
            } catch (IOException ex) {
            }
            try {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(httpHost.getHostName(), httpHost.getPort());
View Full Code Here


                System.out.println("Cannot read file " + file.getPath());
               
            } else {
               
                response.setStatusCode(HttpStatus.SC_OK);
                FileEntity body = new FileEntity(file, "text/html");
                response.setEntity(body);
                System.out.println("Serving file " + file.getPath());
               
            }
        }
View Full Code Here

                System.out.println("Cannot read file " + file.getPath());
               
            } else {
               
                response.setStatusCode(HttpStatus.SC_OK);
                FileEntity body = new FileEntity(file, "text/html");
                response.setEntity(body);
                System.out.println("Serving file " + file.getPath());
               
            }
        }
View Full Code Here

                System.out.println("Cannot read file " + file.getPath());
               
            } else {
               
                response.setStatusCode(HttpStatus.SC_OK);
                FileEntity body = new FileEntity(file, "text/html");
                response.setEntity(body);
                System.out.println("Serving file " + file.getPath());
               
            }
        }
View Full Code Here

            throw new UnsupportedOperationException("Encoding not supported", e);
         }
         nStringEntity.setContentType(payload.getContentMetadata().getContentType());
         apacheRequest.setEntity(nStringEntity);
      } else if (payload instanceof FilePayload) {
         apacheRequest.setEntity(new FileEntity((File) payload.getRawContent(), payload.getContentMetadata()
               .getContentType()));
      } else if (payload instanceof ByteArrayPayload) {
         ByteArrayEntity Entity = new ByteArrayEntity((byte[]) payload.getRawContent());
         Entity.setContentType(payload.getContentMetadata().getContentType());
         apacheRequest.setEntity(Entity);
View Full Code Here

                    else {
                        post.setHeader(HEADER_CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED);
                    }
                }

                FileEntity fileRequestEntity = new FileEntity(new File(file.getPath()),(String) null);// TODO is null correct?
                post.setEntity(fileRequestEntity);

                // We just add placeholder text for file content
                postedBody.append("<actual file content, not shown here>");
            } else {
View Full Code Here

        if(!hasArguments() && getSendFileAsPostBody()) {
            hasPutBody = true;

            // If getSendFileAsPostBody returned true, it's sure that file is not null
            FileEntity fileRequestEntity = new FileEntity(new File(files[0].getPath()), (String) null); // TODO is null correct?
            put.setEntity(fileRequestEntity);

            // We just add placeholder text for file content
            putBody.append("<actual file content, not shown here>");
        }
View Full Code Here

        // Prepare requests for each thread
        request = new HttpRequest[threads];

        if (postFile != null) {
            FileEntity entity = new FileEntity(postFile, contentType);
            contentLength = entity.getContentLength();
            if (postFile.length() > 100000) {
                entity.setChunked(true);
            }

            for (int i = 0; i < threads; i++) {
                BasicHttpEntityEnclosingRequest httppost =
                    new BasicHttpEntityEnclosingRequest("POST", url.getPath());
View Full Code Here

                System.out.println("Cannot read file " + file.getPath());
               
            } else {
               
                response.setStatusCode(HttpStatus.SC_OK);
                FileEntity body = new FileEntity(file, "text/html");
                response.setEntity(body);
                System.out.println("Serving file " + file.getPath());
               
            }
        }
View Full Code Here

    public Request bodyString(final String s, final ContentType contentType) {
        return body(new StringEntity(s, contentType));
    }

    public Request bodyFile(final File file, final ContentType contentType) {
        return body(new FileEntity(file, contentType));
    }
View Full Code Here

TOP

Related Classes of org.apache.http.entity.FileEntity

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.