Java Code Examples for org.apache.catalina.core.StandardContext#getName()
The following examples show how to use
org.apache.catalina.core.StandardContext#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreContextAppender.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Make default Work Dir. * * @param context The context * @return The default working directory for the context. */ protected String getDefaultWorkDir(StandardContext context) { String defaultWorkDir = null; String contextWorkDir = context.getName(); if (contextWorkDir.length() == 0) contextWorkDir = "_"; if (contextWorkDir.startsWith("/")) contextWorkDir = contextWorkDir.substring(1); Container host = context.getParent(); if (host instanceof StandardHost) { String hostWorkDir = ((StandardHost) host).getWorkDir(); if (hostWorkDir != null) { defaultWorkDir = hostWorkDir + File.separator + contextWorkDir; } else { String engineName = context.getParent().getParent().getName(); String hostName = context.getParent().getName(); defaultWorkDir = "work" + File.separator + engineName + File.separator + hostName + File.separator + contextWorkDir; } } return defaultWorkDir; }
Example 2
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
private static boolean isExcludedBySystemProperty(final StandardContext standardContext) { String name = standardContext.getName(); if (name == null) { name = standardContext.getPath(); if (name == null) { // possible ? name = ""; } } if (name.startsWith("/")) { name = name.substring(1); } final SystemInstance systemInstance = SystemInstance.get(); return "true".equalsIgnoreCase(systemInstance.getProperty(name + ".tomcat-only", systemInstance.getProperty("tomcat-only", "false"))); }
Example 3
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
/** * Creates an openejb {@link AppModule} instance * from given tomcat context. * * @param standardContext tomcat context instance * @return a openejb application module */ private AppModule loadApplication(final StandardContext standardContext) { // don't use getId since the app id shouldnt get the host (jndi) // final TomcatDeploymentLoader tomcatDeploymentLoader = new TomcatDeploymentLoader(standardContext, getId(standardContext)); String id = standardContext.getName(); if (id.startsWith("/")) { id = id.substring(1); } final TomcatDeploymentLoader tomcatDeploymentLoader = new TomcatDeploymentLoader(standardContext, id); final AppModule appModule; try { appModule = tomcatDeploymentLoader.load(Contexts.warPath(standardContext), configuredClasspath(standardContext)); } catch (final OpenEJBException e) { throw new TomEERuntimeException(e); } // create the web module loadWebModule(appModule, standardContext); return appModule; }
Example 4
Source File: TomcatWebAppBuilder.java From tomee with Apache License 2.0 | 6 votes |
/** * Add new context info. * * @param host host name * @param standardContext context * @return context info */ public ContextInfo addContextInfo(final String host, final StandardContext standardContext) { String contextRoot = standardContext.getName(); if (!contextRoot.startsWith("/")) { contextRoot = "/" + contextRoot; } final String id = host + contextRoot; ContextInfo contextInfo; synchronized (infos) { contextInfo = infos.get(id); if (contextInfo == null) { contextInfo = new ContextInfo(); final String webappVersion = standardContext.getWebappVersion(); contextInfo.version = webappVersion != null && !webappVersion.isEmpty() ? "##" + webappVersion : webappVersion; contextInfo.standardContext = standardContext; infos.put(id, contextInfo); } } return contextInfo; }
Example 5
Source File: WebappLoader.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Stop associated {@link ClassLoader} and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected void stopInternal() throws LifecycleException { if (log.isDebugEnabled()) log.debug(sm.getString("webappLoader.stopping")); setState(LifecycleState.STOPPING); // Remove context attributes as appropriate if (container instanceof Context) { ServletContext servletContext = ((Context) container).getServletContext(); servletContext.removeAttribute(Globals.CLASS_PATH_ATTR); } // Throw away our current class loader if (classLoader != null) { ((Lifecycle) classLoader).stop(); DirContextURLStreamHandler.unbind(classLoader); } try { StandardContext ctx=(StandardContext)container; String contextName = ctx.getName(); if (!contextName.startsWith("/")) { contextName = "/" + contextName; } ObjectName cloname = new ObjectName (MBeanUtils.getDomain(ctx) + ":type=WebappClassLoader,context=" + contextName + ",host=" + ctx.getParent().getName()); Registry.getRegistry(null, null).unregisterComponent(cloname); } catch (Exception e) { log.error("LifecycleException ", e); } classLoader = null; }
Example 6
Source File: WebappLoader.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Stop associated {@link ClassLoader} and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected void stopInternal() throws LifecycleException { if (log.isDebugEnabled()) log.debug(sm.getString("webappLoader.stopping")); setState(LifecycleState.STOPPING); // Remove context attributes as appropriate if (container instanceof Context) { ServletContext servletContext = ((Context) container).getServletContext(); servletContext.removeAttribute(Globals.CLASS_PATH_ATTR); } // Throw away our current class loader if (classLoader != null) { ((Lifecycle) classLoader).stop(); DirContextURLStreamHandler.unbind(classLoader); } try { StandardContext ctx=(StandardContext)container; String contextName = ctx.getName(); if (!contextName.startsWith("/")) { contextName = "/" + contextName; } ObjectName cloname = new ObjectName (MBeanUtils.getDomain(ctx) + ":type=WebappClassLoader,context=" + contextName + ",host=" + ctx.getParent().getName()); Registry.getRegistry(null, null).unregisterComponent(cloname); } catch (Exception e) { log.error("LifecycleException ", e); } classLoader = null; }
Example 7
Source File: MBeanFactory.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * 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 * @param xmlValidation if XML descriptors should be validated * @param xmlNamespaceAware if the XML processor should namespace aware * @return the object name of the created context * * @exception Exception if an MBean cannot be created or registered */ public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation, boolean xmlNamespaceAware) 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); 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 = service.getContainer(); Host host = (Host) engine.findChild(pname.getKeyProperty("host")); host.addChild(context); } // Return the corresponding MBean name return context.getObjectName().toString(); }
Example 8
Source File: MBeanFactory.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * 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(); }
Example 9
Source File: MBeanFactory.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * 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(); }