Search in sources :

Example 46 with MBeanException

use of javax.management.MBeanException in project ddf by codice.

the class ResourceDownloadActionEndpointTest method getDownloadToLocalSiteExceptionWrappedInMBeanException.

private MBeanException getDownloadToLocalSiteExceptionWrappedInMBeanException() {
    String message = "exception message";
    DownloadToLocalSiteException downloadToCacheException = new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message);
    MBeanException mBeanException = new MBeanException(downloadToCacheException, message);
    return mBeanException;
}
Also used : MBeanException(javax.management.MBeanException) DownloadToLocalSiteException(org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException)

Example 47 with MBeanException

use of javax.management.MBeanException in project jdk8u_jdk by JetBrains.

the class MBeanExceptionTest method test.

private static int test(MBeanServer mbs, ObjectName name, boolean testChecked) throws Exception {
    System.out.println("--------" + name + "--------");
    int failures = 0;
    final String[] ops = { "getAttribute", "setAttribute", "invoke" };
    final int GET = 0, SET = 1, INVOKE = 2;
    final String[] targets = { "UncheckedException", "CheckedException" };
    final int UNCHECKED = 0, CHECKED = 1;
    for (int i = 0; i < ops.length; i++) {
        for (int j = 0; j < targets.length; j++) {
            if (j == CHECKED && !testChecked)
                continue;
            String target = targets[j];
            String what = ops[i] + "/" + target;
            System.out.println(what);
            try {
                switch(i) {
                    case GET:
                        mbs.getAttribute(name, target);
                        break;
                    case SET:
                        mbs.setAttribute(name, new Attribute(target, "x"));
                        break;
                    case INVOKE:
                        mbs.invoke(name, target, null, null);
                        break;
                    default:
                        throw new AssertionError();
                }
                System.out.println("failure: " + what + " returned!");
                failures++;
            } catch (RuntimeMBeanException e) {
                if (j == CHECKED) {
                    System.out.println("failure: RuntimeMBeanException " + "when checked expected: " + e);
                    failures++;
                } else {
                    Throwable cause = e.getCause();
                    if (cause == theUncheckedException)
                        System.out.println("ok: " + what);
                    else {
                        System.out.println("failure: " + what + " wrapped " + cause);
                        failures++;
                    }
                }
            } catch (MBeanException e) {
                if (j == UNCHECKED) {
                    System.out.println("failure: checked exception " + "when unchecked expected: " + e);
                    failures++;
                } else {
                    Throwable cause = e.getCause();
                    if (cause == theCheckedException)
                        System.out.println("ok: " + what);
                    else {
                        System.out.println("failure: " + what + " wrapped " + cause);
                        failures++;
                    }
                }
            } catch (Throwable t) {
                System.out.println("failure: " + what + " threw: " + t);
                while ((t = t.getCause()) != null) System.out.println("  ... " + t);
                failures++;
            }
        }
    }
    return failures;
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) Attribute(javax.management.Attribute) MBeanException(javax.management.MBeanException) RuntimeMBeanException(javax.management.RuntimeMBeanException)

Example 48 with MBeanException

use of javax.management.MBeanException in project geode by apache.

the class MBeanProcessController method invokeOperationOnTargetMBean.

/**
   * Connects to the process and use its MBean to stop it.
   * 
   * @param namePattern the name pattern of the MBean to use for stopping
   * @param pidAttribute the name of the MBean attribute with the process id to compare against
   * @param methodName the name of the MBean operation to invoke
   * @param attributes the names of the MBean attributes to compare with expected values
   * @param values the expected values of the specified MBean attributes
   *
   * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
   *         in the process
   * @throws IOException if a communication problem occurred when talking to the MBean server
   * @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason
   */
private Object invokeOperationOnTargetMBean(final ObjectName namePattern, final String pidAttribute, final String methodName, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException {
    ObjectName objectName = namePattern;
    connect();
    try {
        final QueryExp constraint = buildQueryExp(pidAttribute, attributes, values);
        final Set<ObjectName> mbeanNames = this.server.queryNames(namePattern, constraint);
        if (mbeanNames.isEmpty()) {
            throw new MBeanInvocationFailedException("Failed to find mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
        }
        if (mbeanNames.size() > 1) {
            throw new MBeanInvocationFailedException("Found more than one mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
        }
        objectName = mbeanNames.iterator().next();
        return invoke(objectName, methodName);
    } catch (InstanceNotFoundException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } catch (MBeanException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } catch (ReflectionException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } finally {
        disconnect();
    }
}
Also used : ReflectionException(javax.management.ReflectionException) QueryExp(javax.management.QueryExp) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 49 with MBeanException

use of javax.management.MBeanException in project geode by apache.

the class LocalProcessController method invokeOperationOnTargetMBean.

/**
   * Connects to the process and use its MBean to stop it.
   * 
   * @param namePattern the name pattern of the MBean to use for stopping
   * @param pidAttribute the name of the MBean attribute with the process id to compare against
   * @param methodName the name of the MBean operation to invoke
   * @param attributes the names of the MBean attributes to compare with expected values
   * @param values the expected values of the specified MBean attributes
   *
   * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
   *         in the process
   * @throws IOException if a communication problem occurred when talking to the MBean server
   * @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason
   * @throws PidUnavailableException if parsing the pid from the RuntimeMXBean name fails
   */
private Object invokeOperationOnTargetMBean(final ObjectName namePattern, final String pidAttribute, final String methodName, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException, PidUnavailableException {
    ObjectName objectName = namePattern;
    connect();
    try {
        final QueryExp constraint = buildQueryExp(pidAttribute, attributes, values);
        final Set<ObjectName> mbeanNames = this.server.queryNames(namePattern, constraint);
        if (mbeanNames.isEmpty()) {
            throw new MBeanInvocationFailedException("Failed to find mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
        }
        if (mbeanNames.size() > 1) {
            throw new MBeanInvocationFailedException("Found more than one mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
        }
        objectName = mbeanNames.iterator().next();
        return invoke(objectName, methodName);
    } catch (InstanceNotFoundException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } catch (MBeanException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } catch (ReflectionException e) {
        throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
    } finally {
        disconnect();
    }
}
Also used : ReflectionException(javax.management.ReflectionException) QueryExp(javax.management.QueryExp) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 50 with MBeanException

use of javax.management.MBeanException in project geode by apache.

the class ConnectionNotificationFilterImpl method stopRMIConnectorServer.

/** Stops the RMIConnectorServer and unregisters its MBean. */
private void stopRMIConnectorServer() {
    if (!this.agentConfig.isRmiEnabled())
        return;
    // stop the RMI Connector server...
    try {
        this.rmiConnector.stop();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
    }
    try {
        ObjectName rmiRegistryNamingName = getRMIRegistryNamingName();
        if (this.agentConfig.isRmiRegistryEnabled() && mBeanServer.isRegistered(rmiRegistryNamingName)) {
            String[] empty = new String[0];
            mBeanServer.invoke(rmiRegistryNamingName, "stop", empty, empty);
            MBeanUtil.unregisterMBean(rmiRegistryNamingName);
        }
    } catch (MalformedObjectNameException e) {
        logger.warn(e.getMessage(), e);
    } catch (InstanceNotFoundException e) {
        logger.warn(e.getMessage(), e);
    } catch (ReflectionException e) {
        logger.warn(e.getMessage(), e);
    } catch (MBeanException e) {
        logger.warn(e.getMessage(), e);
    }
    try {
        ObjectName rmiConnectorServerName = getRMIConnectorServerName();
        if (mBeanServer.isRegistered(rmiConnectorServerName)) {
            MBeanUtil.unregisterMBean(rmiConnectorServerName);
        }
    } catch (MalformedObjectNameException e) {
        logger.warn(e.getMessage(), e);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) OperationsException(javax.management.OperationsException) ReflectionException(javax.management.ReflectionException) AdminException(org.apache.geode.admin.AdminException) MalformedObjectNameException(javax.management.MalformedObjectNameException) GemFireException(org.apache.geode.GemFireException) GemFireIOException(org.apache.geode.GemFireIOException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Aggregations

MBeanException (javax.management.MBeanException)105 ReflectionException (javax.management.ReflectionException)50 InstanceNotFoundException (javax.management.InstanceNotFoundException)41 AttributeNotFoundException (javax.management.AttributeNotFoundException)35 ObjectName (javax.management.ObjectName)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)26 MalformedObjectNameException (javax.management.MalformedObjectNameException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ServiceNotFoundException (javax.management.ServiceNotFoundException)17 Attribute (javax.management.Attribute)14 RuntimeErrorException (javax.management.RuntimeErrorException)14 Method (java.lang.reflect.Method)10 DynamicMBean (javax.management.DynamicMBean)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)10 Descriptor (javax.management.Descriptor)9 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)8 MalformedURLException (java.net.MalformedURLException)7 MBeanRegistrationException (javax.management.MBeanRegistrationException)7