Search in sources :

Example 6 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project tomcat by apache.

the class MemoryUserDatabaseMBean method findUser.

/**
     * Return the MBean Name for the specified user name (if any);
     * otherwise return <code>null</code>.
     *
     * @param username User name to look up
     * @return the user object name
     */
public String findUser(String username) {
    UserDatabase database = (UserDatabase) this.resource;
    User user = database.findUser(username);
    if (user == null) {
        return null;
    }
    try {
        ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user);
        return oname.toString();
    } catch (MalformedObjectNameException e) {
        IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for user [" + username + "]");
        iae.initCause(e);
        throw iae;
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase) ObjectName(javax.management.ObjectName)

Example 7 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project tomcat by apache.

the class StoreConfig method storeServer.

/**
     * Store Server from Object Name (Catalina:type=Server).
     *
     * @param aServerName Server ObjectName
     * @param backup <code>true</code> to backup existing configuration files
     *  before rewriting them
     * @param externalAllowed <code>true</code> to allow saving webapp
     *  configuration for webapps that are not inside the host's app
     *  directory
     * @throws MalformedObjectNameException Bad MBean name
     */
public synchronized void storeServer(String aServerName, boolean backup, boolean externalAllowed) throws MalformedObjectNameException {
    if (aServerName == null || aServerName.length() == 0) {
        if (log.isErrorEnabled())
            log.error("Please, call with a correct server ObjectName!");
        return;
    }
    MBeanServer mserver = MBeanUtils.createServer();
    ObjectName objectName = new ObjectName(aServerName);
    if (mserver.isRegistered(objectName)) {
        try {
            Server aServer = (Server) mserver.getAttribute(objectName, "managedResource");
            StoreDescription desc = null;
            desc = getRegistry().findDescription(StandardContext.class);
            if (desc != null) {
                boolean oldSeparate = desc.isStoreSeparate();
                boolean oldBackup = desc.isBackup();
                boolean oldExternalAllowed = desc.isExternalAllowed();
                try {
                    desc.setStoreSeparate(true);
                    desc.setBackup(backup);
                    desc.setExternalAllowed(externalAllowed);
                    store(aServer);
                } finally {
                    desc.setStoreSeparate(oldSeparate);
                    desc.setBackup(oldBackup);
                    desc.setExternalAllowed(oldExternalAllowed);
                }
            } else {
                store(aServer);
            }
        } catch (Exception e) {
            if (log.isInfoEnabled())
                log.info("Object " + aServerName + " is no a Server instance or store exception", e);
        }
    } else if (log.isInfoEnabled())
        log.info("Server " + aServerName + " not found!");
}
Also used : MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) StandardContext(org.apache.catalina.core.StandardContext) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 8 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project tomcat by apache.

the class BaseGenericObjectPool method jmxRegister.

/**
     * Registers the pool with the platform MBean server.
     * The registered name will be
     * <code>jmxNameBase + jmxNamePrefix + i</code> where i is the least
     * integer greater than or equal to 1 such that the name is not already
     * registered. Swallows MBeanRegistrationException, NotCompliantMBeanException
     * returning null.
     *
     * @param config Pool configuration
     * @param jmxNameBase default base JMX name for this pool
     * @param jmxNamePrefix name prefix
     * @return registered ObjectName, null if registration fails
     */
private ObjectName jmxRegister(final BaseObjectPoolConfig config, final String jmxNameBase, String jmxNamePrefix) {
    ObjectName objectName = null;
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    int i = 1;
    boolean registered = false;
    String base = config.getJmxNameBase();
    if (base == null) {
        base = jmxNameBase;
    }
    while (!registered) {
        try {
            ObjectName objName;
            // only one so the names are cleaner.
            if (i == 1) {
                objName = new ObjectName(base + jmxNamePrefix);
            } else {
                objName = new ObjectName(base + jmxNamePrefix + i);
            }
            mbs.registerMBean(this, objName);
            objectName = objName;
            registered = true;
        } catch (final MalformedObjectNameException e) {
            if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(jmxNamePrefix) && jmxNameBase.equals(base)) {
                // Shouldn't happen. Skip registration if it does.
                registered = true;
            } else {
                // Must be an invalid name. Use the defaults instead.
                jmxNamePrefix = BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX;
                base = jmxNameBase;
            }
        } catch (final InstanceAlreadyExistsException e) {
            // Increment the index and try again
            i++;
        } catch (final MBeanRegistrationException e) {
            // Shouldn't happen. Skip registration if it does.
            registered = true;
        } catch (final NotCompliantMBeanException e) {
            // Shouldn't happen. Skip registration if it does.
            registered = true;
        }
    }
    return objectName;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 9 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project tomcat by apache.

the class BasicDataSource method jmxRegister.

private void jmxRegister() {
    // Return immediately if this DataSource has already been registered
    if (registeredJmxName != null) {
        return;
    }
    // Return immediately if no JMX name has been specified
    final String requestedName = getJmxName();
    if (requestedName == null) {
        return;
    }
    ObjectName oname;
    try {
        oname = new ObjectName(requestedName);
    } catch (final MalformedObjectNameException e) {
        log.warn("The requested JMX name [" + requestedName + "] was not valid and will be ignored.");
        return;
    }
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        mbs.registerMBean(this, oname);
    } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
        log.warn("Failed to complete JMX registration", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 10 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project tomcat by apache.

the class GroupMBean method getUsers.

/**
     * @return the MBean Names of all users that are members of this group.
     */
public String[] getUsers() {
    Group group = (Group) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<User> users = group.getUsers();
    while (users.hasNext()) {
        User user = null;
        try {
            user = users.next();
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), user);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for user " + user);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);
}
Also used : Group(org.apache.catalina.Group) MalformedObjectNameException(javax.management.MalformedObjectNameException) User(org.apache.catalina.User) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)123 ObjectName (javax.management.ObjectName)115 MBeanServer (javax.management.MBeanServer)34 MBeanRegistrationException (javax.management.MBeanRegistrationException)32 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)27 InstanceNotFoundException (javax.management.InstanceNotFoundException)26 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)25 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)14 MBeanException (javax.management.MBeanException)7 ReflectionException (javax.management.ReflectionException)7 HashMap (java.util.HashMap)6 StandardMBean (javax.management.StandardMBean)5 CacheServiceMBean (org.apache.cassandra.service.CacheServiceMBean)5 Map (java.util.Map)4 HashSet (java.util.HashSet)3 CacheException (javax.cache.CacheException)3 Group (org.apache.catalina.Group)3 User (org.apache.catalina.User)3 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)3