@Test public void testRegisterMBean() throws Exception { HttpMBeanImpl httpMBean = new HttpMBeanImpl(new ServletServiceImpl(new ServletEventHandler()), new ProxyServiceImpl(null, null, null)); MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); mbeanServer.registerMBean(httpMBean, new ObjectName("org.apache.karaf:type=http,name=root")); TabularData data = httpMBean.getServlets(); }
@Override public TabularData getServlets() throws MBeanException { try { CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet", new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new String[]{"ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet"}, new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[]{"Bundle-ID", "Servlet Name", "State"}); TabularData table = new TabularDataSupport(tableType); List<ServletInfo> servletInfos = servletService.getServlets(); for (ServletInfo info : servletInfos) { CompositeData data = new CompositeDataSupport(servletType, new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new Object[]{info.getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls())}); table.put(data); } return table; } catch (Exception e) { throw new MBeanException(null, e.toString()); } }
HttpMBeanImpl extends StandardMBean implements HttpMBean { @Override public TabularData getServlets() throws MBeanException { try { CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet", new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new String[]{"ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet"}, new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[]{"Bundle-ID", "Servlet Name", "State"}); TabularData table = new TabularDataSupport(tableType); List<ServletInfo> servletInfos = servletService.getServlets(); for (ServletInfo info : servletInfos) { CompositeData data = new CompositeDataSupport(servletType, new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new Object[]{info.getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls())}); table.put(data); } return table; } catch (Exception e) { throw new MBeanException(null, e.toString()); } } }
HttpMBeanImpl extends StandardMBean implements HttpMBean { @Override public TabularData getServlets() throws MBeanException { try { CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet", new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new String[]{"ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet"}, new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[]{"Bundle-ID", "Servlet Name", "State"}); TabularData table = new TabularDataSupport(tableType); List<ServletInfo> servletInfos = servletService.getServlets(); for (ServletInfo info : servletInfos) { CompositeData data = new CompositeDataSupport(servletType, new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new Object[]{info.getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls())}); table.put(data); } return table; } catch (Exception e) { throw new MBeanException(null, e.toString()); } } HttpMBeanImpl(ServletService servletService, ProxyService proxyService); }
HttpMBeanImpl extends StandardMBean implements HttpMBean { @Override public TabularData getServlets() throws MBeanException { try { CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet", new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new String[]{"ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet"}, new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[]{"Bundle-ID", "Servlet Name", "State"}); TabularData table = new TabularDataSupport(tableType); List<ServletInfo> servletInfos = servletService.getServlets(); for (ServletInfo info : servletInfos) { CompositeData data = new CompositeDataSupport(servletType, new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new Object[]{info.getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls())}); table.put(data); } return table; } catch (Exception e) { throw new MBeanException(null, e.toString()); } } HttpMBeanImpl(ServletService servletService, ProxyService proxyService); @Override TabularData getServlets(); @Override Map<String, Proxy> getProxies(); @Override Collection<String> getProxyBalancingPolicies(); @Override void addProxy(String url, String proxyTo, String balancingPolicy); @Override void removeProxy(String url); }
HttpMBeanImpl extends StandardMBean implements HttpMBean { @Override public TabularData getServlets() throws MBeanException { try { CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet", new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new String[]{"ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet"}, new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING}); TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[]{"Bundle-ID", "Servlet Name", "State"}); TabularData table = new TabularDataSupport(tableType); List<ServletInfo> servletInfos = servletService.getServlets(); for (ServletInfo info : servletInfos) { CompositeData data = new CompositeDataSupport(servletType, new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"}, new Object[]{info.getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls())}); table.put(data); } return table; } catch (Exception e) { throw new MBeanException(null, e.toString()); } } HttpMBeanImpl(ServletService servletService, ProxyService proxyService); @Override TabularData getServlets(); @Override Map<String, Proxy> getProxies(); @Override Collection<String> getProxyBalancingPolicies(); @Override void addProxy(String url, String proxyTo, String balancingPolicy); @Override void removeProxy(String url);  }