/** * Configure the web application(s). * * @param handlers * @throws Exception */ protected void addModulesToJetty(ContextHandlerCollection handlers) throws Exception { /* ************* * Manager API * ************* */ ServletContextHandler apiManServer = new ServletContextHandler(ServletContextHandler.SESSIONS); apiManServer.setSecurityHandler(createSecurityHandler()); apiManServer.setContextPath("/apiman"); apiManServer.addEventListener(new Listener()); apiManServer.addEventListener(new BeanManagerResourceBindingListener()); apiManServer.addEventListener(new ResteasyBootstrap()); apiManServer.addFilter( DatabaseSeedFilter.class, "/db-seeder", EnumSet.of(DispatcherType.REQUEST)); // apiManServer.addFilter(LocaleFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); apiManServer.addFilter(ApimanCorsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); apiManServer.addFilter(DisableCachingFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); apiManServer.addFilter(AuthenticationFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); apiManServer.addFilter( DefaultSecurityContextFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); apiManServer.addFilter( TransactionWatchdogFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); apiManServer.addFilter(RootResourceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletHolder resteasyServlet = new ServletHolder(new HttpServletDispatcher()); resteasyServlet.setInitParameter( "javax.ws.rs.Application", TestManagerApiApplication.class.getName()); apiManServer.addServlet(resteasyServlet, "/*"); apiManServer.setInitParameter( "resteasy.injector.factory", "org.jboss.resteasy.cdi.CdiInjectorFactory"); apiManServer.setInitParameter("resteasy.scan", "true"); apiManServer.setInitParameter("resteasy.servlet.mapping.prefix", ""); // Add the web contexts to jetty handlers.addHandler(apiManServer); /* ************* * Mock Gateway (to test publishing of Services from dt to rt) * ************* */ ServletContextHandler mockGatewayServer = new ServletContextHandler(ServletContextHandler.SESSIONS); mockGatewayServer.setSecurityHandler(createSecurityHandler()); mockGatewayServer.setContextPath("/mock-gateway"); ServletHolder mockGatewayServlet = new ServletHolder(new MockGatewayServlet()); mockGatewayServer.addServlet(mockGatewayServlet, "/*"); // Add the web contexts to jetty handlers.addHandler(mockGatewayServer); }
@Test public void testPortableJMX() throws Exception { Server server = new Server(); ServerConnector connector = new ServerConnector(server); server.addConnector(connector); ServletContextHandler context = new ServletContextHandler(server, "/"); WebSocketServerContainerInitializer.configureContext(context); String value = BayeuxServerImpl.ATTRIBUTE + "," + Oort.OORT_ATTRIBUTE + "," + Seti.SETI_ATTRIBUTE; context.setInitParameter(ServletContextHandler.MANAGED_ATTRIBUTES, value); // CometD servlet String cometdServletPath = "/cometd"; String cometdURLMapping = cometdServletPath + "/*"; ServletHolder cometdServletHolder = new ServletHolder(CometDServlet.class); cometdServletHolder.setInitParameter("timeout", "10000"); cometdServletHolder.setInitParameter("ws.cometdURLMapping", cometdURLMapping); cometdServletHolder.setInitOrder(1); context.addServlet(cometdServletHolder, cometdURLMapping); ServletHolder jmxServletHolder = new ServletHolder(CometDJMXExporter.class); jmxServletHolder.setInitOrder(2); context.addServlet(jmxServletHolder, "/jmx"); server.start(); MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); String domain = BayeuxServerImpl.class.getPackage().getName(); Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":*"), null); Assert.assertEquals(1, mbeanNames.size()); ObjectName objectName = mbeanNames.iterator().next(); @SuppressWarnings("unchecked") Set<String> channels = (Set<String>) mbeanServer.getAttribute(objectName, "channels"); Assert.assertTrue(channels.size() > 0); server.stop(); }
@Test public void testJMX() throws Exception { Server server = new Server(); ServerConnector connector = new ServerConnector(server); server.addConnector(connector); MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer); server.addBean(mbeanContainer); ServletContextHandler context = new ServletContextHandler(server, "/"); WebSocketServerContainerInitializer.configureContext(context); String value = BayeuxServerImpl.ATTRIBUTE + "," + Oort.OORT_ATTRIBUTE + "," + Seti.SETI_ATTRIBUTE; context.setInitParameter(ServletContextHandler.MANAGED_ATTRIBUTES, value); // CometD servlet String cometdServletPath = "/cometd"; String cometdURLMapping = cometdServletPath + "/*"; ServletHolder cometdServletHolder = new ServletHolder(CometDServlet.class); cometdServletHolder.setInitParameter("timeout", "10000"); cometdServletHolder.setInitParameter("ws.cometdURLMapping", cometdURLMapping); cometdServletHolder.setInitOrder(1); context.addServlet(cometdServletHolder, cometdURLMapping); ServletHolder oortServletHolder = new ServletHolder(OortStaticConfigServlet.class); oortServletHolder.setInitParameter( OortConfigServlet.OORT_URL_PARAM, "http://localhost" + cometdServletPath); oortServletHolder.setInitOrder(2); context.addServlet(oortServletHolder, "/oort"); ServletHolder setiServletHolder = new ServletHolder(SetiServlet.class); setiServletHolder.setInitOrder(3); context.addServlet(setiServletHolder, "/seti"); server.start(); String domain = BayeuxServerImpl.class.getPackage().getName(); Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":*"), null); Assert.assertEquals(1, mbeanNames.size()); ObjectName objectName = mbeanNames.iterator().next(); @SuppressWarnings("unchecked") Set<String> channels = (Set<String>) mbeanServer.getAttribute(objectName, "channels"); Assert.assertTrue(channels.size() > 0); domain = Oort.class.getPackage().getName(); mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":*,type=oort"), null); Assert.assertEquals(1, mbeanNames.size()); objectName = mbeanNames.iterator().next(); String channel = "/foo"; mbeanServer.invoke( objectName, "observeChannel", new Object[] {channel}, new String[] {String.class.getName()}); @SuppressWarnings("unchecked") Set<String> observedChannels = (Set<String>) mbeanServer.getAttribute(objectName, "observedChannels"); Assert.assertTrue(observedChannels.contains(channel)); domain = Seti.class.getPackage().getName(); mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":*,type=seti"), null); Assert.assertEquals(1, mbeanNames.size()); objectName = mbeanNames.iterator().next(); ObjectName oortObjectName = (ObjectName) mbeanServer.getAttribute(objectName, "oort"); Assert.assertEquals("oort", oortObjectName.getKeyProperty("type")); server.stop(); }