Search in sources :

Example 1 with OperationsException

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

the class MBeanInstantiator method deserialize.

/**
     * De-serializes a byte array in the context of a classloader.
     *
     * @param loader the classloader to use for de-serialization
     * @param data The byte array to be de-sererialized.
     *
     * @return  The de-serialized object stream.
     *
     * @exception OperationsException Any of the usual Input/Output related
     * exceptions.
     */
public ObjectInputStream deserialize(ClassLoader loader, byte[] data) throws OperationsException {
    // Check parameter validity
    if (data == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Null data passed in parameter");
    }
    if (data.length == 0) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Empty data passed in parameter");
    }
    // Object deserialization
    ByteArrayInputStream bIn;
    ObjectInputStream objIn;
    bIn = new ByteArrayInputStream(data);
    try {
        objIn = new ObjectInputStreamWithLoader(bIn, loader);
    } catch (IOException e) {
        throw new OperationsException("An IOException occurred trying to de-serialize the data");
    }
    return objIn;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ObjectInputStream(java.io.ObjectInputStream) OperationsException(javax.management.OperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 2 with OperationsException

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

the class ConnectionNotificationFilterImpl method initializeHelperMbean.

private void initializeHelperMbean() {
    try {
        memberInfoWithStatsMBean = new MemberInfoWithStatsMBean(this);
        MBeanServer mbs = getMBeanServer();
        mbs.registerMBean(memberInfoWithStatsMBean, memberInfoWithStatsMBean.getObjectName());
    /*
       * We are not re-throwing these exceptions as failure create/register the GemFireTypesWrapper
       * will not stop the Agent from working. But we are logging it as it could be an indication of
       * some problem. Also not creating Localized String for the exception.
       */
    } catch (OperationsException e) {
        logger.info(LocalizedMessage.create(LocalizedStrings.AgentImpl_FAILED_TO_INITIALIZE_MEMBERINFOWITHSTATSMBEAN), e);
    } catch (MBeanRegistrationException e) {
        logger.info(LocalizedMessage.create(LocalizedStrings.AgentImpl_FAILED_TO_INITIALIZE_MEMBERINFOWITHSTATSMBEAN), e);
    } catch (AdminException e) {
        logger.info(LocalizedMessage.create(LocalizedStrings.AgentImpl_FAILED_TO_INITIALIZE_MEMBERINFOWITHSTATSMBEAN), e);
    }
}
Also used : AdminException(org.apache.geode.admin.AdminException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) OperationsException(javax.management.OperationsException)

Example 3 with OperationsException

use of javax.management.OperationsException in project apache-kafka-on-k8s by banzaicloud.

the class SanitizerTest method verifyJmx.

private void verifyJmx(String sanitizedValue, int c) throws MalformedObjectNameException {
    Object mbean = new TestStat();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("test:key=" + sanitizedValue);
    try {
        server.registerMBean(mbean, objectName);
        server.unregisterMBean(objectName);
    } catch (OperationsException | MBeanException e) {
        fail("Could not register char=\\u" + c);
    }
}
Also used : MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) OperationsException(javax.management.OperationsException)

Example 4 with OperationsException

use of javax.management.OperationsException in project kafka by apache.

the class SanitizerTest method verifyJmx.

private void verifyJmx(String sanitizedValue, int c) throws MalformedObjectNameException {
    Object mbean = new TestStat();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("test:key=" + sanitizedValue);
    try {
        server.registerMBean(mbean, objectName);
        server.unregisterMBean(objectName);
    } catch (OperationsException | MBeanException e) {
        fail("Could not register char=\\u" + c);
    }
}
Also used : MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) OperationsException(javax.management.OperationsException)

Example 5 with OperationsException

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

the class MBeanInstantiator method deserialize.

/**
     * De-serializes a byte array in the context of a given MBean class loader.
     * <P>The class loader is the one that loaded the class with name
     * "className".
     * <P>The name of the class loader to be used for loading the specified
     * class is specified. If null, a default one has to be provided (for a
     * MBean Server, its own class loader will be used).
     *
     * @param className The name of the class whose class loader should
     *  be used for the de-serialization.
     * @param data The byte array to be de-sererialized.
     * @param loaderName The name of the class loader to be used for loading
     * the specified class. If null, a default one has to be provided (for a
     * MBean Server, its own class loader will be used).
     *
     * @return  The de-serialized object stream.
     *
     * @exception InstanceNotFoundException The specified class loader MBean is
     * not found.
     * @exception OperationsException Any of the usual Input/Output related
     * exceptions.
     * @exception ReflectionException The specified class could not be loaded
     * by the specified class loader.
     */
public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data, ClassLoader loader) throws InstanceNotFoundException, OperationsException, ReflectionException {
    // Check parameter validity
    if (data == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Null data passed in parameter");
    }
    if (data.length == 0) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Empty data passed in parameter");
    }
    if (className == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(), "Null className passed in parameter");
    }
    ReflectUtil.checkPackageAccess(className);
    Class<?> theClass;
    if (loaderName == null) {
        // Load the class using the agent class loader
        theClass = findClass(className, loader);
    } else {
        // Get the class loader MBean
        try {
            ClassLoader instance = null;
            instance = getClassLoader(loaderName);
            if (instance == null)
                throw new ClassNotFoundException(className);
            theClass = Class.forName(className, false, instance);
        } catch (ClassNotFoundException e) {
            throw new ReflectionException(e, "The MBean class could not be loaded by the " + loaderName.toString() + " class loader");
        }
    }
    // Object deserialization
    ByteArrayInputStream bIn;
    ObjectInputStream objIn;
    bIn = new ByteArrayInputStream(data);
    try {
        objIn = new ObjectInputStreamWithLoader(bIn, theClass.getClassLoader());
    } catch (IOException e) {
        throw new OperationsException("An IOException occurred trying to de-serialize the data");
    }
    return objIn;
}
Also used : ReflectionException(javax.management.ReflectionException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) RuntimeOperationsException(javax.management.RuntimeOperationsException) ObjectInputStream(java.io.ObjectInputStream) OperationsException(javax.management.OperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

OperationsException (javax.management.OperationsException)6 IOException (java.io.IOException)3 MBeanException (javax.management.MBeanException)3 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ReflectionException (javax.management.ReflectionException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 ServletException (jakarta.servlet.ServletException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 MBeanParameterInfo (javax.management.MBeanParameterInfo)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 AdminException (org.apache.geode.admin.AdminException)1