Package org.xlightweb

Examples of org.xlightweb.HttpResponse


                             "  <input type=\"text\" name=\"input_text\" value=\"mytext\"><br>\r\n" +
                             "  <input type=\"file\" name=\"file\"><br>\r\n" +
                             "  <input type=\"submit\">\r\n" +
                             "</form>";
       
        exchange.send(new HttpResponse(200, "text/html", txt));
       
      } else {
        System.out.println("STOP");
      }
    }
View Full Code Here


 
 
  private static final class HttpRequestHandler implements IHttpRequestHandler {
         
        public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
            exchange.send(new HttpResponse(200, "text/plain", "OK"));
        }
View Full Code Here

   
    public void onRequest(IHttpExchange exchange) throws IOException {
      countOnRequestCalled++;
      onRequestThreadname = Thread.currentThread().getName();
     
      exchange.send(new HttpResponse(200, "text/plain", "OK"));
    }
View Full Code Here

   
    public void onRequest(IHttpExchange exchange) throws IOException {
      countOnRequestCalled++;
      onRequestThreadname.set(Thread.currentThread().getName());
     
      exchange.send(new HttpResponse(200, "text/plain", "OK"));
    }
View Full Code Here

   
    public void onRequest(IHttpExchange exchange) throws IOException {
      countOnRequestCalled++;
      onRequestThreadname = Thread.currentThread().getName();
     
      exchange.send(new HttpResponse(200, "text/plain", "OK"));
    }
View Full Code Here

  private static final class BlockingReadHandler implements IHttpRequestHandler {
   
    public void onRequest(IHttpExchange exchange) throws IOException {

      String body = exchange.getRequest().getBody().readString();
      exchange.send(new HttpResponse(200, "text/plain", body));
     
    }
View Full Code Here

  public void testGetWithExpireHeader() throws Exception {
     
        IHttpRequestHandler reqHdl = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                HttpResponse resp = new HttpResponse(200, "text/plain", "test");
                resp.setHeader("Expires", "Fri, 30 Oct 2011 14:19:41 GMT");
                exchange.send(resp);
            }
        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
        ConnectionUtils.registerMBean(httpClient);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
        Assert.assertEquals("test", resp.getBody().readString());
       
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
       
View Full Code Here

    public void testGetWithExpireHeaderAndPOST() throws Exception {
       
        IHttpRequestHandler reqHdl = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                HttpResponse resp = new HttpResponse(200, "text/plain", "test");
                resp.setHeader("Expires", "Fri, 30 Oct 2011 14:19:41 GMT");
                exchange.send(resp);
            }
        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
        Assert.assertEquals("test", resp.getBody().readString());
       
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new PostRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
        Assert.assertEquals("test", resp.getBody().readString());

       
        QAUtil.sleep(1000);

       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
        Assert.assertEquals("test", resp.getBody().readString());
       

       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(2, httpClient.getNumCacheMiss());
View Full Code Here

    public void testGetWithExpireAndCacheControlHeader() throws Exception {
       
        IHttpRequestHandler reqHdl = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                HttpResponse resp = new HttpResponse(200, "text/plain", "test");
                resp.setHeader("Expires", "Fri, 30 Oct 2011 14:19:41 GMT");
                resp.setHeader("Cache-Control", "public, max-age=21600");
                exchange.send(resp);
            }
        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
        Assert.assertEquals("test", resp.getBody().readString());
       
        QAUtil.sleep(1000);
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
View Full Code Here

    public void testNegativeExpired() throws Exception {
       
        IHttpRequestHandler reqHdl = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                HttpResponse resp = new HttpResponse(200, "text/plain", "test");
                resp.setHeader("Expires", "-1");
                exchange.send(resp);
            }
        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(2000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
        Assert.assertEquals("test", resp.getBody().readString());
       
        QAUtil.sleep(1000);
       
        Assert.assertEquals(0, httpClient.getNumCacheHit());
        Assert.assertEquals(2, httpClient.getNumCacheMiss());
View Full Code Here

TOP

Related Classes of org.xlightweb.HttpResponse

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.