Package org.apache.http.entity

Examples of org.apache.http.entity.ContentProducer


*/
public class HttpClientUtils
{
    public static void setStringEntity(final String content, HttpPost post)
    {
        ContentProducer cp = new ContentProducer() {
            public void writeTo(OutputStream outstream) throws IOException
            {
                Writer writer = new OutputStreamWriter(outstream, "UTF-8");
                writer.write(content);
                writer.flush();
View Full Code Here


    /** Create an HttpEntity for the graph */ 
    protected HttpEntity graphToHttpEntity(final Graph graph) {

        final RDFFormat syntax = getOutboundSyntax() ;
        ContentProducer producer = new ContentProducer() {
            @Override
            public void writeTo(OutputStream out) throws IOException {
                RDFDataMgr.write(out, graph, syntax) ;
            }
        } ;
View Full Code Here

        return httpParams$;
    }
   
    private static HttpEntity graphToHttpEntity(final Graph graph) {
       
        ContentProducer producer = new ContentProducer() {
            @Override
            public void writeTo(OutputStream out) throws IOException {
                RDFDataMgr.write(out, graph, sendLang) ;
            }
        } ;
View Full Code Here

        body.setContentType(contentType);
        response.setEntity(body);
    }

    private EntityTemplate createEntity() {
        return new EntityTemplate(new ContentProducer() {
            public void writeTo(OutputStream outputStream) throws IOException {
                OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
                writer.write(payload);
                writer.flush();
            }
View Full Code Here

  @Override
  public OutputStream getOutputStream() {
    if (out == null) {
      final ByteArrayOutputStream o = new ByteArrayOutputStream();
      ContentProducer producer = new ContentProducer() {
        public void writeTo(OutputStream out) throws IOException {
          out.write(o.toByteArray());
        }
      };
      HttpEntity entity = new EntityTemplate(producer);
View Full Code Here

                    req = new JsonRpc10Request(requestId, msg.getOperation().getName(), params);
                }
                final JsonRpcRequest json = req;

                // Create content producer so that we can stream the json result out
                ContentProducer cp = new ContentProducer() {
                    public void writeTo(OutputStream outstream) throws IOException {
                        // mapper.writeValue(outstream, req.toJSONObject().toString());
                        try {
                            json.write(outstream);
                        } catch (Exception e) {
View Full Code Here

            final File file = new File(this.docRoot, URLDecoder.decode(
                    target, "UTF-8"));
            if (!file.exists()) {
                response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                EntityTemplate body = new EntityTemplate(
                        new ContentProducer() {

                            public void writeTo(final OutputStream outstream)
                                    throws IOException {
                                OutputStreamWriter writer = new OutputStreamWriter(
                                        outstream, "UTF-8");
                                writer.write("<html><body><h1>");
                                writer.write("File ");
                                writer.write(file.getPath());
                                writer.write(" not found");
                                writer.write("</h1></body></html>");
                                writer.flush();
                            }
                        });
                body.setContentType("text/html; charset=UTF-8");
                response.setEntity(body);
                log.error("找不到文件" + file.getPath(), true);
            } else if (!file.canRead() || file.isDirectory()) {
                response.setStatusCode(HttpStatus.SC_FORBIDDEN);
                EntityTemplate body = new EntityTemplate(
                        new ContentProducer() {

                            public void writeTo(final OutputStream outstream)
                                    throws IOException {
                                OutputStreamWriter writer = new OutputStreamWriter(
                                        outstream, "UTF-8");
View Full Code Here

           
            final File file = new File(this.docRoot, URLDecoder.decode(target));
            if (!file.exists()) {

                response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                EntityTemplate body = new EntityTemplate(new ContentProducer() {
                   
                    public void writeTo(final OutputStream outstream) throws IOException {
                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
                        writer.write("<html><body><h1>");
                        writer.write("File ");
                        writer.write(file.getPath());
                        writer.write(" not found");
                        writer.write("</h1></body></html>");
                        writer.flush();
                    }
                   
                });
                body.setContentType("text/html; charset=UTF-8");
                response.setEntity(body);
                System.out.println("File " + file.getPath() + " not found");
               
            } else if (!file.canRead() || file.isDirectory()) {
               
                response.setStatusCode(HttpStatus.SC_FORBIDDEN);
                EntityTemplate body = new EntityTemplate(new ContentProducer() {
                   
                    public void writeTo(final OutputStream outstream) throws IOException {
                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
                        writer.write("<html><body><h1>");
                        writer.write("Access denied");
View Full Code Here

            String target = request.getRequestLine().getUri();
            final File file = new File(this.docRoot, URLDecoder.decode(target, "UTF-8"));
            if (!file.exists()) {

                response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                EntityTemplate body = new EntityTemplate(new ContentProducer() {
                   
                    public void writeTo(final OutputStream outstream) throws IOException {
                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
                        writer.write("<html><body><h1>");
                        writer.write("File ");
                        writer.write(file.getPath());
                        writer.write(" not found");
                        writer.write("</h1></body></html>");
                        writer.flush();
                    }
                   
                });
                body.setContentType("text/html; charset=UTF-8");
                response.setEntity(body);
                System.out.println("File " + file.getPath() + " not found");
               
            } else if (!file.canRead() || file.isDirectory()) {
               
                response.setStatusCode(HttpStatus.SC_FORBIDDEN);
                EntityTemplate body = new EntityTemplate(new ContentProducer() {
                   
                    public void writeTo(final OutputStream outstream) throws IOException {
                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
                        writer.write("<html><body><h1>");
                        writer.write("Access denied");
View Full Code Here

            String target = request.getRequestLine().getUri();
            final File file = new File(this.docRoot, URLDecoder.decode(target, "UTF-8"));
            if (!file.exists()) {

                response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                EntityTemplate body = new EntityTemplate(new ContentProducer() {
                   
                    public void writeTo(final OutputStream outstream) throws IOException {
                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
                        writer.write("<html><body><h1>");
                        writer.write("File ");
                        writer.write(file.getPath());
                        writer.write(" not found");
                        writer.write("</h1></body></html>");
                        writer.flush();
                    }
                   
                });
                body.setContentType("text/html; charset=UTF-8");
                response.setEntity(body);
                System.out.println("File " + file.getPath() + " not found");
               
            } else if (!file.canRead() || file.isDirectory()) {
               
                response.setStatusCode(HttpStatus.SC_FORBIDDEN);
                EntityTemplate body = new EntityTemplate(new ContentProducer() {
                   
                    public void writeTo(final OutputStream outstream) throws IOException {
                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
                        writer.write("<html><body><h1>");
                        writer.write("Access denied");
View Full Code Here

TOP

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

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.