Example usage for javax.management ReflectionException ReflectionException

List of usage examples for javax.management ReflectionException ReflectionException

Introduction

In this page you can find the example usage for javax.management ReflectionException ReflectionException.

Prototype

public ReflectionException(java.lang.Exception e) 

Source Link

Document

Creates a ReflectionException that wraps the actual java.lang.Exception.

Usage

From source file:org.eclipse.smila.management.jmx.ClassHelper.java

/**
 * Search class.//from w  ww  .j  a v a  2 s.  c om
 * 
 * @param className
 *          the class name
 * 
 * @return the class
 * 
 * @throws ReflectionException
 *           the reflection exception
 */
public static Class searchClass(final String className) throws ReflectionException {
    final Class pClass = PRIMITIVES_MAP.get(className);
    if (pClass != null) {
        return pClass;
    }
    try {
        return Class.forName(className);
    } catch (final ClassNotFoundException e) {
        LOG.error(e);
        throw new ReflectionException(e);
    }
}

From source file:org.eclipse.smila.management.jmx.AgentMBean.java

/**
 * {@inheritDoc}//from ww  w  .  j ava  2 s  .  c  o m
 * 
 * @see javax.management.DynamicMBean#invoke(java.lang.String, java.lang.Object[], java.lang.String[])
 */
public Object invoke(final String actionName, final Object[] params, final String[] signature)
        throws MBeanException, ReflectionException {
    final Class[] classesSig = new Class[signature.length];
    for (int i = 0; i < signature.length; i++) {
        classesSig[i] = ClassHelper.searchClass(signature[i]);
    }
    Method method;
    try {
        method = _agent.getClass().getMethod(actionName, classesSig);
    } catch (final Exception e) {
        _log.error("", e);
        throw new ReflectionException(e);
    }
    final Object result;
    try {
        result = method.invoke(_agent, params);
    } catch (final Exception e) {
        _log.error("", e);
        throw new ReflectionException(e);
    }
    return processValue(result, method);
}

From source file:jef.tools.reflect.ClassEx.java

Object innerInvoke(Object obj, String method, boolean isStatic, Object... params) throws ReflectionException {
    try {/* w  ww.  j  av  a 2  s.  c o m*/
        if (obj == null && !isStatic)
            obj = newInstance();
        List<Class<?>> list = new ArrayList<Class<?>>();
        for (Object pobj : params) {
            list.add(pobj.getClass());
        }
        MethodEx me = BeanUtils.getCompatibleMethod(cls, method, list.toArray(new Class[list.size()]));
        if (me == null) {
            NoSuchMethodException e = new NoSuchMethodException("Method:[" + cls.getName() + "::" + method
                    + "] not found with param count:" + params.length);
            throw new ReflectionException(e);
        }
        if (!Modifier.isPublic(me.getModifiers()) || !Modifier.isPublic(cls.getModifiers())) {
            try {
                me.setAccessible(true);
            } catch (SecurityException e) {
                System.out.println(me.toString() + "\n" + e.getMessage());
            }
        }
        return me.invoke(obj, params);
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e);
    } catch (SecurityException e) {
        throw new ReflectionException(e);
    } catch (IllegalArgumentException e) {
        throw new ReflectionException(e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof Exception) {
            throw new ReflectionException((Exception) e.getCause());
        } else {
            throw new ReflectionException(e);
        }

    }
}

From source file:org.jolokia.http.HttpRequestHandlerTest.java

@Test
public void requestErrorHandling() throws MalformedObjectNameException, InstanceNotFoundException, IOException,
        ReflectionException, AttributeNotFoundException, MBeanException {
    Object[] exceptions = new Object[] { new ReflectionException(new NullPointerException()), 404, 500,
            new InstanceNotFoundException(), 404, 500, new MBeanException(new NullPointerException()), 500, 500,
            new AttributeNotFoundException(), 404, 500, new UnsupportedOperationException(), 500, 500,
            new IOException(), 500, 500, new IllegalArgumentException(), 400, 400, new SecurityException(), 403,
            403, new RuntimeMBeanException(new NullPointerException()), 500, 500 };

    for (int i = 0; i < exceptions.length; i += 3) {
        Exception e = (Exception) exceptions[i];
        reset(backend);//from   ww w  .ja  v a2  s .  co  m
        expect(backend.isDebug()).andReturn(true).anyTimes();
        backend.error(find("" + exceptions[i + 1]), EasyMock.<Throwable>anyObject());
        backend.error(find("" + exceptions[i + 2]), EasyMock.<Throwable>anyObject());
        expect(backend.handleRequest(EasyMock.<JmxRequest>anyObject())).andThrow(e);
        replay(backend);
        JSONObject resp = (JSONObject) handler.handleGetRequest("/jolokia",
                "/read/java.lang:type=Memory/HeapMemoryUsage", null);
        assertEquals(resp.get("status"), exceptions[i + 1]);

        resp = handler.handleThrowable(e);
        assertEquals(resp.get("status"), exceptions[i + 2], e.getClass().getName());
    }
}

From source file:org.hyperic.hq.plugin.jboss.JBossUtil.java

private static Object setAttribute(MBeanServerConnection mServer, ObjectName obj, String name, Object value)
        throws MetricUnreachableException, MetricNotFoundException, PluginException, ReflectionException,
        InstanceNotFoundException, MBeanException, IOException {

    if (name.startsWith("set")) {
        name = name.substring(3);//ww  w.  j a v a2s .c o  m
    }

    Attribute attr = new Attribute(name, value);

    try {
        mServer.setAttribute(obj, attr);
    } catch (AttributeNotFoundException e) {
        throw new MetricNotFoundException(e.getMessage(), e);
    } catch (InvalidAttributeValueException e) {
        throw new ReflectionException(e);
    }

    return null;
}

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (log.isDebugEnabled())
        log.debug("getAttribute " + name);
    Method getter = (Method) _getter.get(name);
    if (getter == null)
        throw new AttributeNotFoundException(name);
    try {//  w ww. ja v  a 2 s .  c  o  m
        Object o = _object;
        if (getter.getDeclaringClass().isInstance(this))
            o = this;
        return getter.invoke(o, (java.lang.Object[]) null);
    } catch (IllegalAccessException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new AttributeNotFoundException(e.toString());
    } catch (InvocationTargetException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new ReflectionException((Exception) e.getTargetException());
    }
}

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

public void setAttribute(Attribute attr)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    if (attr == null)
        return;//  w  w  w.  j a  v a  2s  .c om

    if (log.isDebugEnabled())
        log.debug("setAttribute " + attr.getName() + "=" + attr.getValue());
    Method setter = (Method) _setter.get(attr.getName());
    if (setter == null)
        throw new AttributeNotFoundException(attr.getName());
    try {
        Object o = _object;
        if (setter.getDeclaringClass().isInstance(this))
            o = this;
        setter.invoke(o, new Object[] { attr.getValue() });
    } catch (IllegalAccessException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new AttributeNotFoundException(e.toString());
    } catch (InvocationTargetException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new ReflectionException((Exception) e.getTargetException());
    }
}

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

public Object invoke(String name, Object[] params, String[] signature)
        throws MBeanException, ReflectionException {
    if (log.isDebugEnabled())
        log.debug("invoke " + name);

    String methodKey = name + "(";
    if (signature != null)
        for (int i = 0; i < signature.length; i++)
            methodKey += (i > 0 ? "," : "") + signature[i];
    methodKey += ")";

    try {/* w w w.  j  a  v a 2 s.c  o  m*/
        Method method = (Method) _method.get(methodKey);
        if (method == null)
            throw new NoSuchMethodException(methodKey);

        Object o = _object;
        if (method.getDeclaringClass().isInstance(this))
            o = this;
        return method.invoke(o, params);
    } catch (NoSuchMethodException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new ReflectionException(e);
    } catch (IllegalAccessException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new MBeanException(e);
    } catch (InvocationTargetException e) {
        log.warn(LogSupport.EXCEPTION, e);
        throw new ReflectionException((Exception) e.getTargetException());
    }

}

From source file:com.cyberway.issue.crawler.settings.ComplexType.java

public Object invoke(String arg0, Object[] arg1, String[] arg2) throws MBeanException, ReflectionException {
    throw new ReflectionException(new NoSuchMethodException("No methods to invoke."));
}