Package org.xsocket.connection

Examples of org.xsocket.connection.NonBlockingConnection


        forwardHost = uri.substring(0, idx);
        forwardPort = Integer.parseInt(uri.substring(idx + 1, uri.length()));
      }
     
      try {
        INonBlockingConnection forwardCon = new NonBlockingConnection(forwardHost, forwardPort);
        INonBlockingConnection tcpCon = exchange.getConnection().getUnderlyingTcpConnection();

        forwardCon.setAttachment(tcpCon);
        tcpCon.setAttachment(forwardCon);
       
        forwardCon.setFlushmode(FlushMode.ASYNC);
        forwardCon.setAutoflush(true);
        tcpCon.setFlushmode(FlushMode.ASYNC);
        tcpCon.setAutoflush(true);

        forwardCon.setHandler(new TcpProxyHandler());
        tcpCon.setHandler(new TcpProxyHandler());
       
        IHttpResponse response = new HttpResponse(200);
        response.getResponseHeader().setReason("Connection established");
        response.setHeader("Proxy-agent", "myProxy");
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

        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

      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

      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

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.