Package org.xsocket.connection

Examples of org.xsocket.connection.INonBlockingConnection


     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().getBody().readString();
      nbc.close();
 
      double elapsedMillis = ((double) (respHdl.getTime() - start)) / 1000000;
      System.out.println(elapsedMillis + " millis");
     
      Assert.assertTrue(elapsedMillis < 2000);
View Full Code Here

  private static class Handler implements IDataHandler, IDisconnectHandler {
   
   
    @Execution(Execution.NONTHREADED)
    public final boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
      INonBlockingConnection forwardPipeline = (INonBlockingConnection) connection.getAttachment();
      forwardPipeline.setFlushmode(FlushMode.ASYNC);
     
      ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
     
      ByteBuffer[] copy = new ByteBuffer[data.length];
      for (int i = 0; i < data.length; i++) {
        copy[i] = data[i].duplicate();
      }
     
      forwardPipeline.write(data);
     
      return true;
    }
View Full Code Here

       
   
    @Execution(Execution.NONTHREADED)
    public final boolean onDisconnect(INonBlockingConnection connection) throws IOException {
     
      INonBlockingConnection peerConnection = (INonBlockingConnection) connection.getAttachment();
      if (peerConnection != null) {
        peerConnection.close();
        connection.setAttachment(null);
      }
     
      connection.close();
      //System.out.println("proxy connection destroyed " + connection.getId() + " -> " + peerConnection.getId());
View Full Code Here

    public boolean onConnect(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {

      connection.setIdleTimeoutMillis(IDLE_TIMEOUT_MILLIS);
     
      String pipelineId = forwardMultiplexedConnection.createPipeline();
      INonBlockingConnection forwardPipeline = forwardMultiplexedConnection.getNonBlockingPipeline(pipelineId);
        forwardPipeline.setHandler(new Handler());
     
        forwardPipeline.setIdleTimeoutMillis(IDLE_TIMEOUT_MILLIS * 2);
           
      connection.setAttachment(forwardPipeline);
      forwardPipeline.setAttachment(connection);
     
      //System.out.println("proxy connection established " + connection.getId() + " <-> " + pipelineId);     
      return true;
    }
View Full Code Here

          host = target.substring(0, idx);
          port = Integer.parseInt(target.substring(idx + 1, target.length()).trim());
        }
       
       
        INonBlockingConnection tcpConnection = exchange.getConnection().getUnderlyingTcpConnection();
       
        SSLClientToProxyHandler proxyHandler = new SSLClientToProxyHandler(host, port, tcpConnection);
        tcpConnection.setHandler(proxyHandler);
       
        HttpResponse response = new HttpResponse(200);
        exchange.send(response);
      }
    }
View Full Code Here

  @Execution(Execution.NONTHREADED)
  private static class ProxyHandler implements IDataHandler, IDisconnectHandler {
   
 
    public boolean onDisconnect(INonBlockingConnection connection) throws IOException {
      INonBlockingConnection reverseConnection = (INonBlockingConnection) connection.getAttachment();
      if (reverseConnection != null) {
        connection.setAttachment(null);
        reverseConnection.close();
      }
      return true;
    }
View Full Code Here

      return true;
    }
   
   
    public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
      INonBlockingConnection forwardConnection = (INonBlockingConnection) connection.getAttachment();

      ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
      forwardConnection.write(data);
      forwardConnection.flush();
     
      return true;
    }
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.