Java 类org.apache.catalina.connector.Connector 实例源码

项目:danyuan-application    文件:App.java   
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;
}
项目:tomcat7    文件:Embedded.java   
/**
 * 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);
}
项目:tomcat7    文件:MBeanFactory.java   
/**
 * 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());
}
项目:tomcat7    文件:ApplicationContext.java   
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;
        }
    }
}
项目:lazycat    文件:CatalinaUtil.java   
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;
}
项目:tomcat7    文件:StandardService.java   
/**
 * 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);
    }

}
项目:tomcat7    文件:StandardService.java   
@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();
}
项目:lazycat    文件:MBeanFactory.java   
/**
 * 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());
}
项目:Equella    文件:TomcatServiceImpl.java   
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);
}
项目:lams    文件:Embedded.java   
/**
 * 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);
}
项目:lams    文件:ServerLifecycleListener.java   
/**
 * 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);
    }

}
项目:lazycat    文件:StandardService.java   
@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();
}
项目:lams    文件:MBeanUtils.java   
/**
 * 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);

}
项目:lams    文件:MBeanUtils.java   
/**
 * 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);
    }
}
项目:lams    文件:ClusterListener.java   
/**
 * 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];
}
项目:simple-hostel-management    文件:Utils.java   
/**
 * /!\ 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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:Embedded.java   
/**
 * 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);
}
项目:lazycat    文件:Embedded.java   
/**
 * 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);
}
项目:smarti    文件:TomcatConfiguration.java   
@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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:StandardService.java   
/**
 * 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);
    }

}
项目:lazycat    文件:StandardService.java   
/**
 * 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);
    }

}
项目:lazycat    文件:ApplicationContext.java   
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;
        }
    }
}
项目:Android_watch_magpie    文件:OAuth2SecurityConfiguration.java   
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);
    }
}
项目:seldon-core    文件:TomcatConfig.java   
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[] {});

}
项目:lazycat    文件:StandardService.java   
/**
 * 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);
            }
        }
    }
}
项目:cas-5.1.0    文件:CasEmbeddedContainerTomcatConfiguration.java   
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);
    }
}
项目:tomcat7    文件:Embedded.java   
public Connector createConnector(String address, int port,
                                 boolean secure) {
    String protocol = "http";
    if (secure) {
        protocol = "https";
    }

    return createConnector(address, port, protocol);
}
项目:tomcat7    文件:ConnectorCreateRule.java   
/**
 * 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);
}
项目:tomcat7    文件:ConnectorCreateRule.java   
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.");
    }
}
项目:tomcat7    文件:MBeanFactory.java   
/**
 * 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;
        }
    }

}
项目:tomcat7    文件:MBeanUtils.java   
/**
 * 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);
    }
}
项目:tomcat7    文件:StandardService.java   
/**
 * 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);
    }

}
项目:tomcat7    文件:StandardService.java   
/**
 * 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);
            }
        }
    }
}
项目:tomcat7    文件:StandardService.java   
/**
 * 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);
            }
        }
    }
}
项目:lazycat    文件:ConnectorCreateRule.java   
/**
 * 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);
}
项目:dhus-core    文件:TomcatServer.java   
public int getAltPort()
{
   Connector[] connectors = cat.getServer().findServices()[0].findConnectors();
   if (connectors.length >= 2)
   {
      return connectors[1].getPort();
   }
   return connectors[0].getPort();
}
项目:lazycat    文件:StandardService.java   
/**
 * 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);
            }
        }
    }
}
项目:lazycat    文件:MBeanUtils.java   
/**
 * 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);
    }
}
项目:lams    文件:ConnectorCreateRule.java   
/**
 * 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);
}
项目:lams    文件:ServerLifecycleListener.java   
/**
     * 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);

    }