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