org.apache.catalina.core.StandardEngine Java Examples

The following examples show how to use org.apache.catalina.core.StandardEngine. 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: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Creates a new StandardService and StandardEngine.
 *
 * @param domain       Domain name for the container instance
 * @param defaultHost  Name of the default host to be used in the Engine
 * @param baseDir      Base directory value for Engine
 * @return the object name of the created service
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardServiceEngine(String domain,
        String defaultHost, String baseDir) throws Exception{

    if (!(container instanceof Server)) {
        throw new Exception("Container not Server");
    }

    StandardEngine engine = new StandardEngine();
    engine.setDomain(domain);
    engine.setName(domain);
    engine.setDefaultHost(defaultHost);

    Service service = new StandardService();
    service.setContainer(engine);
    service.setName(domain);

    ((Server) container).addService(service);

    return engine.getObjectName().toString();
}
 
Example #2
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new StandardService and StandardEngine.
 *
 * @param domain       Domain name for the container instance
 * @param defaultHost  Name of the default host to be used in the Engine
 * @param baseDir      Base directory value for Engine 
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardServiceEngine(String domain,
        String defaultHost, String baseDir) throws Exception{

    if (!(container instanceof Server)) {
        throw new Exception("Container not Server");
    }
    
    StandardEngine engine = new StandardEngine();
    engine.setDomain(domain);
    engine.setName(domain);
    engine.setDefaultHost(defaultHost);
    engine.setBaseDir(baseDir);

    Service service = new StandardService();
    service.setContainer(engine);
    service.setName(domain);
    
    ((Server) container).addService(service);
    
    return engine.getObjectName().toString();
}
 
Example #3
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new StandardService and StandardEngine.
 *
 * @param domain       Domain name for the container instance
 * @param defaultHost  Name of the default host to be used in the Engine
 * @param baseDir      Base directory value for Engine 
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardServiceEngine(String domain,
        String defaultHost, String baseDir) throws Exception{

    if (!(container instanceof Server)) {
        throw new Exception("Container not Server");
    }
    
    StandardEngine engine = new StandardEngine();
    engine.setDomain(domain);
    engine.setName(domain);
    engine.setDefaultHost(defaultHost);
    engine.setBaseDir(baseDir);

    Service service = new StandardService();
    service.setContainer(engine);
    service.setName(domain);
    
    ((Server) container).addService(service);
    
    return engine.getObjectName().toString();
}
 
Example #4
Source File: OpenEJBListener.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static File findOpenEjbWar() {
    // in Tomcat 5.5 the OpenEjb war is in the server/webapps director
    final String catalinaBase = System.getProperty("catalina.base");
    final File serverWebapps = new File(catalinaBase, "server/webapps");
    File openEjbWar = findOpenEjbWar(serverWebapps);
    if (openEjbWar != null) {
        return openEjbWar;
    }

    try {
        // in Tomcat 6 the OpenEjb war is normally in webapps, but we just
        // scan all hosts directories
        for (final Service service : TomcatHelper.getServer().findServices()) {
            final Container container = service.getContainer();
            if (container instanceof StandardEngine) {
                final StandardEngine engine = (StandardEngine) container;
                for (final Container child : engine.findChildren()) {
                    if (child instanceof StandardHost) {
                        final StandardHost host = (StandardHost) child;
                        final File hostDir = hostDir(catalinaBase, host.getAppBase());

                        openEjbWar = findOpenEjbWar(hostDir);
                        if (openEjbWar != null) {
                            return openEjbWar;
                        } else {
                            return findOpenEjbWar(host);
                        }
                    }
                }
            }
        }
    } catch (final Exception e) {
        LOGGER.log(Level.WARNING, "OpenEJBListener.findOpenEjbWar: {0}", e.getMessage());
    }

    return null;
}
 
Example #5
Source File: Tomcat.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Access to the engine, for further customization.
 * @return The engine
 */
public Engine getEngine() {
    Service service = getServer().findServices()[0];
    if (service.getContainer() != null) {
        return service.getContainer();
    }
    Engine engine = new StandardEngine();
    engine.setName( "Tomcat" );
    engine.setDefaultHost(hostname);
    engine.setRealm(createDefaultRealm());
    service.setContainer(engine);
    return engine;
}
 
Example #6
Source File: OpenEJBListener.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static File tryToFindAndExtractWar(final StandardServer source) {
    if (System.getProperties().containsKey("openejb.war")) {
        return new File(System.getProperty("openejb.war"));
    }

    for (final Service service : source.findServices()) {
        final Container container = service.getContainer();
        if (container instanceof StandardEngine) {
            final StandardEngine engine = (StandardEngine) container;
            for (final Container child : engine.findChildren()) {
                if (child instanceof StandardHost) {
                    final StandardHost host = (StandardHost) child;
                    final File base = hostDir(System.getProperty("catalina.base"), host.getAppBase());

                    final File[] files = base.listFiles();
                    if (files != null) {
                        for (final File file : files) {
                            if (isTomEEWar(file)) {
                                return file;
                            }
                        }
                    }
                }
            }
        }
    }

    return null;
}
 
Example #7
Source File: GlobalListenerSupport.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Engine is removed.
 *
 * @param engine tomcat engine
 */
private void engineRemoved(final StandardEngine engine) {
    for (final Container child : engine.findChildren()) {
        if (child instanceof StandardHost) {
            final StandardHost host = (StandardHost) child;
            hostRemoved(host);
        }
    }
}
 
Example #8
Source File: GlobalListenerSupport.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Engine is added.
 *
 * @param engine tomcat engine
 */
private void engineAdded(final StandardEngine engine) {
    addContextListener(engine);
    for (final Container child : engine.findChildren()) {
        if (child instanceof StandardHost) {
            final StandardHost host = (StandardHost) child;
            hostAdded(host);
        }
    }
}
 
Example #9
Source File: GlobalListenerSupport.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Service removed.
 *
 * @param service tomcat service
 */
private void serviceRemoved(final Service service) {
    final Container container = service.getContainer();
    if (container instanceof StandardEngine) {
        final StandardEngine engine = (StandardEngine) container;
        engineRemoved(engine);
    }
}
 
Example #10
Source File: GlobalListenerSupport.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Service is added.
 *
 * @param service tomcat service
 */
private void serviceAdded(final Service service) {
    final Container container = service.getContainer();
    if (container instanceof StandardEngine) {
        final StandardEngine engine = (StandardEngine) container;
        engineAdded(engine);
    }
}
 
Example #11
Source File: Contexts.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static File engineBase(final Context standardContext) {
    final String base = System.getProperty(Globals.CATALINA_BASE_PROP);
    if( base == null ) {
        final StandardEngine eng = (StandardEngine) standardContext.getParent().getParent();
        return eng.getCatalinaBase();
    }
    return new File(base);
}
 
Example #12
Source File: ContextConfig.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
protected String getBaseDir() {
    Container engineC=context.getParent().getParent();
    if( engineC instanceof StandardEngine ) {
        return ((StandardEngine)engineC).getBaseDir();
    }
    return System.getProperty(Globals.CATALINA_BASE_PROP);
}
 
Example #13
Source File: ClusterJmxHelper.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private static ObjectName getDefaultClusterName(SimpleTcpCluster cluster) throws Exception {
    String domain = getMBeanServer().getDefaultDomain();
    String type = ":type=";
    String clusterType= type+"Cluster";
    if (cluster.getContainer() instanceof StandardHost) {
        domain = ((StandardHost) cluster.getContainer()).getDomain();
        clusterType += ",host=" + cluster.getContainer().getName();
    } else {
        if (cluster.getContainer() instanceof StandardEngine) {
            domain = ((StandardEngine) cluster.getContainer()).getDomain();
        }
    }
    ObjectName clusterName = new ObjectName(domain + clusterType);
    return clusterName;
}
 
Example #14
Source File: ContextConfig.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
protected String getBaseDir() {
    Container engineC=context.getParent().getParent();
    if( engineC instanceof StandardEngine ) {
        return ((StandardEngine)engineC).getBaseDir();
    }
    return System.getProperty(Globals.CATALINA_BASE_PROP);
}
 
Example #15
Source File: ClusterJmxHelper.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private static ObjectName getDefaultClusterName(SimpleTcpCluster cluster) throws Exception {
    String domain = getMBeanServer().getDefaultDomain();
    String type = ":type=";
    String clusterType= type+"Cluster";
    if (cluster.getContainer() instanceof StandardHost) {
        domain = ((StandardHost) cluster.getContainer()).getDomain();
        clusterType += ",host=" + cluster.getContainer().getName();
    } else {
        if (cluster.getContainer() instanceof StandardEngine) {
            domain = ((StandardEngine) cluster.getContainer()).getDomain();
        }
    }
    ObjectName clusterName = new ObjectName(domain + clusterType);
    return clusterName;
}
 
Example #16
Source File: SFContextServlet.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private int determineTomcatHttpPort(ServletContext ctx) {

		try {
            Object o = FieldUtils.readField(ctx, "context", true);
            StandardContext sCtx = (StandardContext) FieldUtils.readField(o, "context", true);
            Container container = (Container) sCtx;

            Container c = container.getParent();
	        while (c != null && !(c instanceof StandardEngine)) {
	            c = c.getParent();
	        }

	        if (c != null) {
	            StandardEngine engine = (StandardEngine) c;
	            for (Connector connector : engine.getService().findConnectors()) {

                    if(connector.getProtocol().startsWith("HTTP")) {
	            		return connector.getPort();
	            	}

	            }
	        }

        } catch (Exception e) {
            logger.error("Could not determine http port", e);
        }

		return 0;

	}
 
Example #17
Source File: JvmRouteSessionIDBinderListener.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Callback from the cluster, when a message is received, The cluster will
 * broadcast it invoking the messageReceived on the receiver.
 * 
 * @param msg
 *            ClusterMessage - the message received from the cluster
 */
@Override
public void messageReceived(ClusterMessage msg) {
    if (msg instanceof SessionIDMessage) {
        SessionIDMessage sessionmsg = (SessionIDMessage) msg;
        if (log.isDebugEnabled())
            log.debug(sm.getString(
                    "jvmRoute.receiveMessage.sessionIDChanged", sessionmsg
                            .getOrignalSessionID(), sessionmsg
                            .getBackupSessionID(), sessionmsg
                            .getContextName()));
        Container container = getCluster().getContainer();
        Container host = null ;
        if(container instanceof Engine) {
            host = container.findChild(sessionmsg.getHost());
        } else {
            host = container ;
        }
        if (host != null) {
            Context context = (Context) host.findChild(sessionmsg
                    .getContextName());
            if (context != null) {
                try {
                    Session session = context.getManager().findSession(
                            sessionmsg.getOrignalSessionID());
                    if (session != null) {
                        session.setId(sessionmsg.getBackupSessionID());
                    } else if (log.isInfoEnabled())
                        log.info(sm.getString("jvmRoute.lostSession",
                                sessionmsg.getOrignalSessionID(),
                                sessionmsg.getContextName()));
                } catch (IOException e) {
                    log.error(e);
                }

            } else if (log.isErrorEnabled())
                log.error(sm.getString("jvmRoute.contextNotFound",
                        sessionmsg.getContextName(), ((StandardEngine) host
                                .getParent()).getJvmRoute()));
        } else if (log.isErrorEnabled())
            log.error(sm.getString("jvmRoute.hostNotFound", sessionmsg.getContextName()));
    }
    return;
}
 
Example #18
Source File: JvmRouteSessionIDBinderListener.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Callback from the cluster, when a message is received, The cluster will
 * broadcast it invoking the messageReceived on the receiver.
 * 
 * @param msg
 *            ClusterMessage - the message received from the cluster
 */
@Override
public void messageReceived(ClusterMessage msg) {
    if (msg instanceof SessionIDMessage) {
        SessionIDMessage sessionmsg = (SessionIDMessage) msg;
        if (log.isDebugEnabled())
            log.debug(sm.getString(
                    "jvmRoute.receiveMessage.sessionIDChanged", sessionmsg
                            .getOrignalSessionID(), sessionmsg
                            .getBackupSessionID(), sessionmsg
                            .getContextName()));
        Container container = getCluster().getContainer();
        Container host = null ;
        if(container instanceof Engine) {
            host = container.findChild(sessionmsg.getHost());
        } else {
            host = container ;
        }
        if (host != null) {
            Context context = (Context) host.findChild(sessionmsg
                    .getContextName());
            if (context != null) {
                try {
                    Session session = context.getManager().findSession(
                            sessionmsg.getOrignalSessionID());
                    if (session != null) {
                        session.setId(sessionmsg.getBackupSessionID());
                    } else if (log.isInfoEnabled())
                        log.info(sm.getString("jvmRoute.lostSession",
                                sessionmsg.getOrignalSessionID(),
                                sessionmsg.getContextName()));
                } catch (IOException e) {
                    log.error(e);
                }

            } else if (log.isErrorEnabled())
                log.error(sm.getString("jvmRoute.contextNotFound",
                        sessionmsg.getContextName(), ((StandardEngine) host
                                .getParent()).getJvmRoute()));
        } else if (log.isErrorEnabled())
            log.error(sm.getString("jvmRoute.hostNotFound", sessionmsg.getContextName()));
    }
    return;
}
 
Example #19
Source File: StandardEngineSF.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Store the specified Engine properties.
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aEngine
 *            Object whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aEngine,
        StoreDescription parentDesc) throws Exception {
    if (aEngine instanceof StandardEngine) {
        StandardEngine engine = (StandardEngine) aEngine;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = ((Lifecycle) engine)
                .findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);

        // Store nested <Realm> element
        Realm realm = engine.getRealm();
        Realm parentRealm = null;
        // TODO is this case possible? (see it a old Server 5.0 impl)
        if (engine.getParent() != null) {
            parentRealm = engine.getParent().getRealm();
        }
        if (realm != parentRealm) {
            storeElement(aWriter, indent, realm);

        }

        // Store nested <Valve> elements
        Valve valves[] = engine.getPipeline().getValves();
        if(valves != null && valves.length > 0 ) {
            List<Valve> engineValves = new ArrayList<>() ;
            for(int i = 0 ; i < valves.length ; i++ ) {
                if(!( valves[i] instanceof ClusterValve))
                    engineValves.add(valves[i]);
            }
            storeElementArray(aWriter, indent, engineValves.toArray());
        }

        // store all <Cluster> elements
        Cluster cluster = engine.getCluster();
        if (cluster != null) {
            storeElement(aWriter, indent, cluster);
        }
        // store all <Host> elements
        Container children[] = engine.findChildren();
        storeElementArray(aWriter, indent, children);

   }
}
 
Example #20
Source File: Embedded.java    From tomcatsrc with Apache License 2.0 3 votes vote down vote up
/**
 * Create, configure, and return an Engine that will process all
 * HTTP requests received from one of the associated Connectors,
 * based on the specified properties.
 */
public Engine createEngine() {

    if( log.isDebugEnabled() )
        log.debug("Creating engine");

    StandardEngine engine = new StandardEngine();

    // Default host will be set to the first host added
    engine.setRealm(realm);         // Inherited by all children

    return (engine);

}
 
Example #21
Source File: Embedded.java    From Tomcat7.0.67 with Apache License 2.0 3 votes vote down vote up
/**
 * Create, configure, and return an Engine that will process all
 * HTTP requests received from one of the associated Connectors,
 * based on the specified properties.
 */
public Engine createEngine() {

    if( log.isDebugEnabled() )
        log.debug("Creating engine");

    StandardEngine engine = new StandardEngine();

    // Default host will be set to the first host added
    engine.setRealm(realm);         // Inherited by all children

    return (engine);

}