Search in sources :

Example 1 with ImplementationException

use of org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException in project felix by apache.

the class MX4JMBeanServer method registerImpl.

private void registerImpl(MBeanMetaData metadata, boolean privileged) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    introspector.introspect(metadata);
    if (!introspector.isMBeanCompliant(metadata))
        throw new NotCompliantMBeanException("MBean is not compliant");
    MBeanServerInterceptor head = getHeadInterceptor();
    try {
        // With this call, the MBean implementor can replace the ObjectName with a subclass that is not secure, secure it again
        head.registration(metadata, MBeanServerInterceptor.PRE_REGISTER);
        metadata.name = secureObjectName(metadata.name);
        metadata.instance = new ObjectInstance(metadata.name, metadata.info.getClassName());
        register(metadata, privileged);
        head.registration(metadata, MBeanServerInterceptor.POST_REGISTER_TRUE);
    } catch (Throwable x) {
        try {
            head.registration(metadata, MBeanServerInterceptor.POST_REGISTER_FALSE);
        } catch (MBeanRegistrationException ignored) {
        /* Ignore this one to rethrow the other one */
        }
        if (x instanceof SecurityException) {
            throw (SecurityException) x;
        } else if (x instanceof InstanceAlreadyExistsException) {
            throw (InstanceAlreadyExistsException) x;
        } else if (x instanceof MBeanRegistrationException) {
            throw (MBeanRegistrationException) x;
        } else if (x instanceof RuntimeOperationsException) {
            throw (RuntimeOperationsException) x;
        } else if (x instanceof JMRuntimeException) {
            throw (JMRuntimeException) x;
        } else if (x instanceof Exception) {
            throw new MBeanRegistrationException((Exception) x);
        } else if (x instanceof Error) {
            throw new MBeanRegistrationException(new RuntimeErrorException((Error) x));
        } else {
            throw new ImplementationException();
        }
    }
    if (metadata.mbean instanceof ClassLoader && !(metadata.mbean instanceof PrivateClassLoader)) {
        ClassLoader cl = (ClassLoader) metadata.mbean;
        getModifiableClassLoaderRepository().addClassLoader(cl);
    }
}
Also used : RuntimeErrorException(javax.management.RuntimeErrorException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ImplementationException(org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException) ObjectInstance(javax.management.ObjectInstance) PrivateClassLoader(javax.management.loading.PrivateClassLoader) IntrospectionException(javax.management.IntrospectionException) OperationsException(javax.management.OperationsException) BadBinaryOpValueExpException(javax.management.BadBinaryOpValueExpException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) BadStringOperationException(javax.management.BadStringOperationException) ReflectionException(javax.management.ReflectionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RuntimeErrorException(javax.management.RuntimeErrorException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) PrivilegedActionException(java.security.PrivilegedActionException) BadAttributeValueExpException(javax.management.BadAttributeValueExpException) IOException(java.io.IOException) ImplementationException(org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) InvalidApplicationException(javax.management.InvalidApplicationException) MBeanServerInterceptor(org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor.MBeanServerInterceptor) InvokerMBeanServerInterceptor(org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor.InvokerMBeanServerInterceptor) PrivateClassLoader(javax.management.loading.PrivateClassLoader) JMRuntimeException(javax.management.JMRuntimeException) MBeanRegistrationException(javax.management.MBeanRegistrationException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 2 with ImplementationException

use of org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException in project felix by apache.

the class InvokerMBeanServerInterceptor method registration.

public void registration(MBeanMetaData metadata, int operation) throws MBeanRegistrationException {
    if (!(metadata.mbean instanceof MBeanRegistration))
        return;
    MBeanRegistration registrable = (MBeanRegistration) metadata.mbean;
    try {
        switch(operation) {
            case PRE_REGISTER:
                ObjectName objName = registrable.preRegister(outerServer, metadata.name);
                metadata.name = objName;
                break;
            case POST_REGISTER_TRUE:
                registrable.postRegister(Boolean.TRUE);
                break;
            case POST_REGISTER_FALSE:
                registrable.postRegister(Boolean.FALSE);
                break;
            case PRE_DEREGISTER:
                registrable.preDeregister();
                break;
            case POST_DEREGISTER:
                registrable.postDeregister();
                break;
            default:
                throw new ImplementationException();
        }
    } catch (RuntimeException x) {
        throw new RuntimeMBeanException(x);
    } catch (Exception x) {
        if (x instanceof MBeanRegistrationException) {
            throw (MBeanRegistrationException) x;
        }
        throw new MBeanRegistrationException(x);
    }
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) JMRuntimeException(javax.management.JMRuntimeException) ImplementationException(org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ReflectionException(javax.management.ReflectionException) JMRuntimeException(javax.management.JMRuntimeException) RuntimeMBeanException(javax.management.RuntimeMBeanException) RuntimeErrorException(javax.management.RuntimeErrorException) ImplementationException(org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanRegistration(javax.management.MBeanRegistration) ObjectName(javax.management.ObjectName)

Aggregations

AttributeNotFoundException (javax.management.AttributeNotFoundException)2 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)2 JMRuntimeException (javax.management.JMRuntimeException)2 ListenerNotFoundException (javax.management.ListenerNotFoundException)2 MBeanException (javax.management.MBeanException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 ReflectionException (javax.management.ReflectionException)2 RuntimeErrorException (javax.management.RuntimeErrorException)2 ImplementationException (org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 BadAttributeValueExpException (javax.management.BadAttributeValueExpException)1 BadBinaryOpValueExpException (javax.management.BadBinaryOpValueExpException)1 BadStringOperationException (javax.management.BadStringOperationException)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 IntrospectionException (javax.management.IntrospectionException)1 InvalidApplicationException (javax.management.InvalidApplicationException)1 MBeanRegistration (javax.management.MBeanRegistration)1