Package org.xlightweb

Examples of org.xlightweb.BodyDataSink


        HttpClient httpclient = new HttpClient();
       
        File file = QAUtil.createTestfile_40k();
       
        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink dataSink = httpclient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHdl);
          
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        AsyncWriter writer = new AsyncWriter(dataSink, raf);
        writer.onWritten(0);
       
View Full Code Here


 
  private static final class RequestHandler2 implements IHttpRequestHandler {
   
    public void onRequest(IHttpExchange exchange) throws IOException {
     
      BodyDataSink bodyDataSink = exchange.send(new HttpResponseHeader(200, "text/plain"));
      bodyDataSink.write("it works");
      bodyDataSink.close();
    }
View Full Code Here

       
        if (request.getRequestURI().endsWith("/RegisterClient")) {
          BodyDataSource inChannel = request.getBody();
          inChannel.setReceiveTimeoutSec(1);
         
          BodyDataSink outChannel = exchange.send(new HttpResponseHeader(200, "text/plain"));
          outChannel.setFlushmode(FlushMode.ASYNC);
          outChannel.flush();
         
          register(new Link(outChannel, inChannel));
        } else {
          exchange.sendError(404);
        }
View Full Code Here

      HttpServer server = new HttpServer(reqHdl);
      server.start();
     
      HttpClient httpClient = new HttpClient();
      FutureResponseHandler respHdl = new FutureResponseHandler();
      BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/?isWaitForBody=true", "text/plain;charset=UTF-8"), respHdl);
      ds.flush();
     
      QAUtil.sleep(1000);
      ds.write("1234567");
      ds.close();
     
      IHttpResponse response = respHdl.getResponse();
     
      Assert.assertEquals(200, response.getStatus());
     
View Full Code Here

        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/", "text/plain;charset=UTF-8"), respHdl);
        ds.flush();
       
        QAUtil.sleep(1000);
        ds.write("1234567");
        ds.close();
       
        IHttpResponse response = respHdl.getResponse();
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(((HttpServerConnection) reqHdl.getLastCon()).isDelayedClosed());
View Full Code Here

        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/", "text/plain;charset=UTF-8"), respHdl);
        ds.flush();
       
        QAUtil.sleep(1000);

        ds.close();
       
        IHttpResponse response = respHdl.getResponse();
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(((HttpServerConnection) reqHdl.getLastCon()).isDelayedClosed());
View Full Code Here

  private BodyDataSink sendInternal(IHttpRequestHeader requestHeader, int contentLength, IHttpResponseHandler responseHandler) throws IOException, ConnectException {
    synchronized (handlersWaitingForResponseHeader) {
      handlersWaitingForResponseHeader.add(new MessageHeaderHandler(new ResponseHandlerAdapter(responseHandler), requestHeader, responseTimeoutMillis));
    }
   
    BodyDataSink bodyDataSink = writeMessage(requestHeader, contentLength);

    return bodyDataSink;
  }
View Full Code Here

      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("[" + getId() + "] sending (bodyless): " + request.getRequestHeader());
      }

      BodyDataSink bodyDataSink = writeMessage(request.getRequestHeader(), 0);
      bodyDataSink.setFlushmode(FlushMode.ASYNC);
      bodyDataSink.close();
     
     
     
    // no, request has body
    } else {
View Full Code Here

           
            // get the body
            NonBlockingBodyDataSource orgDataSource = response.getNonBlockingBody();
           
            // ... and replace it 
            final BodyDataSink inBodyChannel = exchange.send(response.getResponseHeader());
           
            //... by a body forward handler
            BodyForwarder bodyForwardHandler = new BodyForwarder(orgDataSource, inBodyChannel) {
             
              @Override
              public void onData(NonBlockingBodyDataSource bodyDataSource, BodyDataSink bodyDataSink) throws BufferUnderflowException, IOException {
                ByteBuffer[] bufs = bodyDataSource.readByteBufferByLength(bodyDataSource.available());
                   
                for (ByteBuffer byteBuffer : bufs) {
                  // WARNING DataConverter call could fail!
                  requestString.append(DataConverter.toString(byteBuffer.duplicate()));
                }
                   
                bodyDataSink.write(bufs);
                bodyDataSink.flush();
              }
            };
            orgDataSource.setDataHandler(bodyForwardHandler);
           
          } else {
            exchange.send(response);
          }
        }
       
        public void onException(IOException ioe) {
         
        }
      };
     
     
      // does request contain a body?
      if (req.hasBody()) {
       
        // get the body
        NonBlockingBodyDataSource orgDataSource = req.getNonBlockingBody();
       
        // ... and replace it 
        final BodyDataSink inBodyChannel = exchange.forward(req.getRequestHeader(), respHdl);
       
        //... by a body forward handler
        BodyForwarder bodyForwardHandler = new BodyForwarder(orgDataSource, inBodyChannel) {
         
          @Override
View Full Code Here

            // get the body
            NonBlockingBodyDataSource orgDataSource = response.getNonBlockingBody();

            // ... and replace it 
            final BodyDataSink inBodyChannel = exchange.send(response.getResponseHeader());
           
            //... by a body forward handler
            BodyForwarder bodyForwardHandler = new BodyForwarder(orgDataSource, inBodyChannel) {
             
              @Override
              public void onData(NonBlockingBodyDataSource bodyDataSource, BodyDataSink bodyDataSink) throws BufferUnderflowException, IOException {
                byte[] data = bodyDataSource.readBytesByLength(bodyDataSource.available());
                   
                for (int i = 0; i < data.length; i++) {
                  data[i] = (byte) ((int) data[i] - shift);
                }
                                       
                inBodyChannel.write(data);
                inBodyChannel.flush();
              }
            };
            orgDataSource.setDataHandler(bodyForwardHandler);
           
          } else {
            exchange.send(response);
          }
        };
       
        public void onException(IOException ioe) {
         
        };
      };
     
      // does request contain a body?
      if (exchange.getRequest().hasBody()) {
       
        // get the body
        NonBlockingBodyDataSource orgDataSource = exchange.getRequest().getNonBlockingBody();
       
        // ... and replace it ...
        final BodyDataSink inBodyChannel = exchange.forward(exchange.getRequest().getRequestHeader(), responseInterceptor);
       
        //... by a body forward handler
        BodyForwarder bodyForwardHandler = new BodyForwarder(orgDataSource, inBodyChannel) {
         
          @Override
          public void onData(NonBlockingBodyDataSource bodyDataSource, BodyDataSink bodyDataSink) throws BufferUnderflowException, IOException {
            byte[] data = bodyDataSource.readBytesByLength(bodyDataSource.available());
               
            for (int i = 0; i < data.length; i++) {
              data[i] = (byte) ((int) data[i] + shift);
            }
               
               
            inBodyChannel.write(data);
            inBodyChannel.flush();
          }
        };
        orgDataSource.setDataHandler(bodyForwardHandler);
       
      } else {
View Full Code Here

TOP

Related Classes of org.xlightweb.BodyDataSink

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.