Search in sources :

Example 16 with StringRefAddr

use of javax.naming.StringRefAddr 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)

Example 17 with StringRefAddr

use of javax.naming.StringRefAddr in project Payara by payara.

the class ConnectorResourceAdminServiceImpl method createConnectorResource.

/**
 * Creates the connector resource on a given connection pool
 *
 * @param resourceInfo     JNDI name of the resource to be created
 * @param poolInfo     PoolName to which the connector resource belongs.
 * @param resourceType Resource type Unused.
 * @throws ConnectorRuntimeException If the resouce creation fails.
 */
public void createConnectorResource(ResourceInfo resourceInfo, PoolInfo poolInfo, String resourceType) throws ConnectorRuntimeException {
    try {
        ConnectorConnectionPool ccp = null;
        String jndiNameForPool = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolInfo);
        try {
            ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
        } catch (NamingException ne) {
            // Probably the pool is not yet initialized (lazy-loading), try doing a lookup
            try {
                checkAndLoadPool(poolInfo);
                ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
            } catch (NamingException e) {
                Object[] params = new Object[] { poolInfo, e };
                _logger.log(Level.SEVERE, "unable.to.lookup.pool", params);
            }
        }
        if (ccp == null) {
            ccp = (ConnectorConnectionPool) namingService.lookup(poolInfo, jndiNameForPool);
        }
        ConnectorDescriptorInfo cdi = ccp.getConnectorDescriptorInfo();
        javax.naming.Reference ref = new javax.naming.Reference(cdi.getConnectionFactoryClass(), "com.sun.enterprise.resource.naming.ConnectorObjectFactory", null);
        RefAddr addr = new SerializableObjectRefAddr(PoolInfo.class.getName(), poolInfo);
        ref.add(addr);
        addr = new StringRefAddr("rarName", cdi.getRarName());
        ref.add(addr);
        RefAddr resAddr = new SerializableObjectRefAddr(ResourceInfo.class.getName(), resourceInfo);
        ref.add(resAddr);
        try {
            namingService.publishObject(resourceInfo, ref, true);
            _registry.addResourceInfo(resourceInfo);
        } catch (NamingException ne) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException(ne.getMessage());
            cre.initCause(ne);
            Object[] params = new Object[] { resourceInfo, cre };
            _logger.log(Level.SEVERE, "rardeployment.resource_jndi_bind_failure", params);
            throw cre;
        }
        /*

            ConnectorObjectFactory cof = new ConnectorObjectFactory(jndiName, ccp.getConnectorDescriptorInfo().
                    getConnectionFactoryClass(), cdi.getRarName(), poolName);

            _runtime.getNamingManager().publishObject(jndiName, cof, true);
*/
        // To notify that a connector resource rebind has happened.
        ConnectorResourceNamingEventNotifier.getInstance().notifyListeners(new ConnectorNamingEvent(resourceInfo.toString(), ConnectorNamingEvent.EVENT_OBJECT_REBIND));
    } catch (NamingException ne) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException(ne.getMessage());
        cre.initCause(ne);
        Object[] params = new Object[] { resourceInfo, cre };
        _logger.log(Level.SEVERE, "rardeployment.jndi_lookup_failed", params);
        throw cre;
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ConnectorConnectionPool(com.sun.enterprise.connectors.ConnectorConnectionPool) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) ConnectorNamingEvent(com.sun.appserv.connectors.internal.spi.ConnectorNamingEvent) RefAddr(javax.naming.RefAddr) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) StringRefAddr(javax.naming.StringRefAddr) StringRefAddr(javax.naming.StringRefAddr) ConnectorDescriptorInfo(com.sun.enterprise.connectors.ConnectorDescriptorInfo) NamingException(javax.naming.NamingException) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo)

Example 18 with StringRefAddr

use of javax.naming.StringRefAddr in project rabbitmq-jms-client by rabbitmq.

the class RMQDestination method addBooleanProperty.

/**
 * Adds a boolean valued property to a Reference (as a StringRefAddr) if the value is <code>true</code>
 * (default <code>false</code> on read assumed).
 * @param ref - the reference to contain the value
 * @param propertyName - the name of the property
 * @param value - the value to store with the property
 */
private static final void addBooleanProperty(Reference ref, String propertyName, boolean value) {
    if (propertyName == null)
        return;
    if (value) {
        RefAddr ra = new StringRefAddr(propertyName, String.valueOf(value));
        ref.add(ra);
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr)

Example 19 with StringRefAddr

use of javax.naming.StringRefAddr in project rabbitmq-jms-client by rabbitmq.

the class RMQDestination method addStringProperty.

/**
 * Adds a String valued property to a Reference (as a RefAddr) if it is non-<code>null</code>.
 * @param ref - the reference to contain the value
 * @param propertyName - the name of the property
 * @param value - the value to store with the property
 */
private static final void addStringProperty(Reference ref, String propertyName, String value) {
    if (value == null || propertyName == null)
        return;
    RefAddr ra = new StringRefAddr(propertyName, value);
    ref.add(ra);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr)

Example 20 with StringRefAddr

use of javax.naming.StringRefAddr in project rabbitmq-jms-client by rabbitmq.

the class RMQConnectionFactoryTest method addStringRefProperty.

/**
 * Adds a String valued property to a Reference (as a RefAddr)
 *
 * @param ref          - the reference to contain the value
 * @param propertyName - the name of the property
 * @param value        - the value to store with the property
 */
private static void addStringRefProperty(Reference ref, String propertyName, String value) {
    if (value == null || propertyName == null)
        return;
    removeRefProperty(ref, propertyName);
    RefAddr ra = new StringRefAddr(propertyName, value);
    ref.add(ra);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr)

Aggregations

StringRefAddr (javax.naming.StringRefAddr)67 Reference (javax.naming.Reference)51 NamingException (javax.naming.NamingException)18 RefAddr (javax.naming.RefAddr)9 Test (org.junit.Test)8 Name (javax.naming.Name)7 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 CompositeName (javax.naming.CompositeName)5 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)5 ObjectFactory (javax.naming.spi.ObjectFactory)5 MalformedURLException (java.net.MalformedURLException)4 Enumeration (java.util.Enumeration)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 Context (javax.naming.Context)4 NameNotFoundException (javax.naming.NameNotFoundException)3 Context (org.apache.catalina.Context)3 NamingContext (org.apache.naming.NamingContext)3