Jsr160RequestDispatcher implements RequestDispatcher { public Object dispatchRequest(JmxRequest pJmxReq) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException, NotChangedException { JsonRequestHandler handler = requestHandlerManager.getRequestHandler(pJmxReq.getType()); JMXConnector connector = null; try { connector = createConnector(pJmxReq); connector.connect(); MBeanServerConnection connection = connector.getMBeanServerConnection(); if (handler.handleAllServersAtOnce(pJmxReq)) { MBeanServerExecutor manager = new MBeanServerExecutorRemote(connection); return handler.handleRequest(manager, pJmxReq); } else { return handler.handleRequest(connection, pJmxReq); } } finally { releaseConnector(connector); } } Jsr160RequestDispatcher(Converters pConverters,
                                   ServerHandle pServerInfo,
                                   Restrictor pRestrictor,
                                   Configuration pConfig); Object dispatchRequest(JmxRequest pJmxReq); boolean canHandle(JmxRequest pJmxRequest); boolean useReturnValueWithPath(JmxRequest pJmxRequest); static final String ALLOWED_TARGETS_SYSPROP; static final String ALLOWED_TARGETS_ENV; }
@Test(expectedExceptions = IllegalArgumentException.class) public void illegalDispatch() throws InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException, NotChangedException { dispatcher.dispatchRequest(JmxRequestFactory.createGetRequest("/read/java.lang:type=Memory/HeapMemoryUsage", procParams)); }
@Test(expectedExceptions = IOException.class) public void simpleDispatchFail() throws InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException, NotChangedException { JmxRequest req = preparePostReadRequest(null); getOriginalDispatcher().dispatchRequest(req); }
@Test public void simpleDispatch() throws InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException, NotChangedException { JmxReadRequest req = (JmxReadRequest) preparePostReadRequest(null); Map result = (Map) dispatcher.dispatchRequest(req); assertTrue(result.containsKey("HeapMemoryUsage")); }
@Test public void simpleDispatchForSingleAttribute() throws InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException, NotChangedException { JmxReadRequest req = preparePostReadRequest(null, "HeapMemoryUsage"); assertNotNull(dispatcher.dispatchRequest(req)); }
@Test public void simpleDispatchWithUser() throws InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException, NotChangedException { System.setProperty("TEST_WITH_USER","roland"); try { JmxRequest req = preparePostReadRequest("roland"); Map result = (Map) dispatcher.dispatchRequest(req); assertTrue(result.containsKey("HeapMemoryUsage")); } finally { System.clearProperty("TEST_WITH_USER"); } }
@Test public void defaultBlackList() throws Exception { String blackListedUrl = "service:jmx:rmi: JmxReadRequest req = preparePostReadRequestWithServiceUrl(blackListedUrl, null); try { dispatcher.dispatchRequest(req); fail("Exception should have been thrown for " + blackListedUrl); } catch (SecurityException exp) { assertTrue(exp.getMessage().contains(blackListedUrl)); } }