Search in sources :

Example 1 with SerializableObjectRefAddr

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

the class MailResourceDeployer method installMailResource.

/**
 * Installs the given mail resource. This method gets called during server
 * initialization and from mail resource deployer to handle resource events.
 *
 * @param mailResource mail resource
 * @param resourceInfo
 */
public void installMailResource(MailBean mailResource, ResourceInfo resourceInfo) {
    try {
        MailConfiguration config = new MailConfiguration(mailResource);
        javax.naming.Reference ref = new javax.naming.Reference(javax.mail.Session.class.getName(), MailNamingObjectFactory.class.getName(), null);
        SerializableObjectRefAddr serializableRefAddr = new SerializableObjectRefAddr("jndiName", config);
        ref.add(serializableRefAddr);
        // Publish the object
        namingService.publishObject(resourceInfo, ref, true);
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "mailrsrc.create_obj_error", resourceInfo);
        _logger.log(Level.SEVERE, "mailrsrc.create_obj_error_excp", ex);
    }
}
Also used : MailConfiguration(com.sun.enterprise.deployment.MailConfiguration) MailNamingObjectFactory(org.glassfish.resources.javamail.naming.MailNamingObjectFactory) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) NamingException(javax.naming.NamingException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException)

Example 2 with SerializableObjectRefAddr

use of org.glassfish.resources.naming.SerializableObjectRefAddr 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 3 with SerializableObjectRefAddr

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

the class ContextServiceDeployer method deployResource.

@Override
public void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
    ContextService contextServiceRes = (ContextService) resource;
    if (contextServiceRes == null) {
        _logger.log(Level.WARNING, LogFacade.DEPLOY_ERROR_NULL_CONFIG, "ContextService");
        return;
    }
    String jndiName = contextServiceRes.getJndiName();
    String contextInfo = contextServiceRes.getContextInfo();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "ContextServiceDeployer.deployResource() : jndi-name [" + jndiName + "], " + " context-info [" + contextInfo + "]");
    }
    ResourceInfo resourceInfo = new ResourceInfo(contextServiceRes.getJndiName(), applicationName, moduleName);
    ContextServiceConfig config = new ContextServiceConfig(contextServiceRes);
    javax.naming.Reference ref = new javax.naming.Reference(javax.enterprise.concurrent.ContextService.class.getName(), "org.glassfish.concurrent.runtime.deployer.ConcurrentObjectFactory", null);
    RefAddr addr = new SerializableObjectRefAddr(ContextServiceConfig.class.getName(), config);
    ref.add(addr);
    RefAddr resAddr = new SerializableObjectRefAddr(ResourceInfo.class.getName(), resourceInfo);
    ref.add(resAddr);
    try {
        // Publish the object ref
        namingService.publishObject(resourceInfo, ref, true);
    } catch (NamingException ex) {
        LogHelper.log(_logger, Level.SEVERE, LogFacade.UNABLE_TO_BIND_OBJECT, ex, "ContextService", jndiName);
    }
}
Also used : RefAddr(javax.naming.RefAddr) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) ContextService(org.glassfish.concurrent.config.ContextService) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) NamingException(javax.naming.NamingException)

Example 4 with SerializableObjectRefAddr

use of org.glassfish.resources.naming.SerializableObjectRefAddr 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 5 with SerializableObjectRefAddr

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

the class ManagedScheduledExecutorServiceDeployer method deployResource.

@Override
public void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
    ManagedScheduledExecutorService managedScheduledExecutorServiceRes = (ManagedScheduledExecutorService) resource;
    if (managedScheduledExecutorServiceRes == null) {
        _logger.log(Level.WARNING, LogFacade.DEPLOY_ERROR_NULL_CONFIG, "ManagedScheduledExecutorService");
        return;
    }
    String jndiName = managedScheduledExecutorServiceRes.getJndiName();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "ManagedScheduledExecutorServiceDeployer.deployResource() : jndi-name [" + jndiName + "]");
    }
    ResourceInfo resourceInfo = new ResourceInfo(managedScheduledExecutorServiceRes.getJndiName(), applicationName, moduleName);
    ManagedScheduledExecutorServiceConfig config = new ManagedScheduledExecutorServiceConfig(managedScheduledExecutorServiceRes);
    javax.naming.Reference ref = new javax.naming.Reference(javax.enterprise.concurrent.ManagedScheduledExecutorService.class.getName(), "org.glassfish.concurrent.runtime.deployer.ConcurrentObjectFactory", null);
    RefAddr addr = new SerializableObjectRefAddr(ManagedScheduledExecutorServiceConfig.class.getName(), config);
    ref.add(addr);
    RefAddr resAddr = new SerializableObjectRefAddr(ResourceInfo.class.getName(), resourceInfo);
    ref.add(resAddr);
    try {
        // Publish the object ref
        namingService.publishObject(resourceInfo, ref, true);
    } catch (NamingException ex) {
        LogHelper.log(_logger, Level.SEVERE, LogFacade.UNABLE_TO_BIND_OBJECT, ex, "ManagedScheduledExecutorService", jndiName);
    }
    registerMonitorableComponent(managedScheduledExecutorServiceRes);
}
Also used : RefAddr(javax.naming.RefAddr) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) NamingException(javax.naming.NamingException) ManagedScheduledExecutorService(org.glassfish.concurrent.config.ManagedScheduledExecutorService)

Aggregations

NamingException (javax.naming.NamingException)7 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)7 RefAddr (javax.naming.RefAddr)5 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)5 StringRefAddr (javax.naming.StringRefAddr)2 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 ConnectorNamingEvent (com.sun.appserv.connectors.internal.spi.ConnectorNamingEvent)1 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)1 ConnectorDescriptorInfo (com.sun.enterprise.connectors.ConnectorDescriptorInfo)1 MailConfiguration (com.sun.enterprise.deployment.MailConfiguration)1 ResourceProperty (com.sun.enterprise.repository.ResourceProperty)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Context (javax.naming.Context)1 Reference (javax.naming.Reference)1 InitialContextFactory (javax.naming.spi.InitialContextFactory)1 ContextService (org.glassfish.concurrent.config.ContextService)1 ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)1 ManagedScheduledExecutorService (org.glassfish.concurrent.config.ManagedScheduledExecutorService)1