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);
}
}
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);
}
}
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);
}
}
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;
}
}
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);
}
Aggregations