Search in sources :

Example 1 with ProxyRefAddr

use of org.glassfish.resources.naming.ProxyRefAddr in project Payara by payara.

the class ExternalJndiResourceDeployer method installExternalJndiResource.

/**
 * Installs the given external jndi resource. This method gets called
 * during server initialization and from external jndi resource
 * deployer to handle resource events.
 *
 * @param extJndiRes external jndi resource
 * @param resourceInfo Information about the resource
 */
public void installExternalJndiResource(org.glassfish.resources.beans.ExternalJndiResource extJndiRes, ResourceInfo resourceInfo) {
    try {
        // create the external JNDI factory, its initial context and
        // pass them as references.
        String factoryClass = extJndiRes.getFactoryClass();
        String jndiLookupName = extJndiRes.getJndiLookupName();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "installExternalJndiResources resourceName " + resourceInfo + " factoryClass " + factoryClass + " jndiLookupName = " + jndiLookupName);
        }
        Object factory = ResourceUtil.loadObject(factoryClass);
        if (factory == null) {
            _logger.log(Level.WARNING, "jndi.factory_load_error", factoryClass);
            return;
        } else if (!(factory instanceof javax.naming.spi.InitialContextFactory)) {
            _logger.log(Level.WARNING, "jndi.factory_class_unexpected", factoryClass);
            return;
        }
        // Get properties to create the initial naming context
        // for the target JNDI factory
        Hashtable env = new Hashtable();
        for (Iterator props = extJndiRes.getProperties().iterator(); props.hasNext(); ) {
            ResourceProperty prop = (ResourceProperty) props.next();
            env.put(prop.getName(), prop.getValue());
        }
        Context context = null;
        try {
            context = ((InitialContextFactory) factory).getInitialContext(env);
        } catch (NamingException ne) {
            _logger.log(Level.SEVERE, "jndi.initial_context_error", factoryClass);
            _logger.log(Level.SEVERE, "jndi.initial_context_error_excp", ne.getMessage());
        }
        if (context == null) {
            _logger.log(Level.SEVERE, "jndi.factory_create_error", factoryClass);
            return;
        }
        // Bind a Reference to the proxy object factory; set the
        // initial context factory.
        // JndiProxyObjectFactory.setInitialContext(bindName, context);
        Reference ref = new Reference(extJndiRes.getResType(), "org.glassfish.resources.naming.JndiProxyObjectFactory", null);
        // unique JNDI name within server runtime
        ref.add(new SerializableObjectRefAddr("resourceInfo", resourceInfo));
        // target JNDI name
        ref.add(new StringRefAddr("jndiLookupName", jndiLookupName));
        // target JNDI factory class
        ref.add(new StringRefAddr("jndiFactoryClass", factoryClass));
        // add Context info as a reference address
        ref.add(new ProxyRefAddr(extJndiRes.getResourceInfo().getName(), env));
        // Publish the reference
        namingService.publishObject(resourceInfo, ref, true);
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "customrsrc.create_ref_error", resourceInfo);
        _logger.log(Level.SEVERE, "customrsrc.create_ref_error_excp", ex);
    }
}
Also used : Context(javax.naming.Context) Hashtable(java.util.Hashtable) Reference(javax.naming.Reference) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) NamingException(javax.naming.NamingException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) InitialContextFactory(javax.naming.spi.InitialContextFactory) ResourceProperty(com.sun.enterprise.repository.ResourceProperty) StringRefAddr(javax.naming.StringRefAddr) Iterator(java.util.Iterator) NamingException(javax.naming.NamingException) ProxyRefAddr(org.glassfish.resources.naming.ProxyRefAddr)

Aggregations

ResourceProperty (com.sun.enterprise.repository.ResourceProperty)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1 Reference (javax.naming.Reference)1 StringRefAddr (javax.naming.StringRefAddr)1 InitialContextFactory (javax.naming.spi.InitialContextFactory)1 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)1 ProxyRefAddr (org.glassfish.resources.naming.ProxyRefAddr)1 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)1