Package org.xsocket.connection

Examples of org.xsocket.connection.NonBlockingConnection


        RequestHandler reqHdl = new RequestHandler();       
    HttpServer server = new HttpServer(reqHdl);
    server.start();
   
    INonBlockingConnection con = new NonBlockingConnection("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");

   
   
        while (reqHdl.getLastExchange() == null) {
            QAUtil.sleep(50);
        }
       
        reqHdl.getLastExchange().getRequest().getContentLength();
       
       
        QAUtil.sleep(500);
        try {
            con.readStringByDelimiter("\r\n\r\n");
            Assert.fail("BufferUnderflowException expected");
        } catch (BufferUnderflowException expected) { }

        reqHdl.getLastExchange().getRequest().getNonBlockingBody().available();

        QAUtil.sleep(500);
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);

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


     public void testAutoContinueBodyAccess() throws Exception {
         RequestHandler reqHdl = new RequestHandler();       
         HttpServer server = new HttpServer(reqHdl);
         server.start();
        
         INonBlockingConnection con = new NonBlockingConnection("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");
        
         while (reqHdl.getLastExchange() == null) {
             QAUtil.sleep(50);
         }
        
         IHttpExchange serverExchange = reqHdl.getLastExchange();
         IHttpRequest srvReq = serverExchange.getRequest();
         srvReq.getHeader("Content-Length");
        
         QAUtil.sleep(500);
         try {
             con.readStringByDelimiter("\r\n\r\n");
             Assert.fail("BufferUnderflowException expected");
         } catch (BufferUnderflowException expected) { }
        
         srvReq.getBody().isOpen();
        
         QAUtil.sleep(500);
         Assert.assertTrue(con.readStringByDelimiter("\r\n\r\n").indexOf("100") != -1);
        
         con.close();
         server.close();
     }
View Full Code Here

     public void testAutoContinueUrlEncodedBody() throws Exception {
         RequestHandler reqHdl = new RequestHandler();       
         HttpServer server = new HttpServer(reqHdl);
         server.start();
        
         INonBlockingConnection con = new NonBlockingConnection("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-Type: application/x-www-form-urlencoded\r\n" +
                   "Content-Length: 2000\r\n" +
                   "\r\n");
        
        
         QAUtil.sleep(500);
         Assert.assertTrue(con.readStringByDelimiter("\r\n\r\n").indexOf("100") != -1);
        
        
         con.close();
         server.close();
     }   
View Full Code Here

        HttpServer proxy = new HttpServer(proxyHdl);
        proxy.start();
       
       
       
        INonBlockingConnection con = new NonBlockingConnection("localhost", proxy.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");

       
       
        QAUtil.sleep(500);
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);


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

        HttpServer proxy = new HttpServer(proxyHdl);
        proxy.start();
       
       
       
        INonBlockingConnection con = new NonBlockingConnection("localhost", proxy.getLocalPort());
        con.write("PUT / 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");

       
       
        while (reqHdl.getLastExchange() == null) {
            QAUtil.sleep(50);
        }
       
        reqHdl.getLastExchange().getRequest().getContentLength();
       
       
        QAUtil.sleep(500);
        try {
            String header = con.readStringByDelimiter("\r\n\r\n");
            Assert.fail("BufferUnderflowException expected");
        } catch (BufferUnderflowException expected) { }

        reqHdl.getLastExchange().getRequest().getNonBlockingBody().available();

        QAUtil.sleep(500);
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);

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

    private static final long IDLE_TIMEOUT_MILLIS = 60 * 1000;
   
    private MultiplexedConnection forwardMultiplexedConnection = null;
   
    public ForwardHandler(String forwardHost, int forwardPort) throws IOException {
      forwardMultiplexedConnection = new MultiplexedConnection(new NonBlockingConnection(forwardHost, forwardPort));
    }
View Full Code Here

 
  @Test
  public void testLifeAsyncConnect() throws Exception {
      
      ConnectHandler ch = new ConnectHandler();
      new NonBlockingConnection(InetAddress.getByName("www.web.de"), 80, ch, false, 2000);
     
      QAUtil.sleep(1500);
     
      IHttpClientEndpoint httpEndpoint = ch.getHttpConnection();
      IHttpResponse response = httpEndpoint.call(new GetRequest("/"));
View Full Code Here

  public void testAsyncConnectFailed() throws Exception {
         
    int connectionTimeoutMillis = 1000;
   
      ConnectHandler ch = new ConnectHandler();
      new NonBlockingConnection(InetAddress.getByName("192.168.255.255"), 80, ch, false, connectionTimeoutMillis);
         
      QAUtil.sleep(3000);
     
      if (ch.getIOException() == null) {
        System.out.println("exception expected");
View Full Code Here

   
    public SSLClientToProxyHandler(String forwardHost, int forwardPort, INonBlockingConnection clientToProxyConnection) throws IOException {
      clientToProxyConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      clientToProxyConnection.setAutoflush(true);
     
      INonBlockingConnection proxyToServerConnection = new NonBlockingConnection(InetAddress.getByName(forwardHost), forwardPort, new ProxyHandler(), 60 * 1000, SSLTestContextFactory.getSSLContext(), true, clientToProxyConnection.getWorkerpool());
     
      proxyToServerConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      proxyToServerConnection.setAutoflush(true);
      proxyToServerConnection.setAttachment(clientToProxyConnection);
     
      clientToProxyConnection.setAttachment(proxyToServerConnection);
    }
View Full Code Here

        SimpleDualPortServer dualPortServer = new SimpleDualPortServer(0, 0);
        new Thread(dualPortServer).start();
       
        QAUtil.sleep(1000);
    
        INonBlockingConnection nbc1 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc1.write((int) 55);
       
        INonBlockingConnection nbc2 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc2.write((int) 55);
       
        INonBlockingConnection nbc3 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc3.write((int) 66);
       
        QAUtil.sleep(1000);
       
        HttpClient httpClient = new HttpClient();

        IHttpResponse response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/66", "text/plain", "hello you"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you", response.getBlockingBody().readString());
       

        response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/66", "text/plain", "hello you2"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you2", response.getBlockingBody().readString());


        response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/55", "text/plain", "hello you3"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you3", response.getBlockingBody().readString());

       
        httpClient.close();
        nbc1.close();
        nbc2.close();
        nbc3.close();
        dualPortServer.close();
    }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.NonBlockingConnection

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.