Java Code Examples for org.apache.catalina.connector.Connector

The following are top voted examples for showing how to use org.apache.catalina.connector.Connector. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: oryx2   File: ServingLayer.java   Source Code and License 7 votes vote down vote up
private Connector makeConnector() {
  Connector connector = new Connector(Http11Nio2Protocol.class.getName());

  if (keystoreFile == null) {

    // HTTP connector
    connector.setPort(port);
    connector.setSecure(false);
    connector.setScheme("http");

  } else {

    // HTTPS connector
    connector.setPort(securePort);
    connector.setSecure(true);
    connector.setScheme("https");
    connector.setAttribute("SSLEnabled", "true");
    SSLHostConfig sslHostConfig = new SSLHostConfig();
    SSLHostConfigCertificate cert =
        new SSLHostConfigCertificate(sslHostConfig, SSLHostConfigCertificate.Type.RSA);
    cert.setCertificateKeystoreFile(keystoreFile.toAbsolutePath().toString());
    cert.setCertificateKeystorePassword(keystorePassword);
    cert.setCertificateKeyAlias(keyAlias);
    sslHostConfig.addCertificate(cert);
    connector.addSslHostConfig(sslHostConfig);
  }

  connector.addUpgradeProtocol(new Http2Protocol());

  // Keep quiet about the server type
  connector.setXpoweredBy(false);

  // Basic tuning params:
  connector.setAttribute("maxThreads", 400);
  connector.setAttribute("acceptCount", 50);
  //connector.setAttribute("connectionTimeout", 2000);
  connector.setAttribute("maxKeepAliveRequests", 100);

  // Avoid running out of ephemeral ports under heavy load?
  connector.setAttribute("socket.soReuseAddress", true);

  connector.setMaxPostSize(0);
  connector.setAttribute("disableUploadTimeout", false);

  // Allow long URLs
  connector.setAttribute("maxHttpHeaderSize", 65536);

  // Enable response compression
  connector.setAttribute("compression", "on");
  // Defaults are text/html,text/xml,text/plain,text/css
  connector.setAttribute("compressableMimeType", "text/html,text/xml,text/plain,text/css,text/csv,application/json");

  return connector;
}
 
Example 2
Project: Android_watch_magpie   File: OAuth2SecurityConfiguration.java   Source Code and License 7 votes vote down vote up
private Connector createSSLConnector(String absoluteKeyStore, String keystorePass) {
	Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
	Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
	try {
		connector.setPort(8443);
		connector.setSecure(true);
		connector.setScheme("https");
		
		protocol.setSSLEnabled(true);
		protocol.setKeystoreFile(absoluteKeyStore);
		protocol.setKeystorePass(keystorePass);
		protocol.setKeystoreType("JKS");
		protocol.setKeyAlias("tomcat");
		return connector;
	} catch(Exception ex) {
		throw new IllegalStateException("Can't access to keystore: [" + absoluteKeyStore + "]", ex);
	}
}
 
Example 3
Project: danyuan-application   File: App.java   Source Code and License 6 votes vote down vote up
public Connector httpConnector() {
	Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
	connector.setScheme("http");
	// Connector监听的http的端口号
	connector.setPort(80);
	connector.setSecure(false);
	// 监听到http的端口号后转向到的https的端口号
	connector.setRedirectPort(8443);
	return connector;
}
 
Example 4
Project: tomcat7   File: Embedded.java   Source Code and License 6 votes vote down vote up
/**
 * Add a new Connector to the set of defined Connectors.  The newly
 * added Connector will be associated with the most recently added Engine.
 *
 * @param connector The connector to be added
 *
 * @exception IllegalStateException if no engines have been added yet
 */
@Override
public synchronized void addConnector(Connector connector) {

    if( log.isDebugEnabled() ) {
        log.debug("Adding connector (" + connector.getInfo() + ")");
    }

    // Make sure we have a Container to send requests to
    if (engines.length < 1)
        throw new IllegalStateException
            (sm.getString("embedded.noEngines"));

    /*
     * Add the connector. This will set the connector's container to the
     * most recently added Engine
     */
    super.addConnector(connector);
}
 
Example 5
Project: tomcat7   File: MBeanFactory.java   Source Code and License 6 votes vote down vote up
/**
 * Create a new Connector
 *
 * @param parent MBean Name of the associated parent component
 * @param address The IP address on which to bind
 * @param port TCP port number to listen on
 * @param isAjp Create a AJP/1.3 Connector
 * @param isSSL Create a secure Connector
 *
 * @exception Exception if an MBean cannot be created or registered
 */
private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL)
    throws Exception {
    Connector retobj = new Connector();
    if ((address!=null) && (address.length()>0)) {
        retobj.setProperty("address", address);
    }
    // Set port number
    retobj.setPort(port);
    // Set the protocol
    retobj.setProtocol(isAjp ? "AJP/1.3" : "HTTP/1.1");
    // Set SSL
    retobj.setSecure(isSSL);
    retobj.setScheme(isSSL ? "https" : "http");
    // Add the new instance to its parent component
    // FIX ME - addConnector will fail
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    service.addConnector(retobj);
    
    // Return the corresponding MBean name
    ObjectName coname = retobj.getObjectName();
    
    return (coname.toString());
}
 
Example 6
Project: tomcat7   File: ApplicationContext.java   Source Code and License 6 votes vote down vote up
private void populateSessionTrackingModes() {
    // URL re-writing is always enabled by default
    defaultSessionTrackingModes = EnumSet.of(SessionTrackingMode.URL);
    supportedSessionTrackingModes = EnumSet.of(SessionTrackingMode.URL);

    if (context.getCookies()) {
        defaultSessionTrackingModes.add(SessionTrackingMode.COOKIE);
        supportedSessionTrackingModes.add(SessionTrackingMode.COOKIE);
    }

    // SSL not enabled by default as it can only used on its own
    // Context > Host > Engine > Service
    Service s = ((Engine) context.getParent().getParent()).getService();
    Connector[] connectors = s.findConnectors();
    // Need at least one SSL enabled connector to use the SSL session ID.
    for (Connector connector : connectors) {
        if (Boolean.TRUE.equals(connector.getAttribute("SSLEnabled"))) {
            supportedSessionTrackingModes.add(SessionTrackingMode.SSL);
            break;
        }
    }
}
 
Example 7
Project: lazycat   File: CatalinaUtil.java   Source Code and License 6 votes vote down vote up
public static int getPort(Host h) {
	int port = -1;
	StandardHost host = (StandardHost) h;
	CatalinaUtil.host = (StandardHost) h;

	StandardEngine se = (StandardEngine) host.getParent();
	StandardService ss = (StandardService) se.getService();

	Connector[] cs = ss.findConnectors();
	for (Connector c : cs) {

		if (c.getProtocolHandlerClassName().contains("Http11Protocol"))
			port = c.getPort();
	}
	return port;
}
 
Example 8
Project: tomcat7   File: StandardService.java   Source Code and License 6 votes vote down vote up
/**
 * Add a new Connector to the set of defined Connectors, and associate it
 * with this Service's Container.
 *
 * @param connector The Connector to be added
 */
@Override
public void addConnector(Connector connector) {

    synchronized (connectorsLock) {
        connector.setService(this);
        Connector results[] = new Connector[connectors.length + 1];
        System.arraycopy(connectors, 0, results, 0, connectors.length);
        results[connectors.length] = connector;
        connectors = results;

        if (getState().isAvailable()) {
            try {
                connector.start();
            } catch (LifecycleException e) {
                log.error(sm.getString(
                        "standardService.connector.startFailed",
                        connector), e);
            }
        }

        // Report this property change to interested listeners
        support.firePropertyChange("connector", null, connector);
    }

}
 
Example 9
Project: tomcat7   File: StandardService.java   Source Code and License 6 votes vote down vote up
@Override
protected void destroyInternal() throws LifecycleException {
    // Destroy our defined Connectors
    synchronized (connectorsLock) {
        for (Connector connector : connectors) {
            try {
                connector.destroy();
            } catch (Exception e) {
                log.error(sm.getString(
                        "standardService.connector.destroyFailed",
                        connector), e);
            }
        }
    }

    // Destroy any Executors
    for (Executor executor : findExecutors()) {
        executor.destroy();
    }

    if (container != null) {
        container.destroy();
    }

    super.destroyInternal();
}
 
Example 10
Project: lazycat   File: MBeanFactory.java   Source Code and License 6 votes vote down vote up
/**
 * Create a new Connector
 *
 * @param parent
 *            MBean Name of the associated parent component
 * @param address
 *            The IP address on which to bind
 * @param port
 *            TCP port number to listen on
 * @param isAjp
 *            Create a AJP/1.3 Connector
 * @param isSSL
 *            Create a secure Connector
 *
 * @exception Exception
 *                if an MBean cannot be created or registered
 */
private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL)
		throws Exception {
	Connector retobj = new Connector();
	if ((address != null) && (address.length() > 0)) {
		retobj.setProperty("address", address);
	}
	// Set port number
	retobj.setPort(port);
	// Set the protocol
	retobj.setProtocol(isAjp ? "AJP/1.3" : "HTTP/1.1");
	// Set SSL
	retobj.setSecure(isSSL);
	retobj.setScheme(isSSL ? "https" : "http");
	// Add the new instance to its parent component
	// FIX ME - addConnector will fail
	ObjectName pname = new ObjectName(parent);
	Service service = getService(pname);
	service.addConnector(retobj);

	// Return the corresponding MBean name
	ObjectName coname = retobj.getObjectName();

	return (coname.toString());
}
 
Example 11
Project: Equella   File: TomcatServiceImpl.java   Source Code and License 6 votes vote down vote up
private void setConnector(Connector connector)
{
	if( maxThreads != -2 )
	{
		connector.setAttribute("maxThreads", maxThreads);
	}
	connector.setURIEncoding("UTF-8");
	connector.setUseBodyEncodingForURI(true);
	tomcat.getService().addConnector(connector);
	tomcat.setConnector(connector);
}
 
Example 12
Project: lams   File: Embedded.java   Source Code and License 6 votes vote down vote up
/**
 * Add a new Connector to the set of defined Connectors.  The newly
 * added Connector will be associated with the most recently added Engine.
 *
 * @param connector The connector to be added
 *
 * @exception IllegalStateException if no engines have been added yet
 */
public synchronized void addConnector(Connector connector) {

    if( log.isDebugEnabled() ) {
        log.debug("Adding connector (" + connector.getInfo() + ")");
    }

    // Make sure we have a Container to send requests to
    if (engines.length < 1)
        throw new IllegalStateException
            (sm.getString("embedded.noEngines"));

    /*
     * Add the connector. This will set the connector's container to the
     * most recently added Engine
     */
    super.addConnector(connector);
}
 
Example 13
Project: lams   File: ServerLifecycleListener.java   Source Code and License 6 votes vote down vote up
/**
 * Create the MBeans for the specified Service and its nested components.
 *
 * @param service Service for which to create MBeans
 *
 * @exception Exception if an exception is thrown during MBean creation
 */
protected void createMBeans(Service service) throws Exception {

    // Create the MBean for the Service itself
    if (log.isDebugEnabled())
        log.debug("Creating MBean for Service " + service);
    //MBeanUtils.createMBean(service);
    if (service instanceof StandardService) {
        ((StandardService) service).addPropertyChangeListener(this);
    }

    // Create the MBeans for the corresponding Connectors
    Connector connectors[] = service.findConnectors();
    for (int j = 0; j < connectors.length; j++) {
        createMBeans(connectors[j]);
    }

    // Create the MBean for the associated Engine and friends
    Engine engine = (Engine) service.getContainer();
    if (engine != null) {
        createMBeans(engine);
    }

}
 
Example 14
Project: lazycat   File: StandardService.java   Source Code and License 6 votes vote down vote up
@Override
protected void destroyInternal() throws LifecycleException {
	// Destroy our defined Connectors
	synchronized (connectorsLock) {
		for (Connector connector : connectors) {
			try {
				connector.destroy();
			} catch (Exception e) {
				log.error(sm.getString("standardService.connector.destroyFailed", connector), e);
			}
		}
	}

	// Destroy any Executors
	for (Executor executor : findExecutors()) {
		executor.destroy();
	}

	if (container != null) {
		container.destroy();
	}

	super.destroyInternal();
}
 
Example 15
Project: lams   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Connector connector)
    throws Exception {

    String mname = createManagedName(connector);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(connector);
    ObjectName oname = createObjectName(domain, connector);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example 16
Project: lams   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
static void destroyMBean(Connector connector, Service service)
    throws Exception {

    connector.setService(service);
    String mname = createManagedName(connector);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, connector);
    connector.setService(null);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
}
 
Example 17
Project: lams   File: ClusterListener.java   Source Code and License 6 votes vote down vote up
/**
 * Find the most likely connector the proxy server should connect to, or
 * accept connections from.
 * 
 * @param connectors
 * @return
 */
protected Connector findProxyConnector(Connector[] connectors) {
    int pos = 0;
    int maxThreads = 0;
    for (int i = 0; i < connectors.length; i++) {
        if (connectors[i].getProtocol().startsWith("AJP")) {
            // Return any AJP connector found
            return connectors[i];
        }
        if (Boolean.TRUE.equals(IntrospectionUtils.getProperty(connectors[i].getProtocolHandler(), "reverseConnection"))) {
            return connectors[i];
        }
        Integer mt = (Integer) IntrospectionUtils.getProperty(connectors[i].getProtocolHandler(), "maxThreads");
        if (mt.intValue() > maxThreads) {
            maxThreads = mt.intValue();
            pos = i;
        }
    }
    // If no AJP connector and no reverse, return the connector with the most threads
    return connectors[pos];
}
 
Example 18
Project: simple-hostel-management   File: Utils.java   Source Code and License 6 votes vote down vote up
/**
 * /!\ Work only if application run on embedded Tomcat server
 *
 * @return
 * @throws Exception
 */
public static String getBaseUrlForEmbeddedTomcat() throws Exception {

    // get embedded tomcat
    EmbeddedWebApplicationContext appContext = (EmbeddedWebApplicationContext) new ApplicationContextProvider().getApplicationContext();
    Tomcat tomcat = ((TomcatEmbeddedServletContainer) appContext.getEmbeddedServletContainer()).getTomcat();
    Connector connector = tomcat.getConnector();

    // compose address
    String scheme = connector.getScheme();
    String hostName = tomcat.getHost().getName();
    int port = connector.getPort();
    String contextPath = appContext.getServletContext().getContextPath();

    return scheme + "://" + hostName + ":" + port + contextPath;
}
 
Example 19
Project: apache-tomcat-7.0.73-with-comment   File: Embedded.java   Source Code and License 6 votes vote down vote up
/**
 * Add a new Connector to the set of defined Connectors.  The newly
 * added Connector will be associated with the most recently added Engine.
 *
 * @param connector The connector to be added
 *
 * @exception IllegalStateException if no engines have been added yet
 */
@Override
public synchronized void addConnector(Connector connector) {

    if( log.isDebugEnabled() ) {
        log.debug("Adding connector (" + connector.getInfo() + ")");
    }

    // Make sure we have a Container to send requests to
    if (engines.length < 1)
        throw new IllegalStateException
            (sm.getString("embedded.noEngines"));

    /*
     * Add the connector. This will set the connector's container to the
     * most recently added Engine
     */
    super.addConnector(connector);
}
 
Example 20
Project: lazycat   File: Embedded.java   Source Code and License 6 votes vote down vote up
/**
 * Add a new Connector to the set of defined Connectors. The newly added
 * Connector will be associated with the most recently added Engine.
 *
 * @param connector
 *            The connector to be added
 *
 * @exception IllegalStateException
 *                if no engines have been added yet
 */
@Override
public synchronized void addConnector(Connector connector) {

	if (log.isDebugEnabled()) {
		log.debug("Adding connector (" + connector.getInfo() + ")");
	}

	// Make sure we have a Container to send requests to
	if (engines.length < 1)
		throw new IllegalStateException(sm.getString("embedded.noEngines"));

	/*
	 * Add the connector. This will set the connector's container to the
	 * most recently added Engine
	 */
	super.addConnector(connector);
}
 
Example 21
Project: smarti   File: TomcatConfiguration.java   Source Code and License 6 votes vote down vote up
@Bean
public EmbeddedServletContainerFactory servletContainer() {

    final TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    if (isEnabled()) {
        final Connector ajpConnector = new Connector(getProtocol());
        ajpConnector.setPort(getPort());
        ajpConnector.setSecure(isSecure());
        ajpConnector.setAllowTrace(isAllowTrace());
        ajpConnector.setScheme(getScheme());

        tomcat.addAdditionalTomcatConnectors(ajpConnector);
    }

    return tomcat;
}
 
Example 22
Project: apache-tomcat-7.0.73-with-comment   File: StandardService.java   Source Code and License 6 votes vote down vote up
/**
 * Add a new Connector to the set of defined Connectors, and associate it
 * with this Service's Container.
 *
 * @param connector The Connector to be added
 */
@Override
public void addConnector(Connector connector) {

    synchronized (connectorsLock) {
        connector.setService(this);
        Connector results[] = new Connector[connectors.length + 1];
        System.arraycopy(connectors, 0, results, 0, connectors.length);
        results[connectors.length] = connector;
        connectors = results;

        if (getState().isAvailable()) {
            try {
                connector.start();
            } catch (LifecycleException e) {
                log.error(sm.getString(
                        "standardService.connector.startFailed",
                        connector), e);
            }
        }

        // Report this property change to interested listeners
        support.firePropertyChange("connector", null, connector);
    }

}
 
Example 23
Project: lazycat   File: StandardService.java   Source Code and License 6 votes vote down vote up
/**
 * Add a new Connector to the set of defined Connectors, and associate it
 * with this Service's Container.
 *
 * @param connector
 *            The Connector to be added
 */
@Override
public void addConnector(Connector connector) {

	synchronized (connectorsLock) {
		connector.setService(this);
		Connector results[] = new Connector[connectors.length + 1];
		System.arraycopy(connectors, 0, results, 0, connectors.length);
		results[connectors.length] = connector;
		connectors = results;

		if (getState().isAvailable()) {
			try {
				connector.start();
			} catch (LifecycleException e) {
				log.error(sm.getString("standardService.connector.startFailed", connector), e);
			}
		}

		// Report this property change to interested listeners
		support.firePropertyChange("connector", null, connector);
	}

}
 
Example 24
Project: lazycat   File: ApplicationContext.java   Source Code and License 6 votes vote down vote up
private void populateSessionTrackingModes() {
	// URL re-writing is always enabled by default
	defaultSessionTrackingModes = EnumSet.of(SessionTrackingMode.URL);
	supportedSessionTrackingModes = EnumSet.of(SessionTrackingMode.URL);

	if (context.getCookies()) {
		defaultSessionTrackingModes.add(SessionTrackingMode.COOKIE);
		supportedSessionTrackingModes.add(SessionTrackingMode.COOKIE);
	}

	// SSL not enabled by default as it can only used on its own
	// Context > Host > Engine > Service
	Service s = ((Engine) context.getParent().getParent()).getService();
	Connector[] connectors = s.findConnectors();
	// Need at least one SSL enabled connector to use the SSL session ID.
	for (Connector connector : connectors) {
		if (Boolean.TRUE.equals(connector.getAttribute("SSLEnabled"))) {
			supportedSessionTrackingModes.add(SessionTrackingMode.SSL);
			break;
		}
	}
}
 
Example 25
Project: seldon-core   File: TomcatConfig.java   Source Code and License 6 votes vote down vote up
private Connector[] additionalConnector() {
  if (StringUtils.isBlank(this.additionalPorts)) {
    return null;
  }

  Set<String> defaultPorts = Sets.newHashSet(this.serverPort, this.managementPort);
  String[] ports = this.additionalPorts.split(",");
  List<Connector> result = new ArrayList<>();
  for (String port : ports) {
    if (!defaultPorts.contains(port)) {
      Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
      connector.setScheme("http");
      connector.setPort(Integer.valueOf(port));
      result.add(connector);
    }

  }

  return result.toArray(new Connector[] {});

}
 
Example 26
Project: lazycat   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 * Invoke a pre-startup initialization. This is used to allow connectors to
 * bind to restricted ports under Unix operating environments.
 */
@Override
protected void initInternal() throws LifecycleException {

	super.initInternal();

	if (container != null) {
		container.init();
	}

	// Initialize any Executors
	for (Executor executor : findExecutors()) {
		if (executor instanceof LifecycleMBeanBase) {
			((LifecycleMBeanBase) executor).setDomain(getDomain());
		}
		executor.init();
	}

	// Initialize our defined Connectors
	synchronized (connectorsLock) {
		for (Connector connector : connectors) {
			try {
				connector.init();
			} catch (Exception e) {
				String message = sm.getString("standardService.connector.initFailed", connector);
				log.error(message, e);

				if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"))
					throw new LifecycleException(message);
			}
		}
	}
}
 
Example 27
Project: cas-5.1.0   File: CasEmbeddedContainerTomcatConfiguration.java   Source Code and License 5 votes vote down vote up
private void configureAjp(final TomcatEmbeddedServletContainerFactory tomcat) {
    final CasServerProperties.Ajp ajp = casProperties.getServer().getAjp();
    if (ajp.isEnabled() && ajp.getPort() > 0) {
        LOGGER.debug("Creating AJP configuration for the embedded tomcat container...");
        final Connector ajpConnector = new Connector(ajp.getProtocol());
        ajpConnector.setProtocol(ajp.getProtocol());
        ajpConnector.setPort(ajp.getPort());
        ajpConnector.setSecure(ajp.isSecure());
        ajpConnector.setAllowTrace(ajp.isAllowTrace());
        ajpConnector.setScheme(ajp.getScheme());
        if (ajp.getAsyncTimeout() > 0) {
            ajpConnector.setAsyncTimeout(ajp.getAsyncTimeout());
        }
        ajpConnector.setEnableLookups(ajp.isEnableLookups());
        if (ajp.getMaxPostSize() > 0) {
            ajpConnector.setMaxPostSize(ajp.getMaxPostSize());
        }
        ajpConnector.addUpgradeProtocol(new Http2Protocol());

        if (ajp.getProxyPort() > 0) {
            LOGGER.debug("Set AJP proxy port to [{}]", ajp.getProxyPort());
            ajpConnector.setProxyPort(ajp.getProxyPort());
        }

        if (ajp.getRedirectPort() > 0) {
            LOGGER.debug("Set AJP redirect port to [{}]", ajp.getRedirectPort());
            ajpConnector.setRedirectPort(ajp.getRedirectPort());
        }

        ajp.getAttributes().forEach(ajpConnector::setAttribute);

        tomcat.addAdditionalTomcatConnectors(ajpConnector);
    }
}
 
Example 28
Project: tomcat7   File: Embedded.java   Source Code and License 5 votes vote down vote up
public Connector createConnector(String address, int port,
                                 boolean secure) {
    String protocol = "http";
    if (secure) {
        protocol = "https";
    }

    return createConnector(address, port, protocol);
}
 
Example 29
Project: tomcat7   File: ConnectorCreateRule.java   Source Code and License 5 votes vote down vote up
/**
 * Process the beginning of this element.
 *
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 * @param attributes The attribute list for this element
 */
@Override
public void begin(String namespace, String name, Attributes attributes)
        throws Exception {
    Service svc = (Service)digester.peek();
    Executor ex = null;
    if ( attributes.getValue("executor")!=null ) {
        ex = svc.getExecutor(attributes.getValue("executor"));
    }
    Connector con = new Connector(attributes.getValue("protocol"));
    if ( ex != null )  _setExecutor(con,ex);
    
    digester.push(con);
}
 
Example 30
Project: tomcat7   File: ConnectorCreateRule.java   Source Code and License 5 votes vote down vote up
public void _setExecutor(Connector con, Executor ex) throws Exception {
    Method m = IntrospectionUtils.findMethod(con.getProtocolHandler().getClass(),"setExecutor",new Class[] {java.util.concurrent.Executor.class});
    if (m!=null) {
        m.invoke(con.getProtocolHandler(), new Object[] {ex});
    }else {
        log.warn("Connector ["+con+"] does not support external executors. Method setExecutor(java.util.concurrent.Executor) not found.");
    }
}
 
Example 31
Project: tomcat7   File: MBeanFactory.java   Source Code and License 5 votes vote down vote up
/**
 * Remove an existing Connector.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeConnector(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Service service = getService(oname);
    String port = oname.getKeyProperty("port");
    //String address = oname.getKeyProperty("address");

    Connector conns[] = service.findConnectors();

    for (int i = 0; i < conns.length; i++) {
        String connAddress = String.valueOf(conns[i].getProperty("address"));
        String connPort = ""+conns[i].getPort();

        // if (((address.equals("null")) &&
        if ((connAddress==null) && port.equals(connPort)) {
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
        // } else if (address.equals(connAddress))
        if (port.equals(connPort)) {
            // Remove this component from its parent component
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
    }

}
 
Example 32
Project: tomcat7   File: MBeanUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Connector connector, Service service)
    throws Exception {

    // domain is engine name
    String domain = service.getContainer().getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, connector);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    // Unregister associated request processor
    String worker = null;
    ProtocolHandler handler = connector.getProtocolHandler();
    if (handler instanceof Http11Protocol) {
        worker = ((Http11Protocol)handler).getName();
    } else if (handler instanceof Http11NioProtocol) {
        worker = ((Http11NioProtocol)handler).getName();
    } else if (handler instanceof Http11AprProtocol) {
        worker = ((Http11AprProtocol)handler).getName();
    } else if (handler instanceof AjpProtocol) {
        worker = ((AjpProtocol)handler).getName();
    } else if (handler instanceof AjpAprProtocol) {
        worker = ((AjpAprProtocol)handler).getName();
    }
    ObjectName query = new ObjectName(
            domain + ":type=RequestProcessor,worker=" + worker + ",*");
    Set<ObjectName> results = mserver.queryNames(query, null);
    for(ObjectName result : results) {
        mserver.unregisterMBean(result);
    }
}
 
Example 33
Project: tomcat7   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 * Remove the specified Connector from the set associated from this
 * Service.  The removed Connector will also be disassociated from our
 * Container.
 *
 * @param connector The Connector to be removed
 */
@Override
public void removeConnector(Connector connector) {

    synchronized (connectorsLock) {
        int j = -1;
        for (int i = 0; i < connectors.length; i++) {
            if (connector == connectors[i]) {
                j = i;
                break;
            }
        }
        if (j < 0)
            return;
        if (connectors[j].getState().isAvailable()) {
            try {
                connectors[j].stop();
            } catch (LifecycleException e) {
                log.error(sm.getString(
                        "standardService.connector.stopFailed",
                        connectors[j]), e);
            }
        }
        connector.setService(null);
        int k = 0;
        Connector results[] = new Connector[connectors.length - 1];
        for (int i = 0; i < connectors.length; i++) {
            if (i != j)
                results[k++] = connectors[i];
        }
        connectors = results;

        // Report this property change to interested listeners
        support.firePropertyChange("connector", connector, null);
    }

}
 
Example 34
Project: tomcat7   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 * Start nested components ({@link Executor}s, {@link Connector}s and
 * {@link Container}s) and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {

    if(log.isInfoEnabled())
        log.info(sm.getString("standardService.start.name", this.name));
    setState(LifecycleState.STARTING);

    // Start our defined Container first
    if (container != null) {
        synchronized (container) {
            container.start();
        }
    }

    synchronized (executors) {
        for (Executor executor: executors) {
            executor.start();
        }
    }

    // Start our defined Connectors second
    synchronized (connectorsLock) {
        for (Connector connector: connectors) {
            try {
                // If it has already failed, don't try and start it
                if (connector.getState() != LifecycleState.FAILED) {
                    connector.start();
                }
            } catch (Exception e) {
                log.error(sm.getString(
                        "standardService.connector.startFailed",
                        connector), e);
            }
        }
    }
}
 
Example 35
Project: tomcat7   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 * Invoke a pre-startup initialization. This is used to allow connectors
 * to bind to restricted ports under Unix operating environments.
 */
@Override
protected void initInternal() throws LifecycleException {

    super.initInternal();
    
    if (container != null) {
        container.init();
    }

    // Initialize any Executors
    for (Executor executor : findExecutors()) {
        if (executor instanceof LifecycleMBeanBase) {
            ((LifecycleMBeanBase) executor).setDomain(getDomain());
        }
        executor.init();  // StandardThreadExecutor#initInternal
    }

    // Initialize our defined Connectors
    synchronized (connectorsLock) {
        for (Connector connector : connectors) {
            try {
                connector.init();
            } catch (Exception e) {
                String message = sm.getString(
                        "standardService.connector.initFailed", connector);
                log.error(message, e);

                if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"))
                    throw new LifecycleException(message);
            }
        }
    }
}
 
Example 36
Project: lazycat   File: ConnectorCreateRule.java   Source Code and License 5 votes vote down vote up
/**
 * Process the beginning of this element.
 *
 * @param namespace
 *            the namespace URI of the matching element, or an empty string
 *            if the parser is not namespace aware or the element has no
 *            namespace
 * @param name
 *            the local name if the parser is namespace aware, or just the
 *            element name otherwise
 * @param attributes
 *            The attribute list for this element
 */
@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {
	Service svc = (Service) digester.peek();
	Executor ex = null;
	if (attributes.getValue("executor") != null) {
		ex = svc.getExecutor(attributes.getValue("executor"));
	}
	Connector con = new Connector(attributes.getValue("protocol"));
	if (ex != null)
		_setExecutor(con, ex);

	digester.push(con);
}
 
Example 37
Project: dhus-core   File: TomcatServer.java   Source Code and License 5 votes vote down vote up
public int getAltPort()
{
   Connector[] connectors = cat.getServer().findServices()[0].findConnectors();
   if (connectors.length >= 2)
   {
      return connectors[1].getPort();
   }
   return connectors[0].getPort();
}
 
Example 38
Project: lazycat   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 * Start nested components ({@link Executor}s, {@link Connector}s and
 * {@link Container}s) and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException
 *                if this component detects a fatal error that prevents this
 *                component from being used
 */
@Override
protected void startInternal() throws LifecycleException {

	if (log.isInfoEnabled())
		log.info(sm.getString("standardService.start.name", this.name));
	setState(LifecycleState.STARTING);

	// Start our defined Container first
	if (container != null) {
		synchronized (container) {
			container.start();
		}
	}

	synchronized (executors) {
		for (Executor executor : executors) {
			executor.start();
		}
	}

	// Start our defined Connectors second
	synchronized (connectorsLock) {
		for (Connector connector : connectors) {
			try {
				// If it has already failed, don't try and start it
				if (connector.getState() != LifecycleState.FAILED) {
					connector.start();
				}
			} catch (Exception e) {
				log.error(sm.getString("standardService.connector.startFailed", connector), e);
			}
		}
	}
}
 
Example 39
Project: lazycat   File: MBeanUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Deregister the MBean for this <code>Connector</code> object.
 *
 * @param connector
 *            The Connector to be managed
 *
 * @exception Exception
 *                if an MBean cannot be deregistered
 * @deprecated Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Connector connector, Service service) throws Exception {

	// domain is engine name
	String domain = service.getContainer().getName();
	if (domain == null)
		domain = mserver.getDefaultDomain();
	ObjectName oname = createObjectName(domain, connector);
	if (mserver.isRegistered(oname)) {
		mserver.unregisterMBean(oname);
	}
	// Unregister associated request processor
	String worker = null;
	ProtocolHandler handler = connector.getProtocolHandler();
	if (handler instanceof Http11Protocol) {
		worker = ((Http11Protocol) handler).getName();
	} else if (handler instanceof Http11NioProtocol) {
		worker = ((Http11NioProtocol) handler).getName();
	} else if (handler instanceof Http11AprProtocol) {
		worker = ((Http11AprProtocol) handler).getName();
	} else if (handler instanceof AjpProtocol) {
		worker = ((AjpProtocol) handler).getName();
	} else if (handler instanceof AjpAprProtocol) {
		worker = ((AjpAprProtocol) handler).getName();
	}
	ObjectName query = new ObjectName(domain + ":type=RequestProcessor,worker=" + worker + ",*");
	Set<ObjectName> results = mserver.queryNames(query, null);
	for (ObjectName result : results) {
		mserver.unregisterMBean(result);
	}
}
 
Example 40
Project: lams   File: ConnectorCreateRule.java   Source Code and License 5 votes vote down vote up
/**
 * Process the beginning of this element.
 *
 * @param attributes The attribute list of this element
 */
public void begin(Attributes attributes) throws Exception {
    Service svc = (Service)digester.peek();
    Executor ex = null;
    if ( attributes.getValue("executor")!=null ) {
        ex = svc.getExecutor(attributes.getValue("executor"));
    }
    Connector con = new Connector(attributes.getValue("protocol"));
    if ( ex != null )  setExecutor(con,ex);
    
    digester.push(con);
}
 
Example 41
Project: lams   File: ServerLifecycleListener.java   Source Code and License 5 votes vote down vote up
/**
     * Create the MBeans for the specified Connector and its nested components.
     *
     * @param connector Connector for which to create MBeans
     *
     * @exception Exception if an exception is thrown during MBean creation
     */
    protected void createMBeans(Connector connector) throws Exception {

        // Create the MBean for the Connnector itself
//        if (log.isDebugEnabled())
//            log.debug("Creating MBean for Connector " + connector);
//        MBeanUtils.createMBean(connector);

    }
 
Example 42
Project: lams   File: ServerLifecycleListener.java   Source Code and License 5 votes vote down vote up
/**
     * Deregister the MBeans for the specified Connector and its nested
     * components.
     *
     * @param connector Connector for which to deregister MBeans
     *
     * @exception Exception if an exception is thrown during MBean destruction
     */
    protected void destroyMBeans(Connector connector, Service service)
        throws Exception {

//        // deregister the MBean for the Connector itself
//        if (log.isDebugEnabled())
//            log.debug("Destroying MBean for Connector " + connector);
//        MBeanUtils.destroyMBean(connector, service);

    }
 
Example 43
Project: lams   File: ServerLifecycleListener.java   Source Code and License 5 votes vote down vote up
/**
 * Process a property change event on a Service.
 *
 * @param service The service on which this event occurred
 * @param propertyName The name of the property that changed
 * @param oldValue The previous value (may be <code>null</code>)
 * @param newValue The new value (may be <code>null</code>)
 *
 * @exception Exception if an exception is thrown
 */
protected void processServicePropertyChange(Service service,
                                            String propertyName,
                                            Object oldValue,
                                            Object newValue)
    throws Exception {

    if (log.isTraceEnabled()) {
        log.trace("propertyChange[service=" + service +
            ",propertyName=" + propertyName +
            ",oldValue=" + oldValue +
            ",newValue=" + newValue + "]");
    }
    if ("connector".equals(propertyName)) {
        if (oldValue != null) {
            destroyMBeans((Connector) oldValue, service);
        }
        if (newValue != null) {
            createMBeans((Connector) newValue);
        }
    } else if ("container".equals(propertyName)) {
        if (oldValue != null) {
            destroyMBeans((Engine) oldValue);
        }
        if (newValue != null) {
            createMBeans((Engine) newValue);
        }
    }

}
 
Example 44
Project: lams   File: MBeanFactory.java   Source Code and License 5 votes vote down vote up
/**
 * Remove an existing Connector.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeConnector(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Server server = ServerFactory.getServer();
    Service service = getService(oname);
    String port = oname.getKeyProperty("port");
    //String address = oname.getKeyProperty("address");

    Connector conns[] = (Connector[]) service.findConnectors();

    for (int i = 0; i < conns.length; i++) {
        String connAddress = String.valueOf(conns[i].getProperty("address"));
        String connPort = ""+conns[i].getPort();

        // if (((address.equals("null")) &&
        if ((connAddress==null) && port.equals(connPort)) {
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
        // } else if (address.equals(connAddress))
        if (port.equals(connPort)) {
            // Remove this component from its parent component
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
    }

}
 
Example 45
Project: lams   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 * Remove the specified Connector from the set associated from this
 * Service.  The removed Connector will also be disassociated from our
 * Container.
 *
 * @param connector The Connector to be removed
 */
public void removeConnector(Connector connector) {

    synchronized (connectors) {
        int j = -1;
        for (int i = 0; i < connectors.length; i++) {
            if (connector == connectors[i]) {
                j = i;
                break;
            }
        }
        if (j < 0)
            return;
        if (started && (connectors[j] instanceof Lifecycle)) {
            try {
                ((Lifecycle) connectors[j]).stop();
            } catch (LifecycleException e) {
                log.error("Connector.stop", e);
            }
        }
        connectors[j].setContainer(null);
        connector.setService(null);
        int k = 0;
        Connector results[] = new Connector[connectors.length - 1];
        for (int i = 0; i < connectors.length; i++) {
            if (i != j)
                results[k++] = connectors[i];
        }
        connectors = results;

        // Report this property change to interested listeners
        support.firePropertyChange("connector", connector, null);
    }

}
 
Example 46
Project: lams   File: ClusterListener.java   Source Code and License 5 votes vote down vote up
/**
 * Return the address on which the connector is bound.
 * 
 * @param connector
 * @return
 */
protected String getAddress(Connector connector) {
    InetAddress inetAddress = 
        (InetAddress) IntrospectionUtils.getProperty(connector.getProtocolHandler(), "address");
    if (inetAddress == null) {
        // Should not happen
        return "127.0.0.1";
    } else {
        return inetAddress.getHostAddress();
    }
}
 
Example 47
Project: apache-tomcat-7.0.73-with-comment   File: Embedded.java   Source Code and License 5 votes vote down vote up
public Connector createConnector(String address, int port,
                                 boolean secure) {
    String protocol = "http";
    if (secure) {
        protocol = "https";
    }

    return createConnector(address, port, protocol);
}
 
Example 48
Project: apache-tomcat-7.0.73-with-comment   File: ConnectorCreateRule.java   Source Code and License 5 votes vote down vote up
/**
 * Process the beginning of this element.
 *
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 * @param attributes The attribute list for this element
 */
@Override
public void begin(String namespace, String name, Attributes attributes)
        throws Exception {
    Service svc = (Service)digester.peek();
    Executor ex = null;
    if ( attributes.getValue("executor")!=null ) {
        ex = svc.getExecutor(attributes.getValue("executor"));
    }
    //protocol 1. http 2. ajp
    Connector con = new Connector(attributes.getValue("protocol"));
    if ( ex != null )  _setExecutor(con,ex);
    
    digester.push(con);
}
 
Example 49
Project: apache-tomcat-7.0.73-with-comment   File: ConnectorCreateRule.java   Source Code and License 5 votes vote down vote up
public void _setExecutor(Connector con, Executor ex) throws Exception {
    Method m = IntrospectionUtils.findMethod(con.getProtocolHandler().getClass(),"setExecutor",new Class[] {java.util.concurrent.Executor.class});
    if (m!=null) {
        m.invoke(con.getProtocolHandler(), new Object[] {ex});
    }else {
        log.warn("Connector ["+con+"] does not support external executors. Method setExecutor(java.util.concurrent.Executor) not found.");
    }
}
 
Example 50
Project: apache-tomcat-7.0.73-with-comment   File: MBeanFactory.java   Source Code and License 5 votes vote down vote up
/**
 * Remove an existing Connector.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeConnector(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Service service = getService(oname);
    String port = oname.getKeyProperty("port");
    //String address = oname.getKeyProperty("address");

    Connector conns[] = service.findConnectors();

    for (int i = 0; i < conns.length; i++) {
        String connAddress = String.valueOf(conns[i].getProperty("address"));
        String connPort = ""+conns[i].getPort();

        // if (((address.equals("null")) &&
        if ((connAddress==null) && port.equals(connPort)) {
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
        // } else if (address.equals(connAddress))
        if (port.equals(connPort)) {
            // Remove this component from its parent component
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
    }

}
 
Example 51
Project: ait-platform   File: AitTomcatCustomizer.java   Source Code and License 5 votes vote down vote up
@Bean
public EmbeddedServletContainerFactory servletContainer() {

	TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
	if (tomcatAjpEnabled) {
		Connector ajpConnector = new Connector("AJP/1.3");
		ajpConnector.setPort(ajpPort);
		ajpConnector.setSecure(false);
		ajpConnector.setAllowTrace(false);
		ajpConnector.setScheme("http");
		tomcat.addAdditionalTomcatConnectors(ajpConnector);
	}

	return tomcat;
}
 
Example 52
Project: apache-tomcat-7.0.73-with-comment   File: ThreadLocalLeakPreventionListener.java   Source Code and License 5 votes vote down vote up
/**
 * Updates each ThreadPoolExecutor with the current time, which is the time
 * when a context is being stopped.
 * 
 * @param context
 *            the context being stopped, used to discover all the Connectors
 *            of its parent Service.
 */
private void stopIdleThreads(Context context) {
    if (serverStopping) return;

    if (!(context instanceof StandardContext) ||
        !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
        log.debug("Not renewing threads when the context is stopping. "
            + "It is not configured to do it.");
        return;
    }

    Engine engine = (Engine) context.getParent().getParent();
    Service service = engine.getService();
    Connector[] connectors = service.findConnectors();
    if (connectors != null) {
        for (Connector connector : connectors) {
            ProtocolHandler handler = connector.getProtocolHandler();
            Executor executor = null;
            if (handler != null) {
                executor = handler.getExecutor();
            }

            if (executor instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor threadPoolExecutor =
                    (ThreadPoolExecutor) executor;
                threadPoolExecutor.contextStopping();
            } else if (executor instanceof StandardThreadExecutor) {
                StandardThreadExecutor stdThreadExecutor =
                    (StandardThreadExecutor) executor;
                stdThreadExecutor.contextStopping();
            }

        }
    }
}
 
Example 53
Project: apache-tomcat-7.0.73-with-comment   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 * Remove the specified Connector from the set associated from this
 * Service.  The removed Connector will also be disassociated from our
 * Container.
 *
 * @param connector The Connector to be removed
 */
@Override
public void removeConnector(Connector connector) {

    synchronized (connectorsLock) {
        int j = -1;
        for (int i = 0; i < connectors.length; i++) {
            if (connector == connectors[i]) {
                j = i;
                break;
            }
        }
        if (j < 0)
            return;
        if (connectors[j].getState().isAvailable()) {
            try {
                connectors[j].stop();
            } catch (LifecycleException e) {
                log.error(sm.getString(
                        "standardService.connector.stopFailed",
                        connectors[j]), e);
            }
        }
        connector.setService(null);
        int k = 0;
        Connector results[] = new Connector[connectors.length - 1];
        for (int i = 0; i < connectors.length; i++) {
            if (i != j)
                results[k++] = connectors[i];
        }
        connectors = results;

        // Report this property change to interested listeners
        support.firePropertyChange("connector", connector, null);
    }

}
 
Example 54
Project: apache-tomcat-7.0.73-with-comment   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 *  启动()service容器的三个组件 container(engine) executor(默认没有) connector
 *  都比较重要
 * Start nested components ({@link Executor}s, {@link Connector}s and
 * {@link Container}s) and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {

    if(log.isInfoEnabled())
        log.info(sm.getString("standardService.start.name", this.name));//Catalina
    setState(LifecycleState.STARTING);

    // engine
    // Start our defined Container first
    if (container != null) {
        synchronized (container) {
            container.start();
        }
    }

    synchronized (executors) {
        for (Executor executor: executors) {
            executor.start();
        }
    }

    // Start our defined Connectors second
    synchronized (connectorsLock) {
        for (Connector connector: connectors) {
            try {
                // If it has already failed, don't try and start it
                if (connector.getState() != LifecycleState.FAILED) {
                    connector.start();
                }
            } catch (Exception e) {
                log.error(sm.getString(
                        "standardService.connector.startFailed",
                        connector), e);
            }
        }
    }
}
 
Example 55
Project: apache-tomcat-7.0.73-with-comment   File: StandardService.java   Source Code and License 5 votes vote down vote up
/**
 * Invoke a pre-startup initialization. This is used to allow connectors
 * to bind to restricted ports under Unix operating environments.
 */
@Override
protected void initInternal() throws LifecycleException {

    super.initInternal();
    
    if (container != null) {
     //初始化容器StandEngine
        container.init();
    }

    // Initialize any Executors
    for (Executor executor : findExecutors()) {
        if (executor instanceof LifecycleMBeanBase) {
            ((LifecycleMBeanBase) executor).setDomain(getDomain());
        }
        executor.init();
    }

    // 等到容器初始化的差不多的时候才去初始化连接器
    // Initialize our defined Connectors
    synchronized (connectorsLock) {
        for (Connector connector : connectors) {
            try {
            	//
                connector.init();
            } catch (Exception e) {
                String message = sm.getString(
                        "standardService.connector.initFailed", connector);
                log.error(message, e);

                if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"))
                    throw new LifecycleException(message);
            }
        }
    }
}
 
Example 56
Project: lazycat   File: Embedded.java   Source Code and License 5 votes vote down vote up
public Connector createConnector(String address, int port, boolean secure) {
	String protocol = "http";
	if (secure) {
		protocol = "https";
	}

	return createConnector(address, port, protocol);
}
 
Example 57
Project: xq_seckill_microservice   File: WebServerConfig.java   Source Code and License 5 votes vote down vote up
public void customize(Connector connector) {
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    //设置最大线程数
    protocol.setMaxThreads(1024);
    //设置最大连接数
    protocol.setMaxConnections(2048);
    //设置连接超时时间
    protocol.setConnectionTimeout(30000);
}
 
Example 58
Project: lazycat   File: ConnectorCreateRule.java   Source Code and License 5 votes vote down vote up
public void _setExecutor(Connector con, Executor ex) throws Exception {
	Method m = IntrospectionUtils.findMethod(con.getProtocolHandler().getClass(), "setExecutor",
			new Class[] { java.util.concurrent.Executor.class });
	if (m != null) {
		m.invoke(con.getProtocolHandler(), new Object[] { ex });
	} else {
		log.warn("Connector [" + con
				+ "] does not support external executors. Method setExecutor(java.util.concurrent.Executor) not found.");
	}
}
 
Example 59
Project: xq_seckill_microservice   File: WebServerConfig.java   Source Code and License 5 votes vote down vote up
public void customize(Connector connector) {
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    //设置最大线程数
    protocol.setMaxThreads(1024);
    //设置最大连接数
    protocol.setMaxConnections(2048);
    //设置连接超时时间
    protocol.setConnectionTimeout(30000);
}
 
Example 60
Project: xq_seckill_microservice   File: WebServerConfig.java   Source Code and License 5 votes vote down vote up
public void customize(Connector connector) {
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    //设置最大线程数
    protocol.setMaxThreads(1024);
    //设置最大连接数
    protocol.setMaxConnections(2048);
    //设置连接超时时间
    protocol.setConnectionTimeout(30000);
}