Examples of NStringEntity


Examples of org.apache.http.nio.entity.NStringEntity

                  try {
                    String vmFileName = target.replace(".jhtml", ".vm").replace("/", "\\").substring(1);
                    final File file = new File(this.docRoot, target.replace(".jhtml", ".vm"));
                    if(!file.exists()) {
                      response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                          NStringEntity entity = new NStringEntity(
                                  "<html><body><h1>File" + file.getPath() +
                                  " not found</h1></body></html>",
                                  ContentType.create("text/html", "UTF-8"));
                          response.setEntity(entity);
                          System.out.println("File " + file.getPath() + " not found");
                    } else {
                      template = Velocity.getTemplate(vmFileName, templateEncode);
                      //
                      templateCache.putIfAbsent(target, template);
                    }
                  } catch (Exception e) {
                    logger.error("Exception: get template", e);
                  }
                }
               
                // 渲染VM
                VelocityContext cxt = new VelocityContext();
                monitor.getData(cxt);
                Writer writer = new StringWriter();
                template.merge(cxt, writer);
                response.setStatusCode(HttpStatus.SC_OK);
                NStringEntity entity = new NStringEntity(writer.toString(), ContentType.create("text/html", "UTF-8"));
                response.setEntity(entity);
              } else {
                response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                  NStringEntity entity = new NStringEntity("Velocity not init succeed",
                          ContentType.create("text/html", "UTF-8"));
                  response.setEntity(entity);
                  System.out.println("Velocity not init succeed");
              }
            } else {
              final File file = new File(this.docRoot, target);
              if (!file.exists()) {
                  response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                  NStringEntity entity = new NStringEntity(
                          "<html><body><h1>File" + file.getPath() +
                          " not found</h1></body></html>",
                          ContentType.create("text/html", "UTF-8"));
                  response.setEntity(entity);
                  System.out.println("File " + file.getPath() + " not found");
 
              } else if (!file.canRead() || file.isDirectory()) {
 
                  response.setStatusCode(HttpStatus.SC_FORBIDDEN);
                  NStringEntity entity = new NStringEntity(
                          "<html><body><h1>Access denied</h1></body></html>",
                          ContentType.create("text/html", "UTF-8"));
                  response.setEntity(entity);
                  System.out.println("Cannot read file " + file.getPath());
 
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

            HttpEntity requestEntity = null;
            if (request instanceof HttpEntityEnclosingRequest) {
                requestEntity = ((HttpEntityEnclosingRequest) request).getEntity();
            }
            if (requestEntity == null) {
                response.setEntity(new NStringEntity("Empty content"));
                return;
            }

            boolean ok = true;

            InputStream instream = requestEntity.getContent();
            try {
                ContentType contentType = ContentType.getOrDefault(requestEntity);
                LineIterator it = IOUtils.lineIterator(instream, contentType.getCharset());
                int count = 0;
                while (it.hasNext()) {
                    String line = it.next();
                    int i = count % TEXT.length;
                    String expected = TEXT[i];
                    if (!line.equals(expected)) {
                        ok = false;
                        break;
                    }
                    count++;
                }
            } finally {
                instream.close();
            }
            if (ok) {
                NFileEntity responseEntity = new NFileEntity(TEST_FILE,
                        ContentType.create("text/plian", null));
                if (this.forceChunking) {
                    responseEntity.setChunked(true);
                }
                response.setEntity(responseEntity);
            } else {
                response.setEntity(new NStringEntity("Invalid content"));
            }
        }
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

        if (charset == null) {
            charset = HTTP.DEFAULT_CONTENT_CHARSET;
        }
        this.requestURI = requestURI;
        try {
            NStringEntity entity = new NStringEntity(content, charset);
            entity.setContentType(mimeType + HTTP.CHARSET_PARAM + charset);
            this.producer = entity;
        } catch (UnsupportedEncodingException ex) {
            throw new IllegalArgumentException("Unsupported charset: " + charset);
        }
    }
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

    public static HttpAsyncRequestProducer createPost(
            final URI requestURI,
            final String content,
            final ContentType contentType) throws UnsupportedEncodingException {
        HttpPost httppost = new HttpPost(requestURI);
        NStringEntity entity = new NStringEntity(content, contentType);
        httppost.setEntity(entity);
        HttpHost target = URIUtils.extractHost(requestURI);
        return new RequestProducerImpl(target, httppost, entity);
    }
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

    public static HttpAsyncRequestProducer createPut(
            final URI requestURI,
            final String content,
            final ContentType contentType) throws UnsupportedEncodingException {
        HttpPut httpput = new HttpPut(requestURI);
        NStringEntity entity = new NStringEntity(content, contentType);
        httpput.setEntity(entity);
        HttpHost target = URIUtils.extractHost(requestURI);
        return new RequestProducerImpl(target, httpput, entity);
    }
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

        HttpHost target = start(registry, null);

        HttpContext context = new BasicHttpContext();

        HttpPost httppost = new HttpPost("/oldlocation/");
        httppost.setEntity(new NStringEntity("stuff"));

        Future<HttpResponse> future = this.httpclient.execute(target, httppost, context, null);
        HttpResponse response = future.get();
        Assert.assertNotNull(response);
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

        HttpHost target = start(registry, null);

        HttpContext context = new BasicHttpContext();

        HttpPost httppost = new HttpPost("/oldlocation/");
        httppost.setEntity(new NStringEntity("stuff"));

        Future<HttpResponse> future = this.httpclient.execute(target, httppost, context, null);
        HttpResponse response = future.get();
        Assert.assertNotNull(response);
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

    public void testEntityEnclosingRequestWithoutExpectContinue() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.setEntity(new NStringEntity("stuff"));
        Mockito.when(this.exchangeHandler.generateRequest()).thenReturn(request);

        this.protocolHandler.requestReady(this.conn);

        Mockito.verify(this.exchangeHandler).generateRequest();
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

    public void testResponseContinue() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        state.setRequestState(MessageState.ACK_EXPECTED);
        state.setTimeout(1000);
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.setEntity(new NStringEntity("stuff"));
        state.setRequest(request);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
        final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
View Full Code Here

Examples of org.apache.http.nio.entity.NStringEntity

    @Test
    public void testResponseContinueOutOfSequence() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        state.setRequestState(MessageState.COMPLETED);
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.setEntity(new NStringEntity("stuff"));
        state.setRequest(request);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
        final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
        Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
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.