Search in sources :

Example 96 with NameNotFoundException

use of javax.naming.NameNotFoundException in project jetty.project by eclipse.

the class NamingEntryUtil method lookupNamingEntry.

/**
     * Find a NamingEntry in the given scope.
     *
     * @param scope the object scope
     * @param jndiName the jndi name
     * @return the naming entry for the given scope
     * @throws NamingException if unable to lookup naming entry
     */
public static NamingEntry lookupNamingEntry(Object scope, String jndiName) throws NamingException {
    NamingEntry entry = null;
    try {
        Name scopeName = getNameForScope(scope);
        InitialContext ic = new InitialContext();
        NameParser parser = ic.getNameParser("");
        Name namingEntryName = makeNamingEntryName(parser, jndiName);
        scopeName.addAll(namingEntryName);
        entry = (NamingEntry) ic.lookup(scopeName);
    } catch (NameNotFoundException ee) {
    }
    return entry;
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 97 with NameNotFoundException

use of javax.naming.NameNotFoundException in project hibernate-orm by hibernate.

the class JndiRegionFactoryTest method bind.

/**
	 * Helper method that binds the a non serializable object to the JNDI tree.
	 *
	 * @param jndiName Name under which the object must be bound
	 * @param who Object to bind in JNDI
	 * @param classType Class type under which should appear the bound object
	 * @param ctx Naming context under which we bind the object
	 * @throws Exception Thrown if a naming exception occurs during binding
	 */
private void bind(String jndiName, Object who, Class<?> classType, Context ctx) throws Exception {
    // Ah ! This service isn't serializable, so we use a helper class
    NonSerializableFactory.bind(jndiName, who);
    Name n = ctx.getNameParser("").parse(jndiName);
    while (n.size() > 1) {
        String ctxName = n.get(0);
        try {
            ctx = (Context) ctx.lookup(ctxName);
        } catch (NameNotFoundException e) {
            log.debug("creating Subcontext " + ctxName);
            ctx = ctx.createSubcontext(ctxName);
        }
        n = n.getSuffix(1);
    }
    // The helper class NonSerializableFactory uses address type nns, we go on to
    // use the helper class to bind the service object in JNDI
    StringRefAddr addr = new StringRefAddr("nns", jndiName);
    Reference ref = new Reference(classType.getName(), addr, NonSerializableFactory.class.getName(), null);
    ctx.rebind(n.get(0), ref);
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NonSerializableFactory(org.jboss.util.naming.NonSerializableFactory) Name(javax.naming.Name)

Example 98 with NameNotFoundException

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

the class NamingContext method destroySubcontext.

/**
     * Destroys the named context and removes it from the namespace. Any
     * attributes associated with the name are also removed. Intermediate
     * contexts are not destroyed.
     * <p>
     * This method is idempotent. It succeeds even if the terminal atomic
     * name is not bound in the target context, but throws
     * NameNotFoundException if any of the intermediate contexts do not exist.
     *
     * In a federated naming system, a context from one naming system may be
     * bound to a name in another. One can subsequently look up and perform
     * operations on the foreign context using a composite name. However, an
     * attempt destroy the context using this composite name will fail with
     * NotContextException, because the foreign context is not a "subcontext"
     * of the context in which it is bound. Instead, use unbind() to remove
     * the binding of the foreign context. Destroying the foreign context
     * requires that the destroySubcontext() be performed on a context from
     * the foreign context's "native" naming system.
     *
     * @param name the name of the context to be destroyed; may not be empty
     * @exception NameNotFoundException if an intermediate context does not
     * exist
     * @exception NotContextException if the name is bound but does not name
     * a context, or does not name a context of the appropriate type
     */
@Override
public void destroySubcontext(Name name) throws NamingException {
    if (!checkWritable()) {
        return;
    }
    while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1);
    if (name.isEmpty())
        throw new NamingException(sm.getString("namingContext.invalidName"));
    NamingEntry entry = bindings.get(name.get(0));
    if (entry == null) {
        throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
    }
    if (name.size() > 1) {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).destroySubcontext(name.getSuffix(1));
        } else {
            throw new NamingException(sm.getString("namingContext.contextExpected"));
        }
    } else {
        if (entry.type == NamingEntry.CONTEXT) {
            ((Context) entry.value).close();
            bindings.remove(name.get(0));
        } else {
            throw new NotContextException(sm.getString("namingContext.contextExpected"));
        }
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException)

Example 99 with NameNotFoundException

use of javax.naming.NameNotFoundException in project Smack by igniterealtime.

the class JavaxResolver method lookupSRVRecords0.

@Override
protected List<SRVRecord> lookupSRVRecords0(String name, List<HostAddress> failedAddresses, DnssecMode dnssecMode) {
    List<SRVRecord> res = null;
    Attribute srvAttribute;
    try {
        Attributes dnsLookup = dirContext.getAttributes(name, new String[] { "SRV" });
        srvAttribute = dnsLookup.get("SRV");
        if (srvAttribute == null)
            return null;
    } catch (NameNotFoundException e) {
        LOGGER.log(Level.FINEST, "No DNS SRV RR found for " + name, e);
        return null;
    } catch (NamingException e) {
        LOGGER.log(Level.WARNING, "Exception while resolving DNS SRV RR for " + name, e);
        return null;
    }
    try {
        @SuppressWarnings("unchecked") NamingEnumeration<String> srvRecords = (NamingEnumeration<String>) srvAttribute.getAll();
        res = new ArrayList<>();
        while (srvRecords.hasMore()) {
            String srvRecordString = srvRecords.next();
            String[] srvRecordEntries = srvRecordString.split(" ");
            int priority = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 4]);
            int port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 2]);
            int weight = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 3]);
            String host = srvRecordEntries[srvRecordEntries.length - 1];
            List<InetAddress> hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode);
            if (hostAddresses == null) {
                continue;
            }
            SRVRecord srvRecord = new SRVRecord(host, port, priority, weight, hostAddresses);
            res.add(srvRecord);
        }
    } catch (NamingException e) {
        LOGGER.log(Level.SEVERE, "Exception while resolving DNS SRV RR for" + name, e);
    }
    return res;
}
Also used : Attribute(javax.naming.directory.Attribute) NameNotFoundException(javax.naming.NameNotFoundException) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException) SRVRecord(org.jivesoftware.smack.util.dns.SRVRecord) InetAddress(java.net.InetAddress)

Example 100 with NameNotFoundException

use of javax.naming.NameNotFoundException in project spring-security by spring-projects.

the class JndiDnsResolverTests method testResolveServiceEntryNotExisting.

@Test(expected = DnsEntryNotFoundException.class)
public void testResolveServiceEntryNotExisting() throws Exception {
    when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NameNotFoundException("not found"));
    dnsResolver.resolveServiceEntry("wrong", "secpod.de");
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) Test(org.junit.Test)

Aggregations

NameNotFoundException (javax.naming.NameNotFoundException)168 NamingException (javax.naming.NamingException)81 InitialContext (javax.naming.InitialContext)75 Context (javax.naming.Context)71 Reference (javax.naming.Reference)40 Test (org.junit.Test)39 NotContextException (javax.naming.NotContextException)35 Name (javax.naming.Name)34 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)33 OperationNotSupportedException (javax.naming.OperationNotSupportedException)29 CompositeName (javax.naming.CompositeName)27 Binding (javax.naming.Binding)22 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)16 IOException (java.io.IOException)12 NamingContext (org.eclipse.jetty.jndi.NamingContext)12 ArrayList (java.util.ArrayList)10 InvalidNameException (javax.naming.InvalidNameException)10 Attributes (javax.naming.directory.Attributes)10 HashMap (java.util.HashMap)7