Java 类org.apache.catalina.startup.ContextConfig 实例源码

项目:jerrydog    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, String path,
                                    String docBase)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();    
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(pname.getKeyProperty("host"));

    // Add context to the host
    host.addChild(context);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("StandardContext");

    ObjectName oname =
        MBeanUtils.createObjectName(managed.getDomain(), context);
    return (oname.toString());

}
项目:onetwo    文件:JFishTomcat.java   
public Context addWebapp(Host host, String contextPath, String docBase, ContextConfig config) {
if(hack()){
       if (host instanceof StandardHost) {
           ((StandardHost) host).setContextClass(contextClass.getName());
       }
}
Context ctx = super.addWebapp(host, contextPath, docBase, config);
return ctx;

  }
项目:nano-framework    文件:TomcatCustomServer.java   
protected void init(final String contextRoot, final String resourceBase) throws ServletException, IOException {
    final Path basePath = Files.createTempDirectory(DEFAULT_TOMCAT_BASE_TEMP_DIR);
    setBaseDir(basePath.toString());

    if (StringUtils.isNotEmpty(resourceBase)) {
        this.resourceBase = resourceBase;
    }

    initExecutor();
    initConnector();

    final ContextConfig conf = new ContextConfig();
    final StandardContext ctx = (StandardContext) this.addWebapp(getHost(), contextRoot, new File(this.resourceBase).getAbsolutePath(), conf);
    createGlobalXml();
    conf.setDefaultWebXml(globalWebXml.getAbsolutePath());

    for (LifecycleListener listen : ctx.findLifecycleListeners()) {
        if (listen instanceof DefaultWebXmlListener) {
            ctx.removeLifecycleListener(listen);
        }
    }

    ctx.setParentClassLoader(TomcatCustomServer.class.getClassLoader());

    //Disable TLD scanning by default
    if (System.getProperty(Constants.SKIP_JARS_PROPERTY) == null && System.getProperty(Constants.SKIP_JARS_PROPERTY) == null) {
        LOGGER.debug("disabling TLD scanning");
        StandardJarScanFilter jarScanFilter = (StandardJarScanFilter) ctx.getJarScanner().getJarScanFilter();
        jarScanFilter.setTldSkip("*");
    }
}
项目:spring-osgi    文件:TomcatWarDeployer.java   
private Context createDefaultContext(String contextPath, String docBase) {
    StandardContext context = new StandardContext();

    context.setDocBase(docBase);
    context.setPath(contextPath);

    ContextConfig config = new ContextConfig();
    context.addLifecycleListener(config);
    return context;
}
项目:HowTomcatWorks    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, String path,
                                    String docBase)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();    
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(pname.getKeyProperty("host"));

    // Add context to the host
    host.addChild(context);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("StandardContext");

    ObjectName oname =
        MBeanUtils.createObjectName(managed.getDomain(), context);
    return (oname.toString());

}
项目: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();
  }
}
项目:tomcat7    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);

    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName+".xml");
        if (configFile.isFile()) {
            context.setConfigFile(configFile.toURI().toURL());
        }
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
项目:lams    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);

    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextPath = context.getPath();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextPath},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = getConfigFile(contextPath);
        File configFile = new File(new File(configPath), baseName+".xml");
        context.setConfigFile(configFile.getAbsolutePath());
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextPath},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    ObjectName oname = context.getJmxName();

    return (oname.toString());

}
项目:apache-tomcat-7.0.73-with-comment    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);

    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName+".xml");
        if (configFile.isFile()) {
            context.setConfigFile(configFile.toURI().toURL());
        }
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
项目:lazycat    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent
 *            MBean Name of the associated parent component
 * @param path
 *            The context path for this Context
 * @param docBase
 *            Document base directory (or WAR) for this Context
 *
 * @exception Exception
 *                if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation,
        boolean xmlNamespaceAware, boolean tldValidation, boolean tldNamespaceAware) throws Exception {

    Where.amI();
    // Create a new StandardContext instance
    StandardContext context = new StandardContext();

    path = getPathStr(path);
    context.setPath(path);

    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);

    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain() + ":type=Deployer,host=" + pname.getKeyProperty("host"));
    if (mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
        String configPath = (String) mserver.getAttribute(deployer, "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName + ".xml");
        if (configFile.isFile()) {
            context.setConfigFile(configFile.toURI().toURL());
        }
        mserver.invoke(deployer, "manageApp", new Object[] { context },
                new String[] { "org.apache.catalina.Context" });
        mserver.invoke(deployer, "removeServiced", new Object[] { contextName },
                new String[] { "java.lang.String" });
    } else {
        log.warn("Deployer not found for " + pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
项目:switchyard    文件:RESTEasyResourcePublisher.java   
/**
 * {@inheritDoc}
 */
public synchronized Endpoint publish(ServiceDomain domain, String context, List<Object> instances, Map<String, String> contextParams) throws Exception {
    Host host = ServerUtil.getDefaultHost().getHost();
    StandardContext serverContext = (StandardContext) host.findChild("/" + context);
    if (serverContext == null) {
        serverContext = new StandardContext();
        serverContext.setPath("/" + context);
        File docBase = new File(SERVER_TEMP_DIR, context);
        if (!docBase.exists()) {
            if (!docBase.mkdirs()) {
                throw ExtensionMessages.MESSAGES.unableToCreateTempDirectory(docBase.getPath());
            }
        }
        serverContext.setDocBase(docBase.getPath());
        serverContext.addLifecycleListener(new ContextConfig());

        final Loader loader = new WebCtxLoader(instances.get(0).getClass().getClassLoader());
        loader.setContainer(host);
        serverContext.setLoader(loader);
        serverContext.setInstanceManager(new LocalInstanceManager());

        Wrapper wrapper = serverContext.createWrapper();
        wrapper.setName(SERVLET_NAME);
        wrapper.setServletClass(SERVLET_CLASS);
        wrapper.setLoadOnStartup(1);
        serverContext.addChild(wrapper);
        serverContext.addServletMapping("/*", SERVLET_NAME);
        serverContext.addApplicationListener(LISTENER_CLASS);

        if (contextParams != null) {
            for (Map.Entry<String, String> cp : contextParams.entrySet()) {
                serverContext.addParameter(cp.getKey(), cp.getValue());
            }
        }

        host.addChild(serverContext);
        serverContext.create();
        serverContext.start();
        LOG.info("Published RESTEasy context " + serverContext.getPath());
    }
    while (serverContext.isStarting()) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException ie) {
            // Ignore
            if (LOG.isDebugEnabled()) {
                LOG.debug("Spent sometime to start context.");
            }
        }
    }
    if (serverContext.isStarted()) {
        Registry registry = (Registry)serverContext.getServletContext().getAttribute(Registry.class.getName());
        List<Class<?>> classes = new ArrayList<Class<?>>();
        // Add as singleton instance
        for (Object instance : instances) {
            registry.addSingletonResource(instance);
            classes.add(instance.getClass());
        }
        RESTEasyResource resource = new RESTEasyResource();
        resource.setClasses(classes);
        resource.setContext(serverContext);
        return resource;
    } else {
        throw ExtensionMessages.MESSAGES.unableToStartContext(context, new RuntimeException("Context not yet started"));
    }
}
项目:switchyard    文件:JBossWebEndpointPublisher.java   
/**
 * {@inheritDoc}
 */
public synchronized Endpoint publish(ServiceDomain domain, String context, InboundHandler handler) throws Exception {

    Host host = ServerUtil.getDefaultHost().getHost();
    StandardContext serverContext = (StandardContext) host.findChild("/" + context);
    if (serverContext == null) {
        serverContext = new StandardContext();
        serverContext.setPath("/" + context);
        File docBase = new File(SERVER_TEMP_DIR, context);
        if (!docBase.exists()) {
            if (!docBase.mkdirs()) {
                throw ExtensionMessages.MESSAGES.unableToCreateTempDirectory(docBase.getPath());
            }
        }
        serverContext.setDocBase(docBase.getPath());
        serverContext.addLifecycleListener(new ContextConfig());

        final Loader loader = new WebCtxLoader(Thread.currentThread().getContextClassLoader());
        loader.setContainer(host);
        serverContext.setLoader(loader);
        serverContext.setInstanceManager(new LocalInstanceManager());

        Wrapper wrapper = serverContext.createWrapper();
        wrapper.setName(SERVLET_NAME);
        wrapper.setServletClass(HttpGatewayServlet.class.getName());
        wrapper.setServlet(new HttpGatewayServlet());
        wrapper.setLoadOnStartup(1);
        serverContext.addChild(wrapper);
        serverContext.addServletMapping("/*", SERVLET_NAME);

        host.addChild(serverContext);
        serverContext.create();
        serverContext.start();
        HttpGatewayServlet instance = (HttpGatewayServlet) wrapper.getServlet();
        instance.setHandler(handler);
        LOG.info("Published HTTP context " + serverContext.getPath());
    } else {
        throw ExtensionMessages.MESSAGES.contextAlreadyExists(context);
    }
    return new JBossWebEndpoint(serverContext);
}
项目:switchyard    文件:RemoteEndpointListener.java   
@Override
public synchronized void start() throws Exception {
    // If the remote listener is already started, just return.
    if (_started) {
        return;
    }

    Host host = ServerUtil.getDefaultHost().getHost();
    _serverContext = (StandardContext) host.findChild("/" + _contextName);
    if (_serverContext == null) {
        _serverContext = new StandardContext();
        _serverContext.setPath("/" + _contextName);
        File docBase = new File(SERVER_TEMP_DIR, _contextName);
        if (!docBase.exists()) {
            if (!docBase.mkdirs()) {
                throw ExtensionMessages.MESSAGES.unableToCreateTempDirectory(docBase.getPath());
            }
        }
        _serverContext.setDocBase(docBase.getPath());
        _serverContext.addLifecycleListener(new ContextConfig());

        final Loader loader = new WebCtxLoader(Thread.currentThread().getContextClassLoader());
        loader.setContainer(host);
        _serverContext.setLoader(loader);
        _serverContext.setInstanceManager(new LocalInstanceManager());

        Wrapper wrapper = _serverContext.createWrapper();
        wrapper.setName(SERVLET_NAME);
        wrapper.setServletClass(SwitchYardRemotingServlet.class.getName());
        wrapper.setLoadOnStartup(1);
        _serverContext.addChild(wrapper);
        _serverContext.addServletMapping("/*", SERVLET_NAME);


        host.addChild(_serverContext);
        _serverContext.create();
        _serverContext.start();


        SwitchYardRemotingServlet remotingServlet = (SwitchYardRemotingServlet) wrapper.getServlet();
        remotingServlet.setEndpointPublisher(this);
        _log.info("Published Remote Service Endpoint " + _serverContext.getPath());

        _started = true;
    } else {
        throw ExtensionMessages.MESSAGES.contextAlreadyExists(_contextName);
    }
}
项目:class-guard    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);

    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName+".xml");
        if (configFile.isFile()) {
            context.setConfigFile(configFile.toURI().toURL());
        }
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
项目:apache-tomcat-7.0.57    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);

    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName+".xml");
        if (configFile.isFile()) {
            context.setConfigFile(configFile.toURI().toURL());
        }
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
项目:apache-tomcat-7.0.57    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);

    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName+".xml");
        if (configFile.isFile()) {
            context.setConfigFile(configFile.toURI().toURL());
        }
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
项目:WBSAirback    文件:MBeanFactory.java   
/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, 
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware,
                                    boolean tldValidation,
                                    boolean tldNamespaceAware)
    throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    context.setTldValidation(tldValidation);
    context.setTldNamespaceAware(tldNamespaceAware);

    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain()+
                                         ":type=Deployer,host="+
                                         pname.getKeyProperty("host"));
    if(mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        mserver.invoke(deployer, "addServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
        String configPath = (String)mserver.getAttribute(deployer,
                                                         "configBaseName");
        String baseName = context.getBaseName();
        File configFile = new File(new File(configPath), baseName+".xml");
        context.setConfigFile(configFile.toURI().toURL());
        mserver.invoke(deployer, "manageApp",
                       new Object[] {context},
                       new String[] {"org.apache.catalina.Context"});
        mserver.invoke(deployer, "removeServiced",
                       new Object [] {contextName},
                       new String [] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+pname.getKeyProperty("host"));
        Service service = getService(pname);
        Engine engine = (Engine) service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
项目:embed-apache-tomcat    文件:TomcatApplicationBuilderImpl.java   
@Override
public TomcatApplicationBuilder withDefaultConfig() {
    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);
    return this;
}