Package org.xlightweb

Examples of org.xlightweb.IHttpRequest


        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setAutoUncompress(false);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        request.setHeader("Accept-Encoding", "gzip");
       
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("gzip", response.getHeader("Content-Encoding"));
View Full Code Here


        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setAutoUncompress(false);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        request.setHeader("Accept-Encoding", "gzip");
       
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals("gzip", response.getHeader("Content-Encoding"));
        Assert.assertEquals(200, response.getStatus());
View Full Code Here

        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setAutoUncompress(false);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        request.setHeader("Accept-Encoding", "gzip");
       
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertNull(response.getHeader("Content-Encoding"));
View Full Code Here

        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setAutoUncompress(false);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        request.setHeader("Accept-Encoding", "gzip");
       
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("gzip", response.getHeader("Content-Encoding"));
View Full Code Here

        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setAutoUncompress(false);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        request.setHeader("Accept-Encoding", "gzip");
       
        IHttpResponse response = httpClient.call(request);
       
       
        Assert.assertEquals(200, response.getStatus());
View Full Code Here

        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setAutoUncompress(false);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        request.setHeader("Accept-Encoding", "gzip");
       
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals("gzip", response.getHeader("Content-Encoding"));
        Assert.assertEquals(200, response.getStatus());
View Full Code Here

        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setAutoUncompress(false);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
       
        IHttpResponse response = httpClient.call(request);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("1234567890", response.getBody().readString());
       
View Full Code Here

        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setAutoUncompress(false);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
       
        IHttpResponse response = httpClient.call(request);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("1234567890", response.getBody().readString());
       
View Full Code Here

    private StringBuilder requestString = new StringBuilder();
   
   
    public void onRequest(final IHttpExchange exchange) throws IOException {
     
      IHttpRequest req = exchange.getRequest();

      requestString.append(req.getRequestHeader().toString());
     
     
      IHttpResponseHandler respHdl = new IHttpResponseHandler() {
       
        public void onResponse(IHttpResponse response) throws IOException {

          // does request contain a body?
          if (response.hasBody()) {
           
            // 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

  public static final class TimestampHandler implements IHttpRequestHandler {
   
   
    public void onRequest(final IHttpExchange exchange) throws IOException {
     
      IHttpRequest req = exchange.getRequest();
      req.addHeader("X-Received", new Date().toString());
     
     
      IHttpResponseHandler responseInterceptor = new IHttpResponseHandler() {

        public void onResponse(IHttpResponse response) throws IOException {
View Full Code Here

TOP

Related Classes of org.xlightweb.IHttpRequest

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.