Package org.xsocket.connection

Examples of org.xsocket.connection.INonBlockingConnection


   
    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


        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.getBlockingBody().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

    for (int i = 0; i < 10; i++) {
      ConnectHandler ch = new ConnectHandler();
     
      long start = System.nanoTime();
     
      INonBlockingConnection nbc = pool.getNonBlockingConnection("www.gmx.com", 80, ch);
      // perform ch.isConnected() later. It will be called multithreaded
     
      HttpClientConnection con = new HttpClientConnection(nbc);
     
      IHttpRequest request = new GetRequest("http://www.gmx.com/doesNotExist.html");
     
      ResponseHandler respHdl = new ResponseHandler();
      con.send(request, respHdl);
 
      while (respHdl.getResponse() == null) {
        QAUtil.sleep(100);
      }
     
      respHdl.getResponse().getBlockingBody().readString();
      nbc.close();
 
      double elapsedMillis = ((double) (respHdl.getTime() - start)) / 1000000;
      System.out.println(elapsedMillis + " millis");
     
      Assert.assertTrue(elapsedMillis < 2000);
View Full Code Here

      SSLContext sslContext = SSLTestContextFactory.getSSLContext();
     
        IServer server = new HttpServer(0, new ContentEchoHandler(), sslContext, true);
        server.start();

        INonBlockingConnection tcpCon = new NonBlockingConnection("localhost", server.getLocalPort(), sslContext, true);
        HttpClientConnection con = new HttpClientConnection(tcpCon);
   
           
        FutureResponseHandler hdl = new FutureResponseHandler();
       
View Full Code Here

      SSLContext sslContext = SSLTestContextFactory.getSSLContext();
     
        IServer server = new HttpServer(0, new ContentEchoHandler(), sslContext, true);
        server.start();

        INonBlockingConnection tcpCon = new NonBlockingConnection("localhost", server.getLocalPort(), sslContext, true);
        HttpClientConnection con = new HttpClientConnection(tcpCon);
   
           
        FutureResponseHandler hdl = new FutureResponseHandler();
       
View Full Code Here

    httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/"), respHdl);

    IBlockingConnection serverCon = null;
    long start = System.currentTimeMillis();
    do {
      INonBlockingConnection nbc = dh.getConnection();
      if (nbc != null) {
        serverCon = new BlockingConnection(nbc);
        break;
      }
      QAUtil.sleep(100);
View Full Code Here

TOP

Related Classes of org.xsocket.connection.INonBlockingConnection

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.