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