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