/** * Create a new Memory Realm. * * @param parent MBean Name of the associated parent component * * @exception Exception if an MBean cannot be created or registered */ public String createMemoryRealm(String parent) throws Exception { // Create a new MemoryRealm instance MemoryRealm realm = new MemoryRealm(); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); // Add the new instance to its parent component containerBase.setRealm(realm); // Return the corresponding MBean name ObjectName oname = realm.getObjectName(); if (oname != null) { return (oname.toString()); } else { return null; } }
/** * Create a new Memory Realm. * * @param parent * MBean Name of the associated parent component * * @exception Exception * if an MBean cannot be created or registered */ public String createMemoryRealm(String parent) throws Exception { // Create a new MemoryRealm instance MemoryRealm realm = new MemoryRealm(); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); // Add the new instance to its parent component containerBase.setRealm(realm); // Return the corresponding MBean name ObjectName oname = realm.getObjectName(); if (oname != null) { return (oname.toString()); } else { return null; } }
@Deployment(testable = false) public static Archive<?> app() { return ShrinkWrap.create(WebArchive.class, "mp.war") .addClasses(ConcurrencyServlet.class, User.class) .addAsManifestResource(new StringAsset( "<Context>" + " <Realm className=\"" + MemoryRealm.class.getName() + "\" pathname=\"" + new File("src/test/resources/managed/tomcat-users.xml").getAbsolutePath() + "\" />" + "</Context>"), "context.xml"); }
@Override public Embedded configure() throws Exception { final URL root = new URL(Tomcat6Configurator.class.getResource("/"), "../../../tomcat-core/target/test-classes"); final String cleanedRoot = URLDecoder.decode(root.getFile(), "UTF-8"); final String docBase = cleanedRoot + File.separator + appName; MemoryRealm memoryRealm = new MemoryRealm(); memoryRealm.setPathname(docBase + File.separator + "tomcat-users.xml"); final Embedded catalina = new Embedded(memoryRealm); if (!clientOnly) { P2PLifecycleListener listener = new P2PLifecycleListener(); listener.setConfigLocation(configLocation); catalina.addLifecycleListener(listener); } else { catalina.addLifecycleListener(new ClientServerLifecycleListener()); } final StandardServer server = new StandardServer(); server.addService(catalina); final Engine engine = catalina.createEngine(); engine.setName("engine-" + port); engine.setDefaultHost(DEFAULT_HOST); engine.setJvmRoute("tomcat-" + port); catalina.addEngine(engine); engine.setService(catalina); final Host host = catalina.createHost(DEFAULT_HOST, docBase); engine.addChild(host); final Context context = createContext(catalina, "/", docBase); host.addChild(context); this.manager = new HazelcastSessionManager(); context.setManager((HazelcastSessionManager) manager); updateManager((HazelcastSessionManager) manager); context.setBackgroundProcessorDelay(1); context.setCookies(true); final Connector connector = catalina.createConnector("localhost", port, false); connector.setProperty("bindOnInit", "false"); catalina.addConnector(connector); return catalina; }