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);
 }
Example #2
0
 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()));
 }
Example #3
0
 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());
 }
Example #4
0
  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()));
  }
Example #5
0
  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()));
  }
Example #6
0
 public void setBacklog(int backlog) {
   endpoint.setBacklog(backlog);
 }
Example #7
0
 public int getUnlockTimeout() {
   return endpoint.getUnlockTimeout();
 }
Example #8
0
 public int getSoTimeout() {
   return endpoint.getSoTimeout();
 }
Example #9
0
 public int getSoLinger() {
   return endpoint.getSoLinger();
 }
Example #10
0
 public boolean getTcpNoDelay() {
   return endpoint.getTcpNoDelay();
 }
Example #11
0
 public InetAddress getAddress() {
   return endpoint.getAddress();
 }
Example #12
0
 public Executor getExecutor() {
   return endpoint.getExecutor();
 }
Example #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);
 }
Example #14
0
 public int getPort() {
   return endpoint.getPort();
 }
Example #15
0
 public void setExecutor(Executor executor) {
   endpoint.setExecutor(executor);
 }
Example #16
0
 public void setPort(int port) {
   endpoint.setPort(port);
 }
Example #17
0
 public int getMaxThreads() {
   return endpoint.getMaxThreads();
 }
Example #18
0
 public void setAddress(InetAddress ia) {
   endpoint.setAddress(ia);
 }
Example #19
0
 public void setMaxThreads(int maxThreads) {
   endpoint.setMaxThreads(maxThreads);
 }
Example #20
0
 public void setTcpNoDelay(boolean tcpNoDelay) {
   endpoint.setTcpNoDelay(tcpNoDelay);
 }
Example #21
0
 public int getThreadPriority() {
   return endpoint.getThreadPriority();
 }
Example #22
0
 public void setSoLinger(int soLinger) {
   endpoint.setSoLinger(soLinger);
 }
Example #23
0
 public void setThreadPriority(int threadPriority) {
   endpoint.setThreadPriority(threadPriority);
 }
Example #24
0
 public void setSoTimeout(int soTimeout) {
   endpoint.setSoTimeout(soTimeout);
 }
Example #25
0
 public int getBacklog() {
   return endpoint.getBacklog();
 }
Example #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);
      }
    }
  }