Example usage for javax.management ReflectionException getTargetException

List of usage examples for javax.management ReflectionException getTargetException

Introduction

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

Prototype

public java.lang.Exception getTargetException() 

Source Link

Document

Returns the actual Exception thrown.

Usage

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

/**
 * Execute a single {@link JmxRequest}. If a checked  exception occurs,
 * this gets translated into the appropriate JSON object which will get returned.
 * Note, that these exceptions gets *not* translated into an HTTP error, since they are
 * supposed <em>Jolokia</em> specific errors above the transport layer.
 *
 * @param pJmxReq the request to execute
 * @return the JSON representation of the answer.
 *///from w  w w  . j a  v  a2  s  .c  o m
private JSONObject executeRequest(JmxRequest pJmxReq) {
    // Call handler and retrieve return value
    try {
        return backendManager.handleRequest(pJmxReq);
    } catch (ReflectionException e) {
        return getErrorJSON(404, e, pJmxReq);
    } catch (InstanceNotFoundException e) {
        return getErrorJSON(404, e, pJmxReq);
    } catch (MBeanException e) {
        return getErrorJSON(500, e.getTargetException(), pJmxReq);
    } catch (AttributeNotFoundException e) {
        return getErrorJSON(404, e, pJmxReq);
    } catch (UnsupportedOperationException e) {
        return getErrorJSON(500, e, pJmxReq);
    } catch (IOException e) {
        return getErrorJSON(500, e, pJmxReq);
    } catch (IllegalArgumentException e) {
        return getErrorJSON(400, e, pJmxReq);
    } catch (SecurityException e) {
        // Wipe out stacktrace
        return getErrorJSON(403, new Exception(e.getMessage()), pJmxReq);
    } catch (RuntimeMBeanException e) {
        // Use wrapped exception
        return errorForUnwrappedException(e, pJmxReq);
    }
}

From source file:org.mc4j.ems.impl.jmx.connection.bean.attribute.DAttribute.java

/**
 * Updates the local value of this mbean from the server
 * <p/>/*from w w  w.  j av a2  s . c o  m*/
 * TODO we should not update to null on failure, but retain the last known
 */
public synchronized Object refresh() {
    loaded = true;
    Object newValue = null;
    try {
        MBeanServer server = bean.getConnectionProvider().getMBeanServer();
        newValue = server.getAttribute(bean.getObjectName(), getName());

    } catch (ReflectionException e) {
        supportedType = false;
        registerFailure(e);
        throw new EmsException("Could not load attribute value " + e.toString(), e);
    } catch (InstanceNotFoundException e) {
        registerFailure(e);
        throw new EmsException(
                "Could not load attribute value, bean instance not found " + bean.getObjectName().toString(),
                e);
    } catch (MBeanException e) {
        registerFailure(e);
        Throwable t = e.getTargetException();
        if (t != null)
            throw new EmsException(
                    "Could not load attribute value, target bean threw exception " + t.getLocalizedMessage(),
                    t);
        else
            throw new EmsException("Could not load attribute value " + e.getLocalizedMessage(), e);
    } catch (AttributeNotFoundException e) {
        registerFailure(e);
        throw new EmsException("Could not load attribute value, attribute [" + getName() + "] not found", e);
    } catch (UndeclaredThrowableException e) {
        if (e.getUndeclaredThrowable() instanceof InvocationTargetException) {
            Throwable t = e.getCause();
            if (t.getCause() instanceof NotSerializableException) {
                supportedType = false;
                registerFailure(t.getCause());
                throw new EmsException("Could not load attribute value " + t.getLocalizedMessage(),
                        t.getCause());
            } else
                throw new EmsException("Could not load attribute value " + t.getLocalizedMessage(), t);
        }
        throw new EmsException("Could not load attribute value " + e.getLocalizedMessage(), e);
    } catch (RuntimeException re) {
        supportedType = false;

        // TODO GH: Figure this one out
        // Getting weblogic.management.NoAccessRuntimeException on wl9
        registerFailure(re);
        throw new EmsException("Could not load attribute value " + re.getLocalizedMessage(), re);
    } catch (NoClassDefFoundError ncdfe) {
        supportedType = false;
        registerFailure(ncdfe);
        throw new EmsException("Could not load attribute value " + ncdfe.getLocalizedMessage(), ncdfe);
    } catch (Throwable t) {
        throw new EmsException("Could not load attribute value " + t.getLocalizedMessage(), t);
    }
    alterValue(newValue);
    return newValue;
}