Search in sources :

Example 56 with StringRefAddr

use of javax.naming.StringRefAddr in project aries by apache.

the class ObjectFactoryTest method testURLReferenceWithNoMatchingHandler.

@Test
public void testURLReferenceWithNoMatchingHandler() throws Exception {
    Reference ref = new Reference(null);
    ref.add(new StringRefAddr("URL", "wibble"));
    Object obj = NamingManager.getObjectInstance(ref, null, null, env);
    assertSame("The naming manager should have returned the reference object", ref, obj);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) Test(org.junit.Test)

Example 57 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class NamingContextListener method addResource.

/**
 * Set the specified resources in the naming context.
 *
 * @param resource the resource descriptor
 */
public void addResource(ContextResource resource) {
    Reference ref = lookForLookupRef(resource);
    if (ref == null) {
        // Create a reference to the resource.
        ref = new ResourceRef(resource.getType(), resource.getDescription(), resource.getScope(), resource.getAuth(), resource.getSingleton());
        // Adding the additional parameters, if any
        Iterator<String> params = resource.listProperties();
        while (params.hasNext()) {
            String paramName = params.next();
            String paramValue = (String) resource.getProperty(paramName);
            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
            ref.add(refAddr);
        }
    }
    try {
        if (log.isDebugEnabled()) {
            log.debug("  Adding resource ref " + resource.getName() + "  " + ref);
        }
        createSubcontexts(envCtx, resource.getName());
        envCtx.bind(resource.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }
    if (("javax.sql.DataSource".equals(ref.getClassName()) || "javax.sql.XADataSource".equals(ref.getClassName())) && resource.getSingleton()) {
        Object actualResource = null;
        try {
            ObjectName on = createObjectName(resource);
            actualResource = envCtx.lookup(resource.getName());
            Registry.getRegistry(null, null).registerComponent(actualResource, on, null);
            objectNames.put(resource.getName(), on);
        } catch (Exception e) {
            log.warn(sm.getString("naming.jmxRegistrationFailed", e));
        }
        // further and cleans up and AutoCloseable DataSource by default.
        if (actualResource instanceof AutoCloseable && !resource.getCloseMethodConfigured()) {
            resource.setCloseMethod("close");
        }
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) ResourceRef(org.apache.naming.ResourceRef) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MalformedURLException(java.net.MalformedURLException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) ObjectName(javax.management.ObjectName)

Example 58 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class NamingContextListener method createNamingContext.

/**
 * Create and initialize the JNDI naming context.
 */
private void createNamingContext() throws NamingException {
    // Creating the comp subcontext
    if (container instanceof Server) {
        compCtx = namingContext;
        envCtx = namingContext;
    } else {
        compCtx = namingContext.createSubcontext("comp");
        envCtx = compCtx.createSubcontext("env");
    }
    int i;
    if (log.isDebugEnabled()) {
        log.debug("Creating JNDI naming context");
    }
    if (namingResources == null) {
        namingResources = new NamingResourcesImpl();
        namingResources.setContainer(container);
    }
    // Resource links
    ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
    for (i = 0; i < resourceLinks.length; i++) {
        addResourceLink(resourceLinks[i]);
    }
    // Resources
    ContextResource[] resources = namingResources.findResources();
    for (i = 0; i < resources.length; i++) {
        addResource(resources[i]);
    }
    // Resources Env
    ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
    for (i = 0; i < resourceEnvRefs.length; i++) {
        addResourceEnvRef(resourceEnvRefs[i]);
    }
    // Environment entries
    ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
    for (i = 0; i < contextEnvironments.length; i++) {
        addEnvironment(contextEnvironments[i]);
    }
    // EJB references
    ContextEjb[] ejbs = namingResources.findEjbs();
    for (i = 0; i < ejbs.length; i++) {
        addEjb(ejbs[i]);
    }
    // Message Destination References
    MessageDestinationRef[] mdrs = namingResources.findMessageDestinationRefs();
    for (i = 0; i < mdrs.length; i++) {
        addMessageDestinationRef(mdrs[i]);
    }
    // WebServices references
    ContextService[] services = namingResources.findServices();
    for (i = 0; i < services.length; i++) {
        addService(services[i]);
    }
    // Binding a User Transaction reference
    if (container instanceof Context) {
        try {
            Reference ref = new TransactionRef();
            compCtx.bind("UserTransaction", ref);
            ContextTransaction transaction = namingResources.getTransaction();
            if (transaction != null) {
                Iterator<String> params = transaction.listProperties();
                while (params.hasNext()) {
                    String paramName = params.next();
                    String paramValue = (String) transaction.getProperty(paramName);
                    StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
                    ref.add(refAddr);
                }
            }
        } catch (NameAlreadyBoundException e) {
        // Ignore because UserTransaction was obviously
        // added via ResourceLink
        } catch (NamingException e) {
            log.error(sm.getString("naming.bindFailed", e));
        }
    }
    // Binding the resources directory context
    if (container instanceof Context) {
        try {
            compCtx.bind("Resources", ((Context) container).getResources());
        } catch (NamingException e) {
            log.error(sm.getString("naming.bindFailed", e));
        }
    }
}
Also used : ContextService(org.apache.tomcat.util.descriptor.web.ContextService) Server(org.apache.catalina.Server) MessageDestinationRef(org.apache.tomcat.util.descriptor.web.MessageDestinationRef) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NamingException(javax.naming.NamingException) ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) Reference(javax.naming.Reference) ContextTransaction(org.apache.tomcat.util.descriptor.web.ContextTransaction) ContextEjb(org.apache.tomcat.util.descriptor.web.ContextEjb) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource) StringRefAddr(javax.naming.StringRefAddr) TransactionRef(org.apache.naming.TransactionRef) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)

Example 59 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class NamingContextListener method addResourceLink.

/**
 * Set the specified resource link in the naming context.
 *
 * @param resourceLink the resource link
 */
public void addResourceLink(ContextResourceLink resourceLink) {
    // Create a reference to the resource.
    Reference ref = new ResourceLinkRef(resourceLink.getType(), resourceLink.getGlobal(), resourceLink.getFactory(), null);
    Iterator<String> i = resourceLink.listProperties();
    while (i.hasNext()) {
        String key = i.next();
        Object val = resourceLink.getProperty(key);
        if (val != null) {
            StringRefAddr refAddr = new StringRefAddr(key, val.toString());
            ref.add(refAddr);
        }
    }
    javax.naming.Context ctx = "UserTransaction".equals(resourceLink.getName()) ? compCtx : envCtx;
    try {
        if (log.isDebugEnabled()) {
            log.debug("  Adding resource link " + resourceLink.getName());
        }
        createSubcontexts(envCtx, resourceLink.getName());
        ctx.bind(resourceLink.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }
    ResourceLinkFactory.registerGlobalResourceAccess(getGlobalNamingContext(), resourceLink.getName(), resourceLink.getGlobal());
}
Also used : ResourceLinkRef(org.apache.naming.ResourceLinkRef) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException)

Example 60 with StringRefAddr

use of javax.naming.StringRefAddr in project tomcat by apache.

the class DriverAdapterCPDS method getReference.

/**
 * Implements {@link Referenceable}.
 */
@Override
public Reference getReference() throws NamingException {
    // this class implements its own factory
    final String factory = getClass().getName();
    final Reference ref = new Reference(getClass().getName(), factory, null);
    ref.add(new StringRefAddr("description", getDescription()));
    ref.add(new StringRefAddr("driver", getDriver()));
    ref.add(new StringRefAddr("loginTimeout", String.valueOf(getLoginTimeout())));
    ref.add(new StringRefAddr(Constants.KEY_PASSWORD, getPassword()));
    ref.add(new StringRefAddr(Constants.KEY_USER, getUser()));
    ref.add(new StringRefAddr("url", getUrl()));
    ref.add(new StringRefAddr("poolPreparedStatements", String.valueOf(isPoolPreparedStatements())));
    ref.add(new StringRefAddr("maxIdle", String.valueOf(getMaxIdle())));
    ref.add(new StringRefAddr("numTestsPerEvictionRun", String.valueOf(getNumTestsPerEvictionRun())));
    ref.add(new StringRefAddr("maxPreparedStatements", String.valueOf(getMaxPreparedStatements())));
    // 
    // Pair of current and deprecated.
    ref.add(new StringRefAddr("durationBetweenEvictionRuns", String.valueOf(getDurationBetweenEvictionRuns())));
    ref.add(new StringRefAddr("timeBetweenEvictionRunsMillis", String.valueOf(getTimeBetweenEvictionRunsMillis())));
    // 
    // Pair of current and deprecated.
    ref.add(new StringRefAddr("minEvictableIdleDuration", String.valueOf(getMinEvictableIdleDuration())));
    ref.add(new StringRefAddr("minEvictableIdleTimeMillis", String.valueOf(getMinEvictableIdleTimeMillis())));
    return ref;
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference)

Aggregations

StringRefAddr (javax.naming.StringRefAddr)68 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 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 Iterator (java.util.Iterator)4 Context (javax.naming.Context)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 NameNotFoundException (javax.naming.NameNotFoundException)3 Context (org.apache.catalina.Context)3 NamingContext (org.apache.naming.NamingContext)3