use of javax.naming.NamingException in project jetty.project by eclipse.
the class NamingEntry method unbindENC.
/**
* Unbind this NamingEntry from a java:comp/env
*/
public void unbindENC() {
try {
InitialContext ic = new InitialContext();
Context env = (Context) ic.lookup("java:comp/env");
__log.debug("Unbinding java:comp/env/" + getJndiName());
env.unbind(getJndiName());
} catch (NamingException e) {
__log.warn(e);
}
}
use of javax.naming.NamingException in project jetty.project by eclipse.
the class NamingEntryUtil method bindToENC.
/**
* Link a name in a webapp's java:/comp/evn namespace to a pre-existing
* resource. The pre-existing resource can be either in the webapp's
* naming environment, or in the container's naming environment. Webapp's
* environment takes precedence over the server's namespace.
*
* @param scope the scope of the lookup
* @param asName the name to bind as
* @param mappedName the name from the environment to link to asName
* @return true if bind success, false if not bound
* @throws NamingException if unable to bind
*/
public static boolean bindToENC(Object scope, String asName, String mappedName) throws NamingException {
if (asName == null || asName.trim().equals(""))
throw new NamingException("No name for NamingEntry");
if (mappedName == null || "".equals(mappedName))
mappedName = asName;
NamingEntry entry = lookupNamingEntry(scope, mappedName);
if (entry == null)
return false;
entry.bindToENC(asName);
return true;
}
use of javax.naming.NamingException in project tomcat by apache.
the class NamingContext method bind.
/**
* Binds a name to an object. All intermediate contexts and the target
* context (that named by all but terminal atomic component of the name)
* must already exist.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @param rebind if true, then perform a rebind (ie, overwrite)
* @exception NameAlreadyBoundException if name is already bound
* @exception javax.naming.directory.InvalidAttributesException if object
* did not supply all mandatory attributes
* @exception NamingException if a naming exception is encountered
*/
protected void bind(Name name, Object obj, boolean rebind) 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 (name.size() > 1) {
if (entry == null) {
throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type == NamingEntry.CONTEXT) {
if (rebind) {
((Context) entry.value).rebind(name.getSuffix(1), obj);
} else {
((Context) entry.value).bind(name.getSuffix(1), obj);
}
} else {
throw new NamingException(sm.getString("namingContext.contextExpected"));
}
} else {
if ((!rebind) && (entry != null)) {
throw new NameAlreadyBoundException(sm.getString("namingContext.alreadyBound", name.get(0)));
} else {
// Getting the type of the object and wrapping it within a new
// NamingEntry
Object toBind = NamingManager.getStateToBind(obj, name, this, env);
if (toBind instanceof Context) {
entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT);
} else if (toBind instanceof LinkRef) {
entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF);
} else if (toBind instanceof Reference) {
entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE);
} else if (toBind instanceof Referenceable) {
toBind = ((Referenceable) toBind).getReference();
entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE);
} else {
entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY);
}
bindings.put(name.get(0), entry);
}
}
}
use of javax.naming.NamingException in project hadoop by apache.
the class DNS method getHosts.
/**
* Returns all the host names associated by the provided nameserver with the
* address bound to the specified network interface
*
* @param strInterface
* The name of the network interface or subinterface to query
* (e.g. eth0 or eth0:0)
* @param nameserver
* The DNS host name
* @param tryfallbackResolution
* if true and if reverse DNS resolution fails then attempt to
* resolve the hostname with
* {@link InetAddress#getCanonicalHostName()} which includes
* hosts file resolution.
* @return A string vector of all host names associated with the IPs tied to
* the specified interface
* @throws UnknownHostException if the given interface is invalid
*/
public static String[] getHosts(String strInterface, @Nullable String nameserver, boolean tryfallbackResolution) throws UnknownHostException {
final List<String> hosts = new Vector<String>();
final List<InetAddress> addresses = getIPsAsInetAddressList(strInterface, true);
for (InetAddress address : addresses) {
try {
hosts.add(reverseDns(address, nameserver));
} catch (NamingException ignored) {
}
}
if (hosts.isEmpty() && tryfallbackResolution) {
for (InetAddress address : addresses) {
final String canonicalHostName = address.getCanonicalHostName();
// Don't use the result if it looks like an IP address.
if (!InetAddresses.isInetAddress(canonicalHostName)) {
hosts.add(canonicalHostName);
}
}
}
if (hosts.isEmpty()) {
LOG.warn("Unable to determine hostname for interface " + strInterface);
hosts.add(cachedHostname);
}
return hosts.toArray(new String[hosts.size()]);
}
use of javax.naming.NamingException in project hadoop by apache.
the class LdapGroupsMapping method getRelativeDistinguishedName.
/**
* A helper method to get the Relative Distinguished Name (RDN) from
* Distinguished name (DN). According to Active Directory documentation,
* a group object's RDN is a CN.
*
* @param distinguishedName A string representing a distinguished name.
* @throws NamingException if the DN is malformed.
* @return a string which represents the RDN
*/
private String getRelativeDistinguishedName(String distinguishedName) throws NamingException {
LdapName ldn = new LdapName(distinguishedName);
List<Rdn> rdns = ldn.getRdns();
if (rdns.isEmpty()) {
throw new NamingException("DN is empty");
}
Rdn rdn = rdns.get(rdns.size() - 1);
if (rdn.getType().equalsIgnoreCase(groupNameAttr)) {
String groupName = (String) rdn.getValue();
return groupName;
}
throw new NamingException("Unable to find RDN: The DN " + distinguishedName + " is malformed.");
}
Aggregations