public SpdyProxyProtocol() {
   endpoint = new JIoEndpoint();
   ((JIoEndpoint) endpoint).setHandler(cHandler);
   setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
   setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
   setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
 }
 public void resume() throws Exception {
   try {
     endpoint.resume();
   } catch (Exception ex) {
     log.error(sm.getString("http11protocol.endpoint.resumeerror"), ex);
     throw ex;
   }
   if (log.isInfoEnabled()) log.info(sm.getString("http11protocol.resume", getName()));
 }
 public String getName() {
   String encodedAddr = "";
   if (getAddress() != null) {
     encodedAddr = "" + getAddress();
     if (encodedAddr.startsWith("/")) encodedAddr = encodedAddr.substring(1);
     encodedAddr = URLEncoder.encode(encodedAddr) + "-";
   }
   return ("http-" + encodedAddr + endpoint.getPort());
 }
  public void init() throws Exception {
    endpoint.setName(getName());
    endpoint.setHandler(cHandler);

    // Verify the validity of the configured socket factory
    try {
      if (isSSLEnabled()) {
        sslImplementation = SSLImplementation.getInstance(sslImplementationName);
        socketFactory = sslImplementation.getServerSocketFactory();
        endpoint.setServerSocketFactory(socketFactory);
      } else if (socketFactoryName != null) {
        socketFactory = (ServerSocketFactory) Class.forName(socketFactoryName).newInstance();
        endpoint.setServerSocketFactory(socketFactory);
      }
    } catch (Exception ex) {
      log.error(sm.getString("http11protocol.socketfactory.initerror"), ex);
      throw ex;
    }

    if (socketFactory != null) {
      Iterator<String> attE = attributes.keySet().iterator();
      while (attE.hasNext()) {
        String key = attE.next();
        Object v = attributes.get(key);
        socketFactory.setAttribute(key, v);
      }
    }

    try {
      endpoint.init();
    } catch (Exception ex) {
      log.error(sm.getString("http11protocol.endpoint.initerror"), ex);
      throw ex;
    }
    if (log.isInfoEnabled()) log.info(sm.getString("http11protocol.init", getName()));
  }
  public void start() throws Exception {
    if (this.domain != null) {
      try {
        tpOname = new ObjectName(domain + ":" + "type=ThreadPool,name=" + getName());
        Registry.getRegistry(null, null).registerComponent(endpoint, tpOname, null);
      } catch (Exception e) {
        log.error("Can't register endpoint");
      }
      rgOname = new ObjectName(domain + ":type=GlobalRequestProcessor,name=" + getName());
      Registry.getRegistry(null, null).registerComponent(cHandler.global, rgOname, null);
    }

    try {
      endpoint.start();
    } catch (Exception ex) {
      log.error(sm.getString("http11protocol.endpoint.starterror"), ex);
      throw ex;
    }
    if (log.isInfoEnabled()) log.info(sm.getString("http11protocol.start", getName()));
  }
 public void setBacklog(int backlog) {
   endpoint.setBacklog(backlog);
 }
 public int getUnlockTimeout() {
   return endpoint.getUnlockTimeout();
 }
 public int getSoTimeout() {
   return endpoint.getSoTimeout();
 }
 public int getSoLinger() {
   return endpoint.getSoLinger();
 }
Beispiel #10
0
 public boolean getTcpNoDelay() {
   return endpoint.getTcpNoDelay();
 }
Beispiel #11
0
 public InetAddress getAddress() {
   return endpoint.getAddress();
 }
Beispiel #12
0
 public Executor getExecutor() {
   return endpoint.getExecutor();
 }
Beispiel #13
0
 public void destroy() throws Exception {
   if (log.isInfoEnabled()) log.info(sm.getString("http11protocol.stop", getName()));
   endpoint.destroy();
   if (tpOname != null) Registry.getRegistry(null, null).unregisterComponent(tpOname);
   if (rgOname != null) Registry.getRegistry(null, null).unregisterComponent(rgOname);
 }
Beispiel #14
0
 public int getPort() {
   return endpoint.getPort();
 }
Beispiel #15
0
 public void setExecutor(Executor executor) {
   endpoint.setExecutor(executor);
 }
Beispiel #16
0
 public void setPort(int port) {
   endpoint.setPort(port);
 }
Beispiel #17
0
 public int getMaxThreads() {
   return endpoint.getMaxThreads();
 }
Beispiel #18
0
 public void setAddress(InetAddress ia) {
   endpoint.setAddress(ia);
 }
Beispiel #19
0
 public void setMaxThreads(int maxThreads) {
   endpoint.setMaxThreads(maxThreads);
 }
Beispiel #20
0
 public void setTcpNoDelay(boolean tcpNoDelay) {
   endpoint.setTcpNoDelay(tcpNoDelay);
 }
Beispiel #21
0
 public int getThreadPriority() {
   return endpoint.getThreadPriority();
 }
Beispiel #22
0
 public void setSoLinger(int soLinger) {
   endpoint.setSoLinger(soLinger);
 }
Beispiel #23
0
 public void setThreadPriority(int threadPriority) {
   endpoint.setThreadPriority(threadPriority);
 }
Beispiel #24
0
 public void setSoTimeout(int soTimeout) {
   endpoint.setSoTimeout(soTimeout);
 }
Beispiel #25
0
 public int getBacklog() {
   return endpoint.getBacklog();
 }
Beispiel #26
0
 public void setUnlockTimeout(int unlockTimeout) {
   endpoint.setUnlockTimeout(unlockTimeout);
 }
  /**
   * Send an action to the connector.
   *
   * @param actionCode Type of the action
   * @param param Action parameter
   */
  @Override
  public void actionInternal(ActionCode actionCode, Object param) {

    if (actionCode == ActionCode.REQ_SSL_ATTRIBUTE) {

      try {
        if (sslSupport != null) {
          Object sslO = sslSupport.getCipherSuite();
          if (sslO != null) request.setAttribute(SSLSupport.CIPHER_SUITE_KEY, sslO);
          sslO = sslSupport.getPeerCertificateChain(false);
          if (sslO != null) request.setAttribute(SSLSupport.CERTIFICATE_KEY, sslO);
          sslO = sslSupport.getKeySize();
          if (sslO != null) request.setAttribute(SSLSupport.KEY_SIZE_KEY, sslO);
          sslO = sslSupport.getSessionId();
          if (sslO != null) request.setAttribute(SSLSupport.SESSION_ID_KEY, sslO);
          request.setAttribute(SSLSupport.SESSION_MGR, sslSupport);
        }
      } catch (Exception e) {
        log.warn(sm.getString("http11processor.socket.ssl"), e);
      }

    } else if (actionCode == ActionCode.REQ_HOST_ADDR_ATTRIBUTE) {

      if ((remoteAddr == null) && (socket != null)) {
        InetAddress inetAddr = socket.getSocket().getInetAddress();
        if (inetAddr != null) {
          remoteAddr = inetAddr.getHostAddress();
        }
      }
      request.remoteAddr().setString(remoteAddr);

    } else if (actionCode == ActionCode.REQ_LOCAL_NAME_ATTRIBUTE) {

      if ((localName == null) && (socket != null)) {
        InetAddress inetAddr = socket.getSocket().getLocalAddress();
        if (inetAddr != null) {
          localName = inetAddr.getHostName();
        }
      }
      request.localName().setString(localName);

    } else if (actionCode == ActionCode.REQ_HOST_ATTRIBUTE) {

      if ((remoteHost == null) && (socket != null)) {
        InetAddress inetAddr = socket.getSocket().getInetAddress();
        if (inetAddr != null) {
          remoteHost = inetAddr.getHostName();
        }
        if (remoteHost == null) {
          if (remoteAddr != null) {
            remoteHost = remoteAddr;
          } else { // all we can do is punt
            request.remoteHost().recycle();
          }
        }
      }
      request.remoteHost().setString(remoteHost);

    } else if (actionCode == ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE) {

      if (localAddr == null) localAddr = socket.getSocket().getLocalAddress().getHostAddress();

      request.localAddr().setString(localAddr);

    } else if (actionCode == ActionCode.REQ_REMOTEPORT_ATTRIBUTE) {

      if ((remotePort == -1) && (socket != null)) {
        remotePort = socket.getSocket().getPort();
      }
      request.setRemotePort(remotePort);

    } else if (actionCode == ActionCode.REQ_LOCALPORT_ATTRIBUTE) {

      if ((localPort == -1) && (socket != null)) {
        localPort = socket.getSocket().getLocalPort();
      }
      request.setLocalPort(localPort);

    } else if (actionCode == ActionCode.REQ_SSL_CERTIFICATE) {
      if (sslSupport != null) {
        /*
         * Consume and buffer the request body, so that it does not
         * interfere with the client's handshake messages
         */
        InputFilter[] inputFilters = inputBuffer.getFilters();
        ((BufferedInputFilter) inputFilters[Constants.BUFFERED_FILTER]).setLimit(maxSavePostSize);
        inputBuffer.addActiveFilter(inputFilters[Constants.BUFFERED_FILTER]);
        try {
          Object sslO = sslSupport.getPeerCertificateChain(true);
          if (sslO != null) {
            request.setAttribute(SSLSupport.CERTIFICATE_KEY, sslO);
          }
        } catch (Exception e) {
          log.warn(sm.getString("http11processor.socket.ssl"), e);
        }
      }
    } else if (actionCode == ActionCode.ASYNC_COMPLETE) {
      if (asyncStateMachine.asyncComplete()) {
        ((JIoEndpoint) endpoint).processSocketAsync(this.socket, SocketStatus.OPEN);
      }
    } else if (actionCode == ActionCode.ASYNC_SETTIMEOUT) {
      if (param == null) return;
      long timeout = ((Long) param).longValue();
      // if we are not piggy backing on a worker thread, set the timeout
      socket.setTimeout(timeout);
    } else if (actionCode == ActionCode.ASYNC_DISPATCH) {
      if (asyncStateMachine.asyncDispatch()) {
        ((JIoEndpoint) endpoint).processSocketAsync(this.socket, SocketStatus.OPEN);
      }
    }
  }