Package org.xsocket.connection

Examples of org.xsocket.connection.NonBlockingConnection


       
    } else {
      try {
        if (sslCtx != null) {
          tcpConnection = new NonBlockingConnection(host, port, sslCtx, true);
          ((NonBlockingConnection) tcpConnection).setWorkerpool(pool.getWorkerpool());
         
        } else {
          tcpConnection = new NonBlockingConnection(host, port);
          ((NonBlockingConnection) tcpConnection).setWorkerpool(pool.getWorkerpool());
        }
      } catch (IOException ioe) {
        throw new ConnectException("could not connect to " + host + ":" + port + " reason: " + ioe.toString());
      }
View Full Code Here


    if (idx != -1) {
      forwardPort = Integer.parseInt(host.substring(idx + 1, host.length()));
      forwardHost = host.substring(0, idx);
    }

    INonBlockingConnection con = new NonBlockingConnection(securedProxyHost, securedProxyPort, sslContext, false);
    con.setHandler(new DataHandler(exchange));

   
    StringBuilder sb = new StringBuilder();
   
    sb.append("CONNECT " + forwardHost + ":" + forwardPort + " HTTP/1.1\r\n" +
          "Host: " + host + "\r\n" +
          "User-Agent: xLightweb/" + HttpUtils.getImplementationVersion() + "\r\n");
   
   
    if (proxyUser != null) {
      if (proxyUserPassword != null) {
        sb.append("Proxy-Authorization: Basic " + proxyUserPassword + "\r\n");
       
      } else {
        exchange.sendError(401, "proxy user password is not set (hint: usage <HttpClient>.setProxyPassword(...)");
        return;
      }
    }

    sb.append("Proxy-Connection: keep-alive\r\n" +
          "\r\n");
   
    con.write(sb.toString());
  }
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

 

  private static INonBlockingConnection newNonBlockingConnection(InetSocketAddress address) throws ConnectException {
    try {
      return new NonBlockingConnection(address);
    } catch (IOException ioe) {
      throw new ConnectException(ioe.toString());
    }
  }
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



  private static INonBlockingConnection newNonBlockingConnection(InetSocketAddress address) throws ConnectException {
    try {
      return new NonBlockingConnection(address);
    } catch (IOException ioe) {
      throw new ConnectException(ioe.toString());
    }
  }
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");
View Full Code Here

    @Test
    public void testIdleTimeout() throws Exception {

        IServer server = new HttpServer(new DoNothingRequestHandler());
       
        INonBlockingConnection con = new NonBlockingConnection("localhost", server.getLocalPort());
        con.setIdleTimeoutMillis(1000);
       
        HttpClientConnection httpCon = new HttpClientConnection(con);
       
        ResponseHandler respHdl = new ResponseHandler();
        httpCon.send(new GetRequest("/"), respHdl);
View Full Code Here

    @Test
    public void testIdleTimeoutHandler() throws Exception {

        IServer server = new HttpServer(new DoNothingRequestHandler());
       
        INonBlockingConnection con = new NonBlockingConnection("localhost", server.getLocalPort());
        con.setIdleTimeoutMillis(1000);
       
        HttpClientConnection httpCon = new HttpClientConnection(con);
       
        ResponseHandler2 respHdl = new ResponseHandler2();
        httpCon.send(new GetRequest("/"), respHdl);
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.