Example usage for javax.management MBeanException getTargetException

List of usage examples for javax.management MBeanException getTargetException

Introduction

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

Prototype

public Exception getTargetException() 

Source Link

Document

Return the actual Exception thrown.

Usage

From source file:MBeanTyper.java

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (MBeanTyper.DEBUG) {
        System.err.println("  ++ method=" + method.getName() + ",args=" + args);
    }/* ww w  .ja  va  2  s. c om*/
    try {
        if (method.getDeclaringClass() == Object.class) {
            String name = method.getName();
            if (name.equals("hashCode")) {
                return new Integer(this.hashCode());
            } else if (name.equals("toString")) {
                return this.toString();
            } else if (name.equals("equals")) {
                // FIXME: this needs to be reviewed - we should be
                // smarter about this ...
                return new Boolean(equals(args[0]));
            }
        } else if (isJMXAttribute(method) && (args == null || args.length <= 0)) {
            String name = method.getName().substring(3);
            return server.getAttribute(mbean, name);
        }

        String sig[] = (String[]) signatureCache.get(method);
        if (sig == null) {
            // get the method signature from the method argument directly
            // vs. the arguments passed, since there may be primitives that
            // are wrapped as objects in the arguments
            Class _args[] = method.getParameterTypes();
            if (_args != null && _args.length > 0) {
                sig = new String[_args.length];
                for (int c = 0; c < sig.length; c++) {
                    if (_args[c] != null) {
                        sig[c] = _args[c].getName();
                    }
                }
            } else {
                sig = new String[0];
            }
            signatureCache.put(method, sig);
        }
        return server.invoke(mbean, method.getName(), args, sig);
    } catch (Throwable t) {
        if (MBeanTyper.DEBUG) {
            t.printStackTrace();
        }
        if (t instanceof UndeclaredThrowableException) {
            UndeclaredThrowableException ut = (UndeclaredThrowableException) t;
            throw ut.getUndeclaredThrowable();
        } else if (t instanceof InvocationTargetException) {
            InvocationTargetException it = (InvocationTargetException) t;
            throw it.getTargetException();
        } else if (t instanceof MBeanException) {
            MBeanException me = (MBeanException) t;
            throw me.getTargetException();
        } else {
            throw t;
        }
    }
}

From source file:com.flexive.shared.mbeans.FxCacheProxy.java

private FxCacheException newMBeanException(MBeanException e) {
    return new FxCacheException(
            "Cache error invoking the managed bean: " + e.getMessage() + ", TargetException: "
                    + (e.getTargetException() == null ? "(unknown)" : e.getTargetException().getMessage()),
            e.getTargetException());//from  www  . j a va2 s  . c  om
}

From source file:com.flexive.shared.mbeans.FxCacheProxy.java

private FxBackingCache getBackingCache() {
    try {/*from   w  w  w .  j  ava 2 s .co m*/
        return (FxBackingCache) server.getAttribute(name, "FxCache");
    } catch (MBeanException e) {
        throw new RuntimeException(
                "Cache error invoking the managed bean: " + e.getMessage() + ", TargetException: "
                        + (e.getTargetException() == null ? "(unknown)" : e.getTargetException().getMessage()));
    } catch (AttributeNotFoundException e) {
        throw new RuntimeException("Attribute FxCache not found in managed cache bean: " + e.getMessage());
    } catch (InstanceNotFoundException e) {
        throw new RuntimeException("No FxCache instance found!");
    } catch (ReflectionException e) {
        throw new RuntimeException(
                "Could not invoke operation on FxCache (reflection error): " + e.getMessage());
    }
}

From source file:org.apache.catalina.mbeans.ServerLifecycleListener.java

/**
 * Primary entry point for startup and shutdown events.
 *
 * @param event The event that has occurred
 *///from  w  w  w . ja  va  2s. c om
public void lifecycleEvent(LifecycleEvent event) {

    Lifecycle lifecycle = event.getLifecycle();
    if (Lifecycle.START_EVENT.equals(event.getType())) {

        if (lifecycle instanceof Server) {

            // Loading additional MBean descriptors
            loadMBeanDescriptors();

            createMBeans();

            if (adaptor != null) {
                try {
                    MBeanUtils.createRMIAdaptor(adaptor, adaptorHost, adaptorPort);
                } catch (Exception e) {
                    log.error("createAdaptor: Exception", e);
                }
            }

        }

        // We are embedded.
        if (lifecycle instanceof Service) {
            try {
                MBeanFactory factory = new MBeanFactory();
                createMBeans(factory);
                loadMBeanDescriptors();
                createMBeans((Service) lifecycle);
            } catch (Exception ex) {
                log.error("Create mbean factory");
            }
        }

        /*
        // Ignore events from StandardContext objects to avoid
        // reregistering the context
        if (lifecycle instanceof StandardContext)
        return;
        createMBeans();
        */

    } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
        try {
            if (lifecycle instanceof Server) {
                destroyMBeans((Server) lifecycle);
            }
            if (lifecycle instanceof Service) {
                destroyMBeans((Service) lifecycle);
            }
        } catch (MBeanException t) {

            Exception e = t.getTargetException();
            if (e == null) {
                e = t;
            }
            log.error("destroyMBeans: MBeanException", e);

        } catch (Throwable t) {

            log.error("destroyMBeans: Throwable", t);

        }
        // FIXME: RMI adaptor should be stopped; however, this is
        // undocumented in MX4J, and reports exist in the MX4J bug DB that
        // this doesn't work

    }

    if ((Context.RELOAD_EVENT.equals(event.getType())) || (Lifecycle.START_EVENT.equals(event.getType()))) {

        // Give context a new handle to the MBean server if the
        // context has been reloaded since reloading causes the
        // context to lose its previous handle to the server
        if (lifecycle instanceof StandardContext) {
            // If the context is privileged, give a reference to it
            // in a servlet context attribute
            StandardContext context = (StandardContext) lifecycle;
            if (context.getPrivileged()) {
                context.getServletContext().setAttribute(Globals.MBEAN_REGISTRY_ATTR,
                        MBeanUtils.createRegistry());
                context.getServletContext().setAttribute(Globals.MBEAN_SERVER_ATTR, MBeanUtils.createServer());
            }
        }

    }

}

From source file:org.apache.catalina.mbeans.ServerLifecycleListener.java

/**
 * Create the MBeans that correspond to every existing node of our tree.
 *//*from www . j  a v  a 2 s.  c  o m*/
protected void createMBeans() {

    try {

        MBeanFactory factory = new MBeanFactory();
        createMBeans(factory);
        createMBeans(ServerFactory.getServer());

    } catch (MBeanException t) {

        Exception e = t.getTargetException();
        if (e == null)
            e = t;
        log.error("createMBeans: MBeanException", e);

    } catch (Throwable t) {

        log.error("createMBeans: Throwable", t);

    }

}

From source file:org.apache.catalina.mbeans.ServerLifecycleListener.java

/**
 * Process the addition of a new child Container to a parent Container.
 *
 * @param parent Parent container//from w  ww  .  j a  va2 s  . c  om
 * @param child Child container
 */
protected void processContainerAddChild(Container parent, Container child) {

    if (log.isDebugEnabled())
        log.debug("Process addChild[parent=" + parent + ",child=" + child + "]");

    try {
        if (child instanceof Context) {
            createMBeans((Context) child);
        } else if (child instanceof Engine) {
            createMBeans((Engine) child);
        } else if (child instanceof Host) {
            createMBeans((Host) child);
        }
    } catch (MBeanException t) {
        Exception e = t.getTargetException();
        if (e == null)
            e = t;
        log.error("processContainerAddChild: MBeanException", e);
    } catch (Throwable t) {
        log.error("processContainerAddChild: Throwable", t);
    }

}

From source file:org.apache.catalina.mbeans.ServerLifecycleListener.java

/**
 * Process the removal of a child Container from a parent Container.
 *
 * @param parent Parent container//from   ww  w.  jav a  2s. c o  m
 * @param child Child container
 */
protected void processContainerRemoveChild(Container parent, Container child) {

    if (log.isDebugEnabled())
        log.debug("Process removeChild[parent=" + parent + ",child=" + child + "]");

    try {
        if (child instanceof Context) {
            Context context = (Context) child;
            if (context.getPrivileged()) {
                context.getServletContext().removeAttribute(Globals.MBEAN_REGISTRY_ATTR);
                context.getServletContext().removeAttribute(Globals.MBEAN_SERVER_ATTR);
            }
            if (log.isDebugEnabled())
                log.debug("  Removing MBean for Context " + context);
            destroyMBeans(context);
            if (context instanceof StandardContext) {
                ((StandardContext) context).removePropertyChangeListener(this);
            }
        } else if (child instanceof Host) {
            Host host = (Host) child;
            destroyMBeans(host);
            if (host instanceof StandardHost) {
                ((StandardHost) host).removePropertyChangeListener(this);
            }
        }
    } catch (MBeanException t) {
        Exception e = t.getTargetException();
        if (e == null)
            e = t;
        log.error("processContainerRemoveChild: MBeanException", e);
    } catch (Throwable t) {
        log.error("processContainerRemoveChild: Throwable", t);
    }

}

From source file:org.springframework.jmx.access.MBeanClientInterceptor.java

/**
 * Route the invocation to the configured managed resource. Correctly routes JavaBean property
 * access to {@code MBeanServerConnection.get/setAttribute} and method invocation to
 * {@code MBeanServerConnection.invoke}.
 * @param invocation the {@code MethodInvocation} to re-route
 * @return the value returned as a result of the re-routed invocation
 * @throws Throwable an invocation error propagated to the user
 *//*  ww w  .  j  a va  2 s. c  o  m*/
@Nullable
protected Object doInvoke(MethodInvocation invocation) throws Throwable {
    Method method = invocation.getMethod();
    try {
        Object result;
        if (this.invocationHandler != null) {
            result = this.invocationHandler.invoke(invocation.getThis(), method, invocation.getArguments());
        } else {
            PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
            if (pd != null) {
                result = invokeAttribute(pd, invocation);
            } else {
                result = invokeOperation(method, invocation.getArguments());
            }
        }
        return convertResultValueIfNecessary(result, new MethodParameter(method, -1));
    } catch (MBeanException ex) {
        throw ex.getTargetException();
    } catch (RuntimeMBeanException ex) {
        throw ex.getTargetException();
    } catch (RuntimeErrorException ex) {
        throw ex.getTargetError();
    } catch (RuntimeOperationsException ex) {
        // This one is only thrown by the JMX 1.2 RI, not by the JDK 1.5 JMX code.
        RuntimeException rex = ex.getTargetException();
        if (rex instanceof RuntimeMBeanException) {
            throw ((RuntimeMBeanException) rex).getTargetException();
        } else if (rex instanceof RuntimeErrorException) {
            throw ((RuntimeErrorException) rex).getTargetError();
        } else {
            throw rex;
        }
    } catch (OperationsException ex) {
        if (ReflectionUtils.declaresException(method, ex.getClass())) {
            throw ex;
        } else {
            throw new InvalidInvocationException(ex.getMessage());
        }
    } catch (JMException ex) {
        if (ReflectionUtils.declaresException(method, ex.getClass())) {
            throw ex;
        } else {
            throw new InvocationFailureException("JMX access failed", ex);
        }
    } catch (IOException ex) {
        if (ReflectionUtils.declaresException(method, ex.getClass())) {
            throw ex;
        } else {
            throw new MBeanConnectFailureException("I/O failure during JMX access", ex);
        }
    }
}