Examples of HttpServer


Examples of org.xlightweb.server.HttpServer

    @Test
    public void testApacheClient() throws Exception {
       
     
        ContinueHandler hdl = new ContinueHandler();
        HttpServer server = new HttpServer(hdl);
        server.start();


        HttpClient httpClient = new HttpClient();
        httpClient.getParams().setParameter("http.protocol.expect-continue", true);

        PostMethod meth = new PostMethod("http://localhost:" + server.getLocalPort() + "/test");
        meth.setRequestBody("OK");

        httpClient.executeMethod(meth);
       
        Assert.assertEquals(200, meth.getStatusCode());
        Assert.assertEquals("OK", meth.getResponseBodyAsString());
       
        meth.releaseConnection();
       
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

   
    @Test
    public void testManualContinueWithMissingAnnotation() throws Exception {

        MissingAnnotationContinueHandler hdl = new MissingAnnotationContinueHandler();
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
        Assert.assertFalse(hdl.is100ContinueSent());
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

       
        RequestHandlerChain chain = new RequestHandlerChain();
        chain.addLast(interceptor);
        chain.addLast(new ItWorksHandler());
       
        HttpServer server = new HttpServer(chain);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

        RequestHandlerChain outerChain = new RequestHandlerChain();
        outerChain.addLast(interceptor2);
        outerChain.addLast(chain);
       
       
        HttpServer server = new HttpServer(outerChain);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted1") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted2") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

        RequestHandlerChain outerChain = new RequestHandlerChain();
        outerChain.addLast(interceptor2);
        outerChain.addLast(chain);
       
       
        HttpServer server = new HttpServer(outerChain);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted1") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted2") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

        RequestHandlerChain outerChain = new RequestHandlerChain();
        outerChain.addLast(interceptor2);
        outerChain.addLast(chain);
       
       
        HttpServer server = new HttpServer(outerChain);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
        Assert.assertTrue(hdl.is100ContinueSent());
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted1") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted2") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

        RequestHandlerChain chain = new RequestHandlerChain();
        chain.addLast(interceptor);
        ContinueHandler hdl = new ContinueHandler();
        chain.addLast(hdl);
       
        HttpServer server = new HttpServer(chain);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
        Assert.assertFalse(hdl.is100ContinueSent());
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        if (header.indexOf("200") == -1) {
            Assert.fail();
        }

        Assert.assertTrue(header.indexOf("X-Intercepted") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

        RequestHandlerChain chain = new RequestHandlerChain();
        chain.addLast(interceptor);
        ContinueHandler hdl = new ContinueHandler();
        chain.addLast(hdl);
       
        HttpServer server = new HttpServer(chain);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
        Assert.assertTrue(hdl.is100ContinueSent());
        Assert.assertTrue(header.indexOf("X-Intercepted: true") != -1);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/site/*", new FileServiceRequestHandler(basePath, true));
    ctx.addHandler("/rpc/*", new MyBusinessHandler());
   
    Server server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/site/" + testFile.getName()));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("application/octet-stream", response.getContentType());
    Assert.assertTrue(response.hasBody());
   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/rpc/getCustomers"));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getContentType().startsWith("text/plain"));
    Assert.assertTrue(response.hasBody());
   
    httpClient.close();
    server.close();
   
   
    testFile.delete();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/site/*", new FileServiceRequestHandler(basePath, true));
    ctx.addHandler(new AnnotatedHandler());
   
    Server server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/site/" + testFile.getName()));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("application/octet-stream", response.getContentType());
    Assert.assertTrue(response.hasBody());
   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/rpc/getCustomers"));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getContentType().startsWith("text/plain"));
    Assert.assertTrue(response.hasBody());
   
    httpClient.close();
    server.close();
   
   
    testFile.delete();
  }
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.