Search in sources :

Example 56 with DirContext

use of javax.naming.directory.DirContext in project Payara by payara.

the class StandardContext method listCollectionPaths.

/**
 * List resource paths (recursively), and store all of them in the given
 * Set.
 */
private static void listCollectionPaths(Set<String> set, DirContext resources, String path) throws NamingException {
    Enumeration<Binding> childPaths = resources.listBindings(path);
    while (childPaths.hasMoreElements()) {
        Binding binding = childPaths.nextElement();
        String name = binding.getName();
        StringBuilder childPath = new StringBuilder(path);
        if (!"/".equals(path) && !path.endsWith("/"))
            childPath.append("/");
        childPath.append(name);
        Object object = binding.getObject();
        if (object instanceof DirContext && childPath.charAt(childPath.length() - 1) != '/') {
            childPath.append("/");
        }
        set.add(childPath.toString());
    }
}
Also used : Binding(javax.naming.Binding) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) WebDirContext(org.apache.naming.resources.WebDirContext) FileDirContext(org.apache.naming.resources.FileDirContext)

Example 57 with DirContext

use of javax.naming.directory.DirContext in project Payara by payara.

the class StandardContext method alternateResourcesStop.

/**
 * Stops this context's alternate doc base resources.
 */
public boolean alternateResourcesStop() {
    boolean ok = true;
    if (alternateDocBases == null || alternateDocBases.isEmpty()) {
        return ok;
    }
    for (AlternateDocBase alternateDocBase : alternateDocBases) {
        final DirContext alternateResources = ContextsAdapterUtility.unwrap(alternateDocBase.getResources());
        if (alternateResources instanceof Lifecycle) {
            try {
                ((Lifecycle) alternateResources).stop();
            } catch (Throwable t) {
                log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
                ok = false;
            }
        }
        final DirContext alternateWebappResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
        if (alternateWebappResources instanceof BaseDirContext) {
            try {
                ((BaseDirContext) alternateWebappResources).release();
            } catch (Throwable t) {
                log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
                ok = false;
            }
        }
    }
    this.alternateDocBases = null;
    return (ok);
}
Also used : AlternateDocBase(org.glassfish.grizzly.http.server.util.AlternateDocBase) Lifecycle(org.apache.catalina.Lifecycle) BaseDirContext(org.apache.naming.resources.BaseDirContext) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) WebDirContext(org.apache.naming.resources.WebDirContext) FileDirContext(org.apache.naming.resources.FileDirContext)

Example 58 with DirContext

use of javax.naming.directory.DirContext in project Payara by payara.

the class StandardContext method alternateResourcesStart.

/**
 * Starts this context's alternate doc base resources.
 */
public void alternateResourcesStart() throws LifecycleException {
    if (alternateDocBases == null || alternateDocBases.isEmpty()) {
        return;
    }
    Hashtable<String, String> env = new Hashtable<String, String>();
    if (getParent() != null) {
        env.put(ProxyDirContext.HOST, getParent().getName());
    }
    env.put(ProxyDirContext.CONTEXT, getName());
    for (AlternateDocBase alternateDocBase : alternateDocBases) {
        String basePath = alternateDocBase.getBasePath();
        DirContext alternateWebappResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
        try {
            ProxyDirContext proxyDirContext = new ProxyDirContext(env, alternateWebappResources);
            if (alternateWebappResources instanceof BaseDirContext) {
                ((BaseDirContext) alternateWebappResources).setDocBase(basePath);
                ((BaseDirContext) alternateWebappResources).allocate();
            }
            alternateDocBase.setResources(ContextsAdapterUtility.wrap(proxyDirContext));
        } catch (Throwable t) {
            if (log.isLoggable(Level.FINE)) {
                String msg = MessageFormat.format(rb.getString(LogFacade.STARTING_RESOURCES_EXCEPTION), getName());
                throw new LifecycleException(msg, t);
            } else {
                String msg = MessageFormat.format(rb.getString(LogFacade.STARTING_RESOURCE_EXCEPTION_MESSAGE), new Object[] { getName(), t.getMessage() });
                throw new LifecycleException(msg);
            }
        }
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) AlternateDocBase(org.glassfish.grizzly.http.server.util.AlternateDocBase) Hashtable(java.util.Hashtable) BaseDirContext(org.apache.naming.resources.BaseDirContext) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) WebDirContext(org.apache.naming.resources.WebDirContext) FileDirContext(org.apache.naming.resources.FileDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext)

Example 59 with DirContext

use of javax.naming.directory.DirContext in project Payara by payara.

the class StandardContext method setResources.

/**
 * Set the resources DirContext object with which this Container is
 * associated.
 *
 * @param resources The newly associated DirContext
 */
@Override
public synchronized void setResources(DirContext resources) {
    if (started) {
        throw new IllegalStateException(rb.getString(LogFacade.RESOURCES_STARTED));
    }
    DirContext oldResources = this.webappResources;
    if (oldResources == resources)
        return;
    if (resources instanceof BaseDirContext) {
        BaseDirContext baseDirContext = (BaseDirContext) resources;
        baseDirContext.setCached(isCachingAllowed());
        baseDirContext.setCacheTTL(getCacheTTL());
        baseDirContext.setCacheMaxSize(getCacheMaxSize());
    }
    if (resources instanceof FileDirContext) {
        filesystemBased = true;
        FileDirContext fileDirContext = (FileDirContext) resources;
        fileDirContext.setCaseSensitive(isCaseSensitive());
        fileDirContext.setAllowLinking(isAllowLinking());
    }
    this.webappResources = resources;
    // The proxied resources will be refreshed on start
    this.resources = null;
    support.firePropertyChange("resources", oldResources, this.webappResources);
}
Also used : FileDirContext(org.apache.naming.resources.FileDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) WebDirContext(org.apache.naming.resources.WebDirContext) FileDirContext(org.apache.naming.resources.FileDirContext)

Example 60 with DirContext

use of javax.naming.directory.DirContext in project Payara by payara.

the class ProxyDirContext method createSubcontext.

/**
 * Creates and binds a new context, along with associated attributes.
 * This method creates a new subcontext with the given name, binds it in
 * the target context (that named by all but terminal atomic component of
 * the name), and associates the supplied attributes with the newly
 * created object. All intermediate and target contexts must already
 * exist. If attrs is null, this method is equivalent to
 * Context.createSubcontext().
 *
 * @param name the name of the context to create; may not be empty
 * @param attrs the attributes to associate with the newly created context
 * @return the newly created context
 * @exception javax.naming.NameAlreadyBoundException if the name is already
 * bound
 * @exception javax.naming.directory.InvalidAttributesException if attrs
 * does not contain all the mandatory attributes required for creation
 * @exception NamingException if a naming exception is encountered
 */
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
    DirContext context = dirContext.createSubcontext(parseName(name), attrs);
    cacheUnload(name.toString());
    return context;
}
Also used : DirContext(javax.naming.directory.DirContext)

Aggregations

DirContext (javax.naming.directory.DirContext)111 NamingException (javax.naming.NamingException)51 InitialDirContext (javax.naming.directory.InitialDirContext)43 SearchResult (javax.naming.directory.SearchResult)27 SearchControls (javax.naming.directory.SearchControls)24 Attributes (javax.naming.directory.Attributes)21 Attribute (javax.naming.directory.Attribute)17 IOException (java.io.IOException)16 NamingEnumeration (javax.naming.NamingEnumeration)16 Hashtable (java.util.Hashtable)14 Test (org.junit.Test)14 DistinguishedName (org.springframework.ldap.core.DistinguishedName)11 ProxyDirContext (org.apache.naming.resources.ProxyDirContext)10 WebDirContext (org.apache.naming.resources.WebDirContext)9 ArrayList (java.util.ArrayList)8 BaseDirContext (org.apache.naming.resources.BaseDirContext)8 FileDirContext (org.apache.naming.resources.FileDirContext)8 WARDirContext (org.apache.naming.resources.WARDirContext)8 Name (javax.naming.Name)7 BasicAttribute (javax.naming.directory.BasicAttribute)7