Package org.xsocket.connection

Examples of org.xsocket.connection.INonBlockingConnection


           

            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("try to get a connection from pool (waitForConnect = true)");
            }
            INonBlockingConnection con = pool.getNonBlockingConnection(InetAddress.getByName(host), normalizePort(port, isSSL), true, connectTimeoutMillis, isSSL);

            HttpClientConnection httpCon = newHttpClientConnection(con);
            setHttpConnection(httpCon);
           
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("[" + con.getId() + "] sending request to remote endpoint");
            }
           
            if (contentLength == null) {
                return httpCon.send(requestHeader, responseHandler);
            } else {
View Full Code Here


        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");
        exchange.send(response);
View Full Code Here

  private static class TcpProxyHandler 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();
       
      int available = connection.available();
      if (available > 0) {
        ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
        forwardConnection.write(data);
        forwardConnection.flush();
      } else if (available == -1) {
        connection.close();
      }
     
      return true;
View Full Code Here

     * @param targetHost       the target host
     * @param targetPort       the target port
     * @throws IOException if an exception occurs
     */
    public static void establishTcpTunnel(IHttpConnection httpConnection, String targetHost, int targetPort) throws IOException {
        INonBlockingConnection forwardCon = new NonBlockingConnection(targetHost, targetPort);
       
        INonBlockingConnection tcpCon = httpConnection.getUnderlyingTcpConnection();

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

        forwardCon.setHandler(new TcpProxyHandler());
        tcpCon.setHandler(new TcpProxyHandler());
    }
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

   
    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

     * @param targetHost       the target host
     * @param targetPort       the target port
     * @throws IOException if an exception occurs
     */
    public static void establishTcpTunnel(IHttpConnection httpConnection, String targetHost, int targetPort) throws IOException {
        INonBlockingConnection forwardCon = new NonBlockingConnection(targetHost, targetPort);
       
        INonBlockingConnection tcpCon = httpConnection.getUnderlyingTcpConnection();

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

        forwardCon.setHandler(new TcpProxyHandler());
        tcpCon.setHandler(new TcpProxyHandler());
    }
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.