All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hthurow.tomcatjndi.NamingContextListener Maven / Gradle / Ivy

package hthurow.tomcatjndi;

import org.apache.catalina.Context;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.deploy.ContextResource;

import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

/**
 * @author Holger Thurow ([email protected])
 * @since 26.07.17
 */
public class NamingContextListener extends org.apache.catalina.core.NamingContextListener {

    @Override
    public void lifecycleEvent(LifecycleEvent event) {

        container = event.getLifecycle();
        if (container instanceof Context) {
            ((Context)container).setLoader(new Loader());
        }

        super.lifecycleEvent(event);

    }

    /**
     *
     * TODO Only called in case of a DataSource?
     * TODO Reconsider building of ObjectName.
     * 

* Sonst "Failed to register in JMX: javax.management.RuntimeOperationsException: Object name cannot be null" *

     Jul 24, 2017 7:28:36 AM org.apache.tomcat.util.modeler.Registry registerComponent
     SEVERE: Error registering null
     javax.management.RuntimeOperationsException: Object name cannot be null
     ...
     Jul 24, 2017 7:28:36 AM org.apache.catalina.core.NamingContextListener addResource
     WARNING: Failed to register in JMX: javax.management.RuntimeOperationsException: Object name cannot be null
     * 
*/ @Override protected ObjectName createObjectName(ContextResource resource) throws MalformedObjectNameException { String domain = "Catalina"; ObjectName name; String quotedResourceName = ObjectName.quote(resource.getName()); name = new ObjectName(domain + ":type=DataSource" + ",class=" + resource.getType() + ",name=" + quotedResourceName); return (name); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy