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