Package org.xsocket.connection

Examples of org.xsocket.connection.IServer


  @Test
  public void testBadRequest() throws Exception {

   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET /s/ ere6r" + "\r\n\r\n");

   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("400") != -1);
    Assert.assertTrue(body.indexOf("bad message") != -1);

    con.close();
    server.close();
  }
View Full Code Here


 
  @Test
  public void testHttp09Request() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET /\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("400") != -1);
    Assert.assertTrue(body.indexOf("simple request messages are not supported") != -1);

    con.close();
    server.close();
  }
View Full Code Here


  @Test
  public void testHttp09Request_2() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET /\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("400") != -1);
    Assert.assertTrue(body.indexOf("simple request messages are not supported") != -1);

    con.close();
    server.close();
  }
View Full Code Here

 
 
  @Test
  public void testHttp11RequestWithServeralSpaces() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET    /    HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

    con.close();
    server.close();
  }
View Full Code Here

 
 
  @Test
  public void testHttp11RequestWithServeralSpacesAndTabs() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET    /  \t  HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

    con.close();
    server.close();
  }
View Full Code Here

 
  @Test
  public void testHttp11RequestWithHeaderValueSpaces() throws Exception {
   
    RequestHandler srvHdl = new RequestHandler();
    IServer server = new HttpServer(srvHdl);
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET / HTTP/1.1\r\n" +
          "Content-Length: 5    \r\n" +
          "X-MyHeader: this is a text   \r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n" +
          "12345");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

   
    Assert.assertEquals("this is a text", srvHdl.getRequest().getHeader("X-MyHeader"));
   
    con.close();
    server.close();
  }
View Full Code Here

  }
 
  @Test
  public void testHttp11RequestWithLeadingCRLF() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("\r\n" +
          "GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

    con.close();
    server.close();
  }
View Full Code Here

 
 
  @Test
  public void testHttp11RequestWithServeralLeadingCRLF() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("\r\n" +
          "\r\n" +
          "GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

    con.close();
    server.close();
  }
View Full Code Here

 
 
  @Test
  public void testHttp11RequestWithServeralLeadingCRLFAndSpaces() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("\r\n" +
          "  \r\n" +
          "GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("400") != -1);
    Assert.assertTrue(body.indexOf("bad request") != -1);

    con.close();
    server.close();
  }
View Full Code Here

 
 
  @Test
  public void testLargeCookie() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Cookie: pA_c[p]=rZNBCsIwEEXvkhNkZpIa05VgFx5ANyJStWpRbKGgC9u7m1qo;\r\n" +
          " pA_c[p340358058568d1f]=S7QysqoutjIytF;\r\n" +
          " pA_c[p3403580662066ea]=S7QysqoutjIytFIqyChwTC;\r\n" +
          "\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

    con.close();
    server.close();
  }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.IServer

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.