Search in sources :

Example 1 with Host

use of org.apache.catalina.Host in project tomcat by apache.

the class StandardContextSF method store.

/**
     * Store a Context as Separate file as configFile value from context exists.
     * filename can be relative to catalina.base.
     *
     * @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter,
     *      int, java.lang.Object)
     */
@Override
public void store(PrintWriter aWriter, int indent, Object aContext) throws Exception {
    if (aContext instanceof StandardContext) {
        StoreDescription desc = getRegistry().findDescription(aContext.getClass());
        if (desc.isStoreSeparate()) {
            URL configFile = ((StandardContext) aContext).getConfigFile();
            if (configFile != null) {
                if (desc.isExternalAllowed()) {
                    if (desc.isBackup())
                        storeWithBackup((StandardContext) aContext);
                    else
                        storeContextSeparate(aWriter, indent, (StandardContext) aContext);
                    return;
                }
            } else if (desc.isExternalOnly()) {
                // Set a configFile so that the configuration is actually saved
                Context context = ((StandardContext) aContext);
                Host host = (Host) context.getParent();
                File configBase = host.getConfigBaseFile();
                ContextName cn = new ContextName(context.getName(), false);
                String baseName = cn.getBaseName();
                File xml = new File(configBase, baseName + ".xml");
                context.setConfigFile(xml.toURI().toURL());
                if (desc.isBackup())
                    storeWithBackup((StandardContext) aContext);
                else
                    storeContextSeparate(aWriter, indent, (StandardContext) aContext);
                return;
            }
        }
    }
    super.store(aWriter, indent, aContext);
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardContext(org.apache.catalina.core.StandardContext) Host(org.apache.catalina.Host) File(java.io.File) URL(java.net.URL) ContextName(org.apache.catalina.util.ContextName)

Example 2 with Host

use of org.apache.catalina.Host in project ofbiz-framework by apache.

the class CatalinaContainer method prepareHost.

private Host prepareHost(Tomcat tomcat, List<String> virtualHosts) {
    Host host;
    if (UtilValidate.isEmpty(virtualHosts)) {
        host = tomcat.getHost();
    } else {
        host = prepareVirtualHost(tomcat, virtualHosts);
    }
    host.setAppBase(System.getProperty("ofbiz.home") + "/framework/catalina/hosts");
    host.setDeployOnStartup(false);
    host.setBackgroundProcessorDelay(5);
    host.setAutoDeploy(false);
    ((StandardHost) host).setWorkDir(new File(System.getProperty(Globals.CATALINA_HOME_PROP), "work" + File.separator + host.getName()).getAbsolutePath());
    return host;
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) StandardHost(org.apache.catalina.core.StandardHost) File(java.io.File)

Example 3 with Host

use of org.apache.catalina.Host in project tomcat70 by apache.

the class MBeanFactory method getParentContainerFromParent.

/**
 * Get Parent ContainerBase to add its child component
 * from parent's ObjectName
 */
private ContainerBase getParentContainerFromParent(ObjectName pname) throws Exception {
    String type = pname.getKeyProperty("type");
    String j2eeType = pname.getKeyProperty("j2eeType");
    Service service = getService(pname);
    StandardEngine engine = (StandardEngine) service.getContainer();
    if ((j2eeType != null) && (j2eeType.equals("WebModule"))) {
        String name = pname.getKeyProperty("name");
        name = name.substring(2);
        int i = name.indexOf('/');
        String hostName = name.substring(0, i);
        String path = name.substring(i);
        Host host = (Host) engine.findChild(hostName);
        String pathStr = getPathStr(path);
        StandardContext context = (StandardContext) host.findChild(pathStr);
        return context;
    } else if (type != null) {
        if (type.equals("Engine")) {
            return engine;
        } else if (type.equals("Host")) {
            String hostName = pname.getKeyProperty("host");
            StandardHost host = (StandardHost) engine.findChild(hostName);
            return host;
        }
    }
    return null;
}
Also used : StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host)

Example 4 with Host

use of org.apache.catalina.Host in project tomcat70 by apache.

the class MBeanUtils method createObjectName.

/**
 * Create an <code>ObjectName</code> for this
 * <code>Loader</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param loader The Loader to be named
 *
 * @exception MalformedObjectNameException if a name cannot be created
 */
static ObjectName createObjectName(String domain, Loader loader) throws MalformedObjectNameException {
    ObjectName name = null;
    Container container = loader.getContainer();
    if (container instanceof Engine) {
        name = new ObjectName(domain + ":type=Loader");
    } else if (container instanceof Host) {
        name = new ObjectName(domain + ":type=Loader,host=" + container.getName());
    } else if (container instanceof Context) {
        Context context = ((Context) container);
        ContextName cn = new ContextName(context.getName(), false);
        Container host = context.getParent();
        name = new ObjectName(domain + ":type=Loader,context=" + cn.getDisplayName() + ",host=" + host.getName());
    }
    return (name);
}
Also used : Context(org.apache.catalina.Context) Container(org.apache.catalina.Container) Host(org.apache.catalina.Host) Engine(org.apache.catalina.Engine) ObjectName(javax.management.ObjectName) ContextName(org.apache.catalina.util.ContextName)

Example 5 with Host

use of org.apache.catalina.Host in project tomcat70 by apache.

the class MBeanUtils method createObjectName.

/**
 * Create an <code>ObjectName</code> for this
 * <code>Context</code> object.
 *
 * @param domain Domain in which this name is to be created
 * @param context The Context to be named
 *
 * @exception MalformedObjectNameException if a name cannot be created
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static ObjectName createObjectName(String domain, Context context) throws MalformedObjectNameException {
    ObjectName name = null;
    Host host = (Host) context.getParent();
    ContextName cn = new ContextName(context.getName(), false);
    name = new ObjectName(domain + ":j2eeType=WebModule,name=//" + host.getName() + cn.getDisplayName() + ",J2EEApplication=none,J2EEServer=none");
    return (name);
}
Also used : Host(org.apache.catalina.Host) ObjectName(javax.management.ObjectName) ContextName(org.apache.catalina.util.ContextName)

Aggregations

Host (org.apache.catalina.Host)124 Context (org.apache.catalina.Context)59 StandardHost (org.apache.catalina.core.StandardHost)57 Container (org.apache.catalina.Container)44 File (java.io.File)37 Engine (org.apache.catalina.Engine)37 StandardContext (org.apache.catalina.core.StandardContext)33 Test (org.junit.Test)24 ObjectName (javax.management.ObjectName)18 ContextName (org.apache.catalina.util.ContextName)16 IOException (java.io.IOException)14 StandardEngine (org.apache.catalina.core.StandardEngine)12 URL (java.net.URL)10 Server (org.apache.catalina.Server)9 Tomcat (org.apache.catalina.startup.Tomcat)9 LifecycleException (org.apache.catalina.LifecycleException)8 StandardService (org.apache.catalina.core.StandardService)8 ArrayList (java.util.ArrayList)7 InitialContext (javax.naming.InitialContext)7 Service (org.apache.catalina.Service)6