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

项目:jerrydog    文件:Embedded.java   
/**
 * Create, configure, and return a new TCP/IP socket connector
 * based on the specified properties.
 *
 * @param address InetAddress to listen to, or <code>null</code>
 *  to listen on all address on this server
 * @param port Port number to listen to
 * @param secure Should this port be SSL-enabled?
 */
public Connector createConnector(InetAddress address, int port,
                                 boolean secure) {

    if (debug >= 1)
        logger.log("Creating connector for address='" +
                   ((address == null) ? "ALL" : address.getHostAddress()) +
                   "' port='" + port + "' secure='" + secure + "'");

    String protocol = "http";
    if (secure) {
        protocol = "https";
    }

    return createConnector(address, port, protocol);

}
项目:jerrydog    文件: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 (debug >= 2)
        log("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);
    }

}
项目:jerrydog    文件:ServerLifecycleListener.java   
/**
 * Deregister the MBeans for the specified Service and its nested
 * components.
 *
 * @param service Service for which to destroy MBeans
 *
 * @exception Exception if an exception is thrown during MBean destruction
 */
protected void destroyMBeans(Service service) throws Exception {

    // Deregister the MBeans for the associated Engine
    Engine engine = (Engine) service.getContainer();
    if (engine != null) {
        destroyMBeans(engine);
    }

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

    // Deregister the MBean for the Service itself
    if (debug >= 2) {
        log("Destroying MBean for Service " + service);
    }
    MBeanUtils.destroyMBean(service);
    if (service instanceof StandardService) {
        ((StandardService) service).removePropertyChangeListener(this);
    }

}
项目:jerrydog    文件: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
 */
public static ModelMBean 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();
    ModelMBean mbean = managed.createMBean(connector);
    ObjectName oname = createObjectName(domain, connector);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:jerrydog    文件: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
 */
public 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);
    mserver.unregisterMBean(oname);

}
项目:HowTomcatWorks    文件:Embedded.java   
/**
 * Create, configure, and return a new TCP/IP socket connector
 * based on the specified properties.
 *
 * @param address InetAddress to listen to, or <code>null</code>
 *  to listen on all address on this server
 * @param port Port number to listen to
 * @param secure Should this port be SSL-enabled?
 */
public Connector createConnector(InetAddress address, int port,
                                 boolean secure) {

    if (debug >= 1)
        logger.log("Creating connector for address='" +
                   ((address == null) ? "ALL" : address.getHostAddress()) +
                   "' port='" + port + "' secure='" + secure + "'");

    String protocol = "http";
    if (secure) {
        protocol = "https";
    }

    return createConnector(address, port, protocol);

}
项目:HowTomcatWorks    文件: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 (debug >= 2)
        log("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);
    }

}
项目:HowTomcatWorks    文件:ServerLifecycleListener.java   
/**
 * Deregister the MBeans for the specified Service and its nested
 * components.
 *
 * @param service Service for which to destroy MBeans
 *
 * @exception Exception if an exception is thrown during MBean destruction
 */
protected void destroyMBeans(Service service) throws Exception {

    // Deregister the MBeans for the associated Engine
    Engine engine = (Engine) service.getContainer();
    if (engine != null) {
        destroyMBeans(engine);
    }

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

    // Deregister the MBean for the Service itself
    if (debug >= 2) {
        log("Destroying MBean for Service " + service);
    }
    MBeanUtils.destroyMBean(service);
    if (service instanceof StandardService) {
        ((StandardService) service).removePropertyChangeListener(this);
    }

}
项目:HowTomcatWorks    文件: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
 */
public static ModelMBean 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();
    ModelMBean mbean = managed.createMBean(connector);
    ObjectName oname = createObjectName(domain, connector);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:HowTomcatWorks    文件: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
 */
public 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);
    mserver.unregisterMBean(oname);

}
项目:jerrydog    文件: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 (debug >= 1) {
        logger.log("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"));

    // Configure this Connector as needed
    connector.setContainer(engines[engines.length - 1]);

    // Add this Connector to our set of defined Connectors
    Connector results[] = new Connector[connectors.length + 1];
    for (int i = 0; i < connectors.length; i++)
        results[i] = connectors[i];
    results[connectors.length] = connector;
    connectors = results;

    // Start this Connector if necessary
    if (started) {
        try {
            connector.initialize();
            if (connector instanceof Lifecycle) {
                ((Lifecycle) connector).start();
            }
        } catch (LifecycleException e) {
            logger.log("Connector.start", e);
        }
    }

}
项目:jerrydog    文件: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 (debug >= 5)
        log("Creating MBean for Connector " + connector);
    MBeanUtils.createMBean(connector);

}
项目:jerrydog    文件:ServerLifecycleListener.java   
/**
 * 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 (debug >= 5)
        log("Destroying MBean for Connector " + connector);
    MBeanUtils.destroyMBean(connector, service);

}
项目:jerrydog    文件:ServerLifecycleListener.java   
/**
 * 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 (debug >= 6) {
        log("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);
        }
    }

}
项目:jerrydog    文件:MBeanFactory.java   
/**
 * Remove an existing Connector.
 *
 * @param name MBean Name of the comonent to remove
 *
 * @param serviceName Service name of the connector 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();
    String serviceName = oname.getKeyProperty("service");
    Service service = server.findService(serviceName);
    String port = oname.getKeyProperty("port");
    String address = oname.getKeyProperty("address");

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

    for (int i = 0; i < conns.length; i++) {
        Class cls = conns[i].getClass();
        Method getAddrMeth = cls.getMethod("getAddress", null);
        Object addrObj = getAddrMeth.invoke(conns[i], null);
        String connAddress = null;
        if (addrObj != null) {
            connAddress = addrObj.toString();
        } 
        Method getPortMeth = cls.getMethod("getPort", null);
        Object portObj = getPortMeth.invoke(conns[i], null);
        String connPort = new String();
        if (portObj != null) {
            connPort = portObj.toString();
        }
        if (((address.equals("null")) && (connAddress==null)) && port.equals(connPort)) {
            service.removeConnector(conns[i]);
            break;
        } else if (address.equals(connAddress) && port.equals(connPort)) {
            // Remove this component from its parent component
            service.removeConnector(conns[i]);
            break;
        } 
    }

}
项目:jerrydog    文件: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
 */
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) {
                ;
            }
        }
        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);
    }

}
项目:HowTomcatWorks    文件:Bootstrap.java   
public static void main(String[] args) {
  Connector connector = new HttpConnector();
  Wrapper wrapper1 = new SimpleWrapper();
  wrapper1.setName("Primitive");
  wrapper1.setServletClass("PrimitiveServlet");
  Wrapper wrapper2 = new SimpleWrapper();
  wrapper2.setName("Modern");
  wrapper2.setServletClass("ModernServlet");

  Context context = new SimpleContext();
  context.addChild(wrapper1);
  context.addChild(wrapper2);

  Mapper mapper = new SimpleContextMapper();
  mapper.setProtocol("http");
  LifecycleListener listener = new SimpleContextLifecycleListener();
  ((Lifecycle) context).addLifecycleListener(listener);
  context.addMapper(mapper);
  Loader loader = new SimpleLoader();
  context.setLoader(loader);
  // context.addServletMapping(pattern, name);
  context.addServletMapping("/Primitive", "Primitive");
  context.addServletMapping("/Modern", "Modern");
  connector.setContainer(context);
  try {
    connector.initialize();
    ((Lifecycle) connector).start();
    ((Lifecycle) context).start();

    // make the application wait until we press a key.
    System.in.read();
    ((Lifecycle) context).stop();
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
项目:HowTomcatWorks    文件: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 (debug >= 1) {
        logger.log("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"));

    // Configure this Connector as needed
    connector.setContainer(engines[engines.length - 1]);

    // Add this Connector to our set of defined Connectors
    Connector results[] = new Connector[connectors.length + 1];
    for (int i = 0; i < connectors.length; i++)
        results[i] = connectors[i];
    results[connectors.length] = connector;
    connectors = results;

    // Start this Connector if necessary
    if (started) {
        try {
            connector.initialize();
            if (connector instanceof Lifecycle) {
                ((Lifecycle) connector).start();
            }
        } catch (LifecycleException e) {
            logger.log("Connector.start", e);
        }
    }

}
项目:HowTomcatWorks    文件: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 (debug >= 5)
        log("Creating MBean for Connector " + connector);
    MBeanUtils.createMBean(connector);

}
项目:HowTomcatWorks    文件:ServerLifecycleListener.java   
/**
 * 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 (debug >= 5)
        log("Destroying MBean for Connector " + connector);
    MBeanUtils.destroyMBean(connector, service);

}
项目:HowTomcatWorks    文件:ServerLifecycleListener.java   
/**
 * 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 (debug >= 6) {
        log("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);
        }
    }

}
项目:HowTomcatWorks    文件:MBeanFactory.java   
/**
 * Remove an existing Connector.
 *
 * @param name MBean Name of the comonent to remove
 *
 * @param serviceName Service name of the connector 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();
    String serviceName = oname.getKeyProperty("service");
    Service service = server.findService(serviceName);
    String port = oname.getKeyProperty("port");
    String address = oname.getKeyProperty("address");

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

    for (int i = 0; i < conns.length; i++) {
        Class cls = conns[i].getClass();
        Method getAddrMeth = cls.getMethod("getAddress", null);
        Object addrObj = getAddrMeth.invoke(conns[i], null);
        String connAddress = null;
        if (addrObj != null) {
            connAddress = addrObj.toString();
        } 
        Method getPortMeth = cls.getMethod("getPort", null);
        Object portObj = getPortMeth.invoke(conns[i], null);
        String connPort = new String();
        if (portObj != null) {
            connPort = portObj.toString();
        }
        if (((address.equals("null")) && (connAddress==null)) && port.equals(connPort)) {
            service.removeConnector(conns[i]);
            break;
        } else if (address.equals(connAddress) && port.equals(connPort)) {
            // Remove this component from its parent component
            service.removeConnector(conns[i]);
            break;
        } 
    }

}
项目:HowTomcatWorks    文件: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
 */
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) {
                ;
            }
        }
        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);
    }

}
项目:HowTomcatWorks    文件:Bootstrap.java   
public static void main(String[] args) {
  System.setProperty("catalina.base", System.getProperty("user.dir"));
  Connector connector = new HttpConnector();

  Context context = new StandardContext();
  // StandardContext's start method adds a default mapper
  context.setPath("/app1");
  context.setDocBase("app1");
  LifecycleListener listener = new ContextConfig();
  ((Lifecycle) context).addLifecycleListener(listener);

  Host host = new StandardHost();
  host.addChild(context);
  host.setName("localhost");
  host.setAppBase("webapps");

  Loader loader = new WebappLoader();
  context.setLoader(loader);
  connector.setContainer(host);
  try {
    connector.initialize();
    ((Lifecycle) connector).start();
    ((Lifecycle) host).start();
    Container[] c = context.findChildren();
    int length = c.length;
    for (int i=0; i<length; i++) {
      Container child = c[i];
      System.out.println(child.getName());
    }

    // make the application wait until we press a key.
    System.in.read();
    ((Lifecycle) host).stop();
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
项目:jerrydog    文件:Embedded.java   
/**
 * Remove the specified Connector from the set of defined Connectors.
 *
 * @param connector The Connector to be removed
 */
public synchronized void removeConnector(Connector connector) {

    if (debug >= 1) {
        logger.log("Removing connector (" + connector.getInfo() + ")");
    }

    // Is the specified Connector actually defined?
    int j = -1;
    for (int i = 0; i < connectors.length; i++) {
        if (connector == connectors[i]) {
            j = i;
            break;
        }
    }
    if (j < 0)
        return;

    // Stop this Connector if necessary
    if (connector instanceof Lifecycle) {
        if (debug >= 1)
            logger.log(" Stopping this Connector");
        try {
            ((Lifecycle) connector).stop();
        } catch (LifecycleException e) {
            logger.log("Connector.stop", e);
        }
    }

    // Remove this Connector from our set of defined Connectors
    if (debug >= 1)
        logger.log(" Removing this Connector");
    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;

}
项目:jerrydog    文件:MBeanFactory.java   
/**
 * Create a new AjpConnector
 *
 * @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
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createAjpConnector(String parent, String address, int port)
    throws Exception {

    Object retobj = null;

    try {

        // Create a new CoyoteConnector instance for AJP
        // use reflection to avoid j-t-c compile-time circular dependencies
        Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
        Constructor ct = cls.getConstructor(null);
        retobj = ct.newInstance(null);
        Class partypes1 [] = new Class[1];
        // Set address
        String str = new String();
        partypes1[0] = str.getClass();
        Method meth1 = cls.getMethod("setAddress", partypes1);
        Object arglist1[] = new Object[1];
        arglist1[0] = address;
        meth1.invoke(retobj, arglist1);
        // Set port number
        Class partypes2 [] = new Class[1];
        partypes2[0] = Integer.TYPE;
        Method meth2 = cls.getMethod("setPort", partypes2);
        Object arglist2[] = new Object[1];
        arglist2[0] = new Integer(port);
        meth2.invoke(retobj, arglist2);
        // set protocolHandlerClassName for AJP
        Class partypes3 [] = new Class[1];
        partypes3[0] = str.getClass();
        Method meth3 = cls.getMethod("setProtocolHandlerClassName", partypes3);
        Object arglist3[] = new Object[1];
        arglist3[0] = new String("org.apache.jk.server.JkCoyoteHandler");
        meth3.invoke(retobj, arglist3);

    } catch (Exception e) {
        throw new MBeanException(e);
    }

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("name"));
    service.addConnector((Connector)retobj);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("CoyoteConnector");
    ObjectName oname =
        MBeanUtils.createObjectName(managed.getDomain(), (Connector)retobj);
    return (oname.toString());

}
项目:jerrydog    文件:MBeanFactory.java   
/**
 * Create a new HttpConnector
 *
 * @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
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createHttpConnector(String parent, String address, int port)
    throws Exception {

    Object retobj = null;

    try {

        // Create a new CoyoteConnector instance
        // use reflection to avoid j-t-c compile-time circular dependencies
        Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
        Constructor ct = cls.getConstructor(null);
        retobj = ct.newInstance(null);
        Class partypes1 [] = new Class[1];
        // Set address
        String str = new String();
        partypes1[0] = str.getClass();
        Method meth1 = cls.getMethod("setAddress", partypes1);
        Object arglist1[] = new Object[1];
        arglist1[0] = address;
        meth1.invoke(retobj, arglist1);
        // Set port number
        Class partypes2 [] = new Class[1];
        partypes2[0] = Integer.TYPE;
        Method meth2 = cls.getMethod("setPort", partypes2);
        Object arglist2[] = new Object[1];
        arglist2[0] = new Integer(port);
        meth2.invoke(retobj, arglist2);
    } catch (Exception e) {
        throw new MBeanException(e);
    }

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("name"));
    service.addConnector((Connector)retobj);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("CoyoteConnector");
    ObjectName oname =
        MBeanUtils.createObjectName(managed.getDomain(), (Connector)retobj);
    return (oname.toString());

}
项目:jerrydog    文件:StandardServer.java   
/**
 * Store the specified Connector properties.
 *
 * @param writer PrintWriter to which we are storing
 * @param indent Number of spaces to indent this element
 * @param connector Object whose properties are being stored
 *
 * @exception Exception if an exception occurs while storing
 */
private void storeConnector(PrintWriter writer, int indent,
                            Connector connector) throws Exception {

    // Store the beginning of this element
    for (int i = 0; i < indent; i++) {
        writer.print(' ');
    }
    writer.print("<Connector");
    storeAttributes(writer, connector);
    writer.println(">");

    // Store nested <Factory> element
    ServerSocketFactory factory = connector.getFactory();
    if (factory != null) {
        storeFactory(writer, indent + 2, factory);
    }

    // Store nested <Listener> elements
    if (connector instanceof Lifecycle) {
        LifecycleListener listeners[] =
            ((Lifecycle) connector).findLifecycleListeners();
        if (listeners == null) {
            listeners = new LifecycleListener[0];
        }
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i].getClass().getName().equals
                (SERVER_LISTENER_CLASS_NAME)) {
                continue;
            }
            storeListener(writer, indent + 2, listeners[i]);
        }
    }

    // Store the ending of this element
    for (int i = 0; i < indent; i++) {
        writer.print(' ');
    }
    writer.println("</Connector>");

}
项目:jerrydog    文件:StandardServer.java   
/**
 * Store the specified Service properties.
 *
 * @param writer PrintWriter to which we are storing
 * @param indent Number of spaces to indent this element
 * @param server Object to be stored
 *
 * @exception Exception if an exception occurs while storing
 */
private void storeService(PrintWriter writer, int indent,
                          Service service) throws Exception {

    // Store the beginning of this element
    for (int i = 0; i < indent; i++) {
        writer.print(' ');
    }
    writer.print("<Service");
    storeAttributes(writer, service);
    writer.println(">");

    // Store nested <Connector> elements
    Connector connectors[] = service.findConnectors();
    for (int i = 0; i < connectors.length; i++) {
        storeConnector(writer, indent + 2, connectors[i]);
    }

    // Store nested <Engine> element (or other appropriate container)
    Container container = service.getContainer();
    if (container != null) {
        if (container instanceof Context) {
            storeContext(writer, indent + 2, (Context) container);
        } else if (container instanceof Engine) {
            storeEngine(writer, indent + 2, (Engine) container);
        } else if (container instanceof Host) {
            storeHost(writer, indent + 2, (Host) container);
        }
    }

    // Store nested <Listener> elements
    if (service instanceof Lifecycle) {
        LifecycleListener listeners[] =
            ((Lifecycle) service).findLifecycleListeners();
        for (int i = 0; i < listeners.length; i++) {
            if (listeners[i].getClass().getName().equals
                (SERVER_LISTENER_CLASS_NAME)) {
                continue;
            }
            storeListener(writer, indent + 2, listeners[i]);
        }
    }

    // Store the ending of this element
    for (int i = 0; i < indent; i++) {
        writer.print(' ');
    }
    writer.println("</Service>");

}
项目:tip    文件:HttpRequest.java   
@Override
public Connector getConnector() {
    return connector;
}
项目:tip    文件:HttpRequest.java   
@Override
public void setConnector(Connector connector) {
    this.connector = connector;
}
项目:tip    文件:HttpResponse.java   
@Override
public Connector getConnector() {
    return connector;
}
项目:tip    文件:HttpResponse.java   
@Override
public void setConnector(Connector connector) {
    this.connector = connector;
}
项目:HowTomcatWorks    文件:Bootstrap.java   
public static void main(String[] args) {

    //invoke: http://localhost:8080/myApp/Session

    System.setProperty("catalina.base", System.getProperty("user.dir"));
    Connector connector = new HttpConnector();
    Wrapper wrapper1 = new SimpleWrapper();
    wrapper1.setName("Session");
    wrapper1.setServletClass("SessionServlet");

    Context context = new StandardContext();
    // StandardContext's start method adds a default mapper
    context.setPath("/myApp");
    context.setDocBase("myApp");

    context.addChild(wrapper1);

    // context.addServletMapping(pattern, name);
    // note that we must use /myApp/Session, not just /Session
    // because the /myApp section must be the same as the path, so the cookie will
    // be sent back.
    context.addServletMapping("/myApp/Session", "Session");
    // add ContextConfig. This listener is important because it configures
    // StandardContext (sets configured to true), otherwise StandardContext
    // won't start
    LifecycleListener listener = new SimpleContextConfig();
    ((Lifecycle) context).addLifecycleListener(listener);

    // here is our loader
    Loader loader = new WebappLoader();
    // associate the loader with the Context
    context.setLoader(loader);

    connector.setContainer(context);

    // add a Manager
    Manager manager = new StandardManager();
    context.setManager(manager);

    try {
      connector.initialize();
      ((Lifecycle) connector).start();

      ((Lifecycle) context).start();

      // make the application wait until we press a key.
      System.in.read();
      ((Lifecycle) context).stop();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
项目:HowTomcatWorks    文件:Bootstrap.java   
public static void main(String[] args) {
  Connector connector = new HttpConnector();
  Wrapper wrapper1 = new SimpleWrapper();
  wrapper1.setName("Primitive");
  wrapper1.setServletClass("PrimitiveServlet");
  Wrapper wrapper2 = new SimpleWrapper();
  wrapper2.setName("Modern");
  wrapper2.setServletClass("ModernServlet");
  Loader loader = new SimpleLoader();

  Context context = new SimpleContext();
  context.addChild(wrapper1);
  context.addChild(wrapper2);

  Mapper mapper = new SimpleContextMapper();
  mapper.setProtocol("http");
  LifecycleListener listener = new SimpleContextLifecycleListener();
  ((Lifecycle) context).addLifecycleListener(listener);
  context.addMapper(mapper);
  context.setLoader(loader);
  // context.addServletMapping(pattern, name);
  context.addServletMapping("/Primitive", "Primitive");
  context.addServletMapping("/Modern", "Modern");

  // ------ add logger --------
  System.setProperty("catalina.base", System.getProperty("user.dir"));
  FileLogger logger = new FileLogger();
  logger.setPrefix("FileLog_");
  logger.setSuffix(".txt");
  logger.setTimestamp(true);
  logger.setDirectory("webroot");
  context.setLogger(logger);

  //---------------------------

  connector.setContainer(context);
  try {
    connector.initialize();
    ((Lifecycle) connector).start();
    ((Lifecycle) context).start();

    // make the application wait until we press a key.
    System.in.read();
    ((Lifecycle) context).stop();
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
项目:HowTomcatWorks    文件:Bootstrap.java   
public static void main(String[] args) {

    //invoke: http://localhost:8080/Modern or  http://localhost:8080/Primitive

    System.setProperty("catalina.base", System.getProperty("user.dir"));
    Connector connector = new HttpConnector();
    Wrapper wrapper1 = new SimpleWrapper();
    wrapper1.setName("Primitive");
    wrapper1.setServletClass("PrimitiveServlet");
    Wrapper wrapper2 = new SimpleWrapper();
    wrapper2.setName("Modern");
    wrapper2.setServletClass("ModernServlet");

    Context context = new StandardContext();
    // StandardContext's start method adds a default mapper
    context.setPath("/myApp");
    context.setDocBase("myApp");

    context.addChild(wrapper1);
    context.addChild(wrapper2);

    // context.addServletMapping(pattern, name);
    context.addServletMapping("/Primitive", "Primitive");
    context.addServletMapping("/Modern", "Modern");
    // add ContextConfig. This listener is important because it configures
    // StandardContext (sets configured to true), otherwise StandardContext
    // won't start
    LifecycleListener listener = new SimpleContextConfig();
    ((Lifecycle) context).addLifecycleListener(listener);

    // here is our loader
    Loader loader = new WebappLoader();
    // associate the loader with the Context
    context.setLoader(loader);

    connector.setContainer(context);

    try {
      connector.initialize();
      ((Lifecycle) connector).start();
      ((Lifecycle) context).start();
      // now we want to know some details about WebappLoader
      WebappClassLoader classLoader = (WebappClassLoader) loader.getClassLoader();
      System.out.println("Resources' docBase: " + ((ProxyDirContext)classLoader.getResources()).getDocBase());
      String[] repositories = classLoader.findRepositories();
      for (int i=0; i<repositories.length; i++) {
        System.out.println("  repository: " + repositories[i]);
      }

      // make the application wait until we press a key.
      System.in.read();
      ((Lifecycle) context).stop();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
项目:HowTomcatWorks    文件:Bootstrap1.java   
public static void main(String[] args) {

  //invoke: http://localhost:8080/Modern or  http://localhost:8080/Primitive

    System.setProperty("catalina.base", System.getProperty("user.dir"));
    Connector connector = new HttpConnector();
    Wrapper wrapper1 = new SimpleWrapper();
    wrapper1.setName("Primitive");
    wrapper1.setServletClass("PrimitiveServlet");
    Wrapper wrapper2 = new SimpleWrapper();
    wrapper2.setName("Modern");
    wrapper2.setServletClass("ModernServlet");

    Context context = new StandardContext();
    // StandardContext's start method adds a default mapper
    context.setPath("/myApp");
    context.setDocBase("myApp");
    LifecycleListener listener = new SimpleContextConfig();
    ((Lifecycle) context).addLifecycleListener(listener);

    context.addChild(wrapper1);
    context.addChild(wrapper2);
    // for simplicity, we don't add a valve, but you can add
    // valves to context or wrapper just as you did in Chapter 6

    Loader loader = new WebappLoader();
    context.setLoader(loader);
    // context.addServletMapping(pattern, name);
    context.addServletMapping("/Primitive", "Primitive");
    context.addServletMapping("/Modern", "Modern");
    // add ContextConfig. This listener is important because it configures
    // StandardContext (sets configured to true), otherwise StandardContext
    // won't start

    // add constraint
    SecurityCollection securityCollection = new SecurityCollection();
    securityCollection.addPattern("/");
    securityCollection.addMethod("GET");

    SecurityConstraint constraint = new SecurityConstraint();
    constraint.addCollection(securityCollection);
    constraint.addAuthRole("manager");
    LoginConfig loginConfig = new LoginConfig();
    loginConfig.setRealmName("Simple Realm");
    // add realm
    Realm realm = new SimpleRealm();

    context.setRealm(realm);
    context.addConstraint(constraint);
    context.setLoginConfig(loginConfig);

    connector.setContainer(context);

    try {
      connector.initialize();
      ((Lifecycle) connector).start();
      ((Lifecycle) context).start();

      // make the application wait until we press a key.
      System.in.read();
      ((Lifecycle) context).stop();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
项目:HowTomcatWorks    文件:Bootstrap2.java   
public static void main(String[] args) {

  //invoke: http://localhost:8080/Modern or  http://localhost:8080/Primitive

    System.setProperty("catalina.base", System.getProperty("user.dir"));
    Connector connector = new HttpConnector();
    Wrapper wrapper1 = new SimpleWrapper();
    wrapper1.setName("Primitive");
    wrapper1.setServletClass("PrimitiveServlet");
    Wrapper wrapper2 = new SimpleWrapper();
    wrapper2.setName("Modern");
    wrapper2.setServletClass("ModernServlet");

    Context context = new StandardContext();
    // StandardContext's start method adds a default mapper
    context.setPath("/myApp");
    context.setDocBase("myApp");
    LifecycleListener listener = new SimpleContextConfig();
    ((Lifecycle) context).addLifecycleListener(listener);

    context.addChild(wrapper1);
    context.addChild(wrapper2);
    // for simplicity, we don't add a valve, but you can add
    // valves to context or wrapper just as you did in Chapter 6

    Loader loader = new WebappLoader();
    context.setLoader(loader);
    // context.addServletMapping(pattern, name);
    context.addServletMapping("/Primitive", "Primitive");
    context.addServletMapping("/Modern", "Modern");
    // add ContextConfig. This listener is important because it configures
    // StandardContext (sets configured to true), otherwise StandardContext
    // won't start

    // add constraint
    SecurityCollection securityCollection = new SecurityCollection();
    securityCollection.addPattern("/");
    securityCollection.addMethod("GET");

    SecurityConstraint constraint = new SecurityConstraint();
    constraint.addCollection(securityCollection);
    constraint.addAuthRole("manager");
    LoginConfig loginConfig = new LoginConfig();
    loginConfig.setRealmName("Simple User Database Realm");
    // add realm
    Realm realm = new SimpleUserDatabaseRealm();
    ((SimpleUserDatabaseRealm) realm).createDatabase("conf/tomcat-users.xml");
    context.setRealm(realm);
    context.addConstraint(constraint);
    context.setLoginConfig(loginConfig);

    connector.setContainer(context);

    try {
      connector.initialize();
      ((Lifecycle) connector).start();
      ((Lifecycle) context).start();

      // make the application wait until we press a key.
      System.in.read();
      ((Lifecycle) context).stop();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
项目:HowTomcatWorks    文件:Embedded.java   
/**
 * Remove the specified Connector from the set of defined Connectors.
 *
 * @param connector The Connector to be removed
 */
public synchronized void removeConnector(Connector connector) {

    if (debug >= 1) {
        logger.log("Removing connector (" + connector.getInfo() + ")");
    }

    // Is the specified Connector actually defined?
    int j = -1;
    for (int i = 0; i < connectors.length; i++) {
        if (connector == connectors[i]) {
            j = i;
            break;
        }
    }
    if (j < 0)
        return;

    // Stop this Connector if necessary
    if (connector instanceof Lifecycle) {
        if (debug >= 1)
            logger.log(" Stopping this Connector");
        try {
            ((Lifecycle) connector).stop();
        } catch (LifecycleException e) {
            logger.log("Connector.stop", e);
        }
    }

    // Remove this Connector from our set of defined Connectors
    if (debug >= 1)
        logger.log(" Removing this Connector");
    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;

}
项目:HowTomcatWorks    文件:MBeanFactory.java   
/**
 * Create a new AjpConnector
 *
 * @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
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createAjpConnector(String parent, String address, int port)
    throws Exception {

    Object retobj = null;

    try {

        // Create a new CoyoteConnector instance for AJP
        // use reflection to avoid j-t-c compile-time circular dependencies
        Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
        Constructor ct = cls.getConstructor(null);
        retobj = ct.newInstance(null);
        Class partypes1 [] = new Class[1];
        // Set address
        String str = new String();
        partypes1[0] = str.getClass();
        Method meth1 = cls.getMethod("setAddress", partypes1);
        Object arglist1[] = new Object[1];
        arglist1[0] = address;
        meth1.invoke(retobj, arglist1);
        // Set port number
        Class partypes2 [] = new Class[1];
        partypes2[0] = Integer.TYPE;
        Method meth2 = cls.getMethod("setPort", partypes2);
        Object arglist2[] = new Object[1];
        arglist2[0] = new Integer(port);
        meth2.invoke(retobj, arglist2);
        // set protocolHandlerClassName for AJP
        Class partypes3 [] = new Class[1];
        partypes3[0] = str.getClass();
        Method meth3 = cls.getMethod("setProtocolHandlerClassName", partypes3);
        Object arglist3[] = new Object[1];
        arglist3[0] = new String("org.apache.jk.server.JkCoyoteHandler");
        meth3.invoke(retobj, arglist3);

    } catch (Exception e) {
        throw new MBeanException(e);
    }

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("name"));
    service.addConnector((Connector)retobj);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("CoyoteConnector");
    ObjectName oname =
        MBeanUtils.createObjectName(managed.getDomain(), (Connector)retobj);
    return (oname.toString());

}