/** * 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(); }
/** * Process the START event for an associated Engine. * * @param event The lifecycle event that has occurred */ public void lifecycleEvent(LifecycleEvent event) { // Identify the engine we are associated with try { engine = (Engine) event.getLifecycle(); if (engine instanceof StandardEngine) { int engineDebug = ((StandardEngine) engine).getDebug(); if (engineDebug > this.debug) this.debug = engineDebug; } } catch (ClassCastException e) { log(sm.getString("engineConfig.cce", event.getLifecycle()), e); return; } // Process the event that has occurred if (event.getType().equals(Lifecycle.START_EVENT)) start(); else if (event.getType().equals(Lifecycle.STOP_EVENT)) stop(); }
/** * Create a new StandardEngine. * * @param parent MBean Name of the associated parent component * @param name Unique name of this Engine * @param defaultHost Default hostname of this Engine * * @exception Exception if an MBean cannot be created or registered */ public String createStandardEngine(String parent, String name, String defaultHost) throws Exception { // Create a new StandardEngine instance StandardEngine engine = new StandardEngine(); engine.setName(name); engine.setDefaultHost(defaultHost); // 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.setContainer(engine); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("StandardEngine"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), engine); return (oname.toString()); }
/** * 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); // engine.setService(service); return engine.getObjectName().toString(); }
public static int getPort(Host h) { int port = -1; StandardHost host = (StandardHost) h; CatalinaUtil.host = (StandardHost) h; StandardEngine se = (StandardEngine) host.getParent(); StandardService ss = (StandardService) se.getService(); Connector[] cs = ss.findConnectors(); for (Connector c : cs) { if (c.getProtocolHandlerClassName().contains("Http11Protocol")) port = c.getPort(); } return port; }
@Test(description = "Tests the construction of Application Server URL for a sample request") public void testConstructionOfApplicationServerURL() { Request request = new Request(); Connector connector = new Connector(); connector.setProtocol(TestConstants.SSL_PROTOCOL); connector.setPort(TestConstants.SSL_PORT); connector.setScheme(TestConstants.SSL_PROTOCOL); Engine engine = new StandardEngine(); Service service = new StandardService(); engine.setService(service); engine.getService().addConnector(connector); Host host = new StandardHost(); host.setName(TestConstants.DEFAULT_TOMCAT_HOST); request.getMappingData().host = host; host.setParent(engine); Optional<String> actual = SSOUtils.constructApplicationServerURL(request); if (actual.isPresent()) { Assert.assertEquals(actual.get(), TestConstants.DEFAULT_APPLICATION_SERVER_URL); } else { Assert.fail(); } }
@Test(description = "Tests the construction of Application Server URL for no SSL/TLS Connector") public void testConstructionOfApplicationServerURLWithNoConnector() { Request request = new Request(); Engine engine = new StandardEngine(); Service service = new StandardService(); engine.setService(service); Host host = new StandardHost(); host.setName(TestConstants.DEFAULT_TOMCAT_HOST); request.getMappingData().host = host; host.setParent(engine); Optional<String> actual = SSOUtils.constructApplicationServerURL(request); Assert.assertTrue(!actual.isPresent()); }
private void prepareCatalinaComponents() { engine = new StandardEngine(); host = new StandardHost(); fooContext = new StandardContext(); barContext = new StandardContext(); Connector connector = new Connector(); connector.setProtocol(TestConstants.SSL_PROTOCOL); connector.setPort(TestConstants.SSL_PORT); connector.setScheme(TestConstants.SSL_PROTOCOL); Service service = new StandardService(); engine.setService(service); engine.getService().addConnector(connector); host.setAppBase(TestConstants.WEB_APP_BASE); host.setName(TestConstants.DEFAULT_TOMCAT_HOST); host.setParent(engine); fooContext.setParent(host); fooContext.setDocBase(TestConstants.FOO_CONTEXT); barContext.setParent(host); barContext.setDocBase(TestConstants.BAR_CONTEXT); }
StandardEngine build() { StandardEngine engine = new StandardEngine(); engine.setName(name); engine.setDefaultHost(defaultHost); engine.setBaseDir(baseDir); engine.setBackgroundProcessorDelay(backgroundProcessorDelay); engine.setStartStopThreads(startStopThreads); engine.setJvmRoute(jvmRoute); for (HostConfiguration hostConfiguration : hosts) { Host host = hostConfiguration.build(); engine.addChild(host); } return engine; }
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; }
protected String getBaseDir() { Container engineC=context.getParent().getParent(); if( engineC instanceof StandardEngine ) { return ((StandardEngine)engineC).getBaseDir(); } return System.getProperty(Globals.CATALINA_BASE_PROP); }
protected String getBaseDir() { Container engineC=context.getParent().getParent(); if( engineC instanceof StandardEngine ) { return ((StandardEngine)engineC).getBaseDir(); } return System.getProperty("catalina.base"); }
/** * Create the MBeans for the specified Engine and its nested components. * * @param engine Engine for which to create MBeans * * @exception Exception if an exception is thrown during MBean creation */ protected void createMBeans(Engine engine) throws Exception { // Create the MBean for the Engine itself if (log.isDebugEnabled()) { log.debug("Creating MBean for Engine " + engine); } //MBeanUtils.createMBean(engine); engine.addContainerListener(this); if (engine instanceof StandardEngine) { ((StandardEngine) engine).addPropertyChangeListener(this); } // Create the MBeans for the associated nested components Realm eRealm = engine.getRealm(); if (eRealm != null) { if (log.isDebugEnabled()) log.debug("Creating MBean for Realm " + eRealm); //MBeanUtils.createMBean(eRealm); } // Create the MBeans for each child Host Container hosts[] = engine.findChildren(); for (int j = 0; j < hosts.length; j++) { createMBeans((Host) hosts[j]); } }
/** * Create a new StandardEngine. * * @param parent MBean Name of the associated parent component * @param engineName Unique name of this Engine * @param defaultHost Default hostname of this Engine * @param serviceName Unique name of this Service * * @exception Exception if an MBean cannot be created or registered */ public Vector createStandardEngineService(String parent, String engineName, String defaultHost, String serviceName) throws Exception { // Create a new StandardService instance StandardService service = new StandardService(); service.setName(serviceName); // Create a new StandardEngine instance StandardEngine engine = new StandardEngine(); engine.setName(engineName); engine.setDefaultHost(defaultHost); // Need to set engine before adding it to server in order to set domain service.setContainer(engine); // Add the new instance to its parent component Server server = ServerFactory.getServer(); server.addService(service); Vector onames = new Vector(); // FIXME service & engine.getObjectName //ObjectName oname = engine.getObjectName(); ObjectName oname = MBeanUtils.createObjectName(engineName, engine); onames.add(0, oname); //oname = service.getObjectName(); oname = MBeanUtils.createObjectName(engineName, service); onames.add(1, oname); return (onames); }
@Test public void test() throws Exception { StandardContext context = new StandardContext(); context.setName("foo"); WebappLoader loader = new WebappLoader() { @Override public ClassLoader getClassLoader() { return WebappLoader.class.getClassLoader(); } }; context.setLoader(loader); StandardHost host = new StandardHost(); StandardEngine engine = new StandardEngine(); engine.setService(new StandardService()); host.setParent(engine); context.setParent(host); loader.setContext(context); RedisSessionManager manager = new RedisSessionManager(); manager.setSessionIdGenerator(new StandardSessionIdGenerator()); manager.setContext(context); manager.initializeSerializer(); manager.initializeDatabaseConnection(); manager.clear(); StandardSession session = manager.createSession(null); session.setAttribute("foo", "test"); manager.afterRequest(); StandardSession loaded = manager.findSession(session.getId()); Assert.assertEquals(session.getAttribute("foo"), loaded.getAttribute("foo")); Assert.assertEquals(1, manager.getSize()); Assert.assertArrayEquals(new String[] { session.getId() }, manager.keys()); manager.processExpires(); }
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; }
/** * 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; }
protected String getBaseDir() { Container engineC = context.getParent().getParent(); if (engineC instanceof StandardEngine) { return ((StandardEngine) engineC).getBaseDir(); } return System.getProperty(Globals.CATALINA_BASE_PROP); }
private StandardContext getStandardContext(ServletContextEvent sce) throws MalformedObjectNameException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException { MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0); ObjectName name = new ObjectName("Catalina", "type", "Server"); Server server = (Server) mBeanServer.getAttribute(name, "managedResource"); StandardEngine engine = (StandardEngine) server.findService("Catalina").getContainer(); Container container = engine.findChild(engine.getDefaultHost()); StandardContext context = (StandardContext) container.findChild(sce.getServletContext().getContextPath()); return context; }
/** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { /* set up the manager */ this.manager.setContainer(new StandardContext()); this.manager.getContainer().setName("test"); this.manager.getContainer().setParent(new StandardEngine()); this.manager.getContainer().getParent().setName("parent"); /* create the store */ this.mongoStore = new MongoStore(); this.mongoStore.setHosts("127.0.0.1:27017"); this.mongoStore.setDbName("unitest"); this.mongoStore.setManager(manager); this.manager.setStore(mongoStore); /* initialize the store */ this.manager.start(); /* create the test session */ this.testSession = (StandardSession)this.manager.createSession(this.sessionId); /* add some data */ this.testSession.setAttribute("test", "test", false); }