use of javax.naming.NamingException in project ACS by ACS-Community.
the class JNDIContext method lookup.
/**
* @see Context#lookup(Name)
* THIS IS OLD CDB implementation
public Object lookup(Name name) throws NamingException {
//System.out.println("CDBContext lookup on " + this.name + " for " + name.toString());
String nameToLookup = this.name + "/" + name;
String recordName = nameToLookup.substring(nameToLookup.lastIndexOf('/')+1);
// get list from the server
String elements = dal.list_nodes(nameToLookup);
try {
if (elements.indexOf(recordName + ".xml") != -1) {
String xml = dal.get_DAO(nameToLookup);
return new JNDIXMLContext(nameToLookup, elements, xml);
} else {
if (elements.length() == 0 ) { // inside a XML?
int slashIndex = nameToLookup.lastIndexOf('/');
String newName;
while( slashIndex != -1 ) {
newName = nameToLookup.substring(0,slashIndex);
recordName = newName.substring(newName.lastIndexOf('/')+1);
elements = dal.list_nodes(newName);
if (elements.indexOf(recordName + ".xml") != -1) {
String xml = dal.get_DAO(newName);
recordName = nameToLookup.substring(slashIndex+1);
return new JNDIXMLContext(newName, elements, xml).lookup(recordName);
}
slashIndex = newName.lastIndexOf('/');
}
throw new NamingException("No name " + nameToLookup );
}
return new JNDIContext(nameToLookup, elements);
}
} catch (CDBRecordDoesNotExistEx e) {
// if it does not exists then it is just a context
return new JNDIContext(nameToLookup, elements);
} catch (CDBXMLErrorEx e) {
AcsJCDBXMLErrorEx acse = new AcsJCDBXMLErrorEx(e);
throw new NamingException(acse.getFilename());
}
}*/
/**
* This methos returns either a new JNDI_Context or a new JNDI_XMLContxt obj.
*/
public Object lookup(Name name) throws NamingException {
final String lookupName = name.toString();
final String fullLookupName = this.name + "/" + lookupName;
String daoElements = dal.list_daos(fullLookupName);
if (daoElements.length() == 0)
daoElements = null;
// is subnode
StringTokenizer token = new StringTokenizer(elements);
while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
// is DAO?
if (daoElements != null) {
try {
return new JNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
} catch (CDBXMLErrorEx th) {
AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
ex2.setRootCause(jex);
throw ex2;
} catch (Throwable th) {
throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
}
} else
return new JNDIContext(fullLookupName, dal.list_nodes(fullLookupName), logger);
}
if (daoElements != null) {
// lookup in DAO
token = new StringTokenizer(daoElements);
while (token.hasMoreTokens()) if (token.nextElement().equals(lookupName)) {
try {
return new JNDIXMLContext(fullLookupName, dal.list_nodes(fullLookupName), dal.get_DAO(fullLookupName), logger);
} catch (CDBXMLErrorEx th) {
AcsJCDBXMLErrorEx jex = AcsJCDBXMLErrorEx.fromCDBXMLErrorEx(th);
NamingException ex2 = new NamingException(jex.getFilename() + ": " + jex.getErrorString());
ex2.setRootCause(jex);
throw ex2;
} catch (Throwable th) {
throw new NamingException("Failed to retrieve DAO: " + fullLookupName);
}
}
}
// not found
throw new NamingException("No name " + fullLookupName);
}
use of javax.naming.NamingException in project Activiti by Activiti.
the class LDAPUserManager method findUserByQueryCriteria.
@Override
public List<User> findUserByQueryCriteria(final UserQueryImpl query, final Page page) {
if (query.getId() != null) {
List<User> result = new ArrayList<User>();
result.add(findUserById(query.getId()));
return result;
} else if (query.getFullNameLike() != null) {
final String fullNameLike = query.getFullNameLike().replaceAll("%", "");
LDAPTemplate ldapTemplate = new LDAPTemplate(ldapConfigurator);
return ldapTemplate.execute(new LDAPCallBack<List<User>>() {
public List<User> executeInContext(InitialDirContext initialDirContext) {
List<User> result = new ArrayList<User>();
try {
String searchExpression = ldapConfigurator.getLdapQueryBuilder().buildQueryByFullNameLike(ldapConfigurator, fullNameLike);
String baseDn = ldapConfigurator.getUserBaseDn() != null ? ldapConfigurator.getUserBaseDn() : ldapConfigurator.getBaseDn();
NamingEnumeration<?> namingEnum = initialDirContext.search(baseDn, searchExpression, createSearchControls());
while (namingEnum.hasMore()) {
SearchResult searchResult = (SearchResult) namingEnum.next();
UserEntity user = new UserEntity();
mapSearchResultToUser(searchResult, user);
result.add(user);
}
namingEnum.close();
} catch (NamingException ne) {
logger.debug("Could not execute LDAP query: " + ne.getMessage(), ne);
return null;
}
return result;
}
});
} else {
throw new ActivitiIllegalArgumentException("Query is currently not supported by LDAPUserManager.");
}
}
use of javax.naming.NamingException in project opennms by OpenNMS.
the class JBossMBeanServerConnector method createConnection.
@Override
public JmxServerConnectionWrapper createConnection(final InetAddress ipAddress, final Map<String, String> propertiesMap) throws JmxServerConnectionException {
JBossConnectionWrapper wrapper = null;
ClassLoader icl = null;
final ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
String connectionType = ParameterMap.getKeyedString(propertiesMap, "factory", "RMI");
String timeout = ParameterMap.getKeyedString(propertiesMap, "timeout", "3000");
String jbossVersion = ParameterMap.getKeyedString(propertiesMap, "version", "4");
String port = ParameterMap.getKeyedString(propertiesMap, "port", "1099");
if (jbossVersion == null || jbossVersion.startsWith("4")) {
try {
icl = new IsolatingClassLoader("jboss", new URL[] { new File(System.getProperty("opennms.home") + "/lib/jboss/jbossall-client.jar").toURI().toURL() }, originalLoader, PACKAGES, true);
} catch (MalformedURLException e) {
LOG.error("JBossConnectionWrapper MalformedURLException", e);
} catch (InvalidContextClassLoaderException e) {
LOG.error("JBossConnectionWrapper InvalidContextClassLoaderException", e);
}
} else if (jbossVersion.startsWith("3")) {
PrivilegedAction<IsolatingClassLoader> action = new PrivilegedAction<IsolatingClassLoader>() {
@Override
public IsolatingClassLoader run() {
try {
return new IsolatingClassLoader("jboss", new URL[] { new File(System.getProperty("opennms.home") + "/lib/jboss/jbossall-client32.jar").toURI().toURL() }, originalLoader, PACKAGES, true);
} catch (MalformedURLException e) {
LOG.error("JBossConnectionWrapper MalformedURLException", e);
} catch (InvalidContextClassLoaderException e) {
LOG.error("JBossConnectionWrapper InvalidContextClassLoaderException", e);
}
return null;
}
};
AccessController.doPrivileged(action);
}
if (icl == null) {
return null;
}
Thread.currentThread().setContextClassLoader(icl);
if (connectionType.equals("RMI")) {
InitialContext ctx = null;
final String hostAddress = InetAddressUtils.toUrlIpAddress(ipAddress);
try {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
props.put(Context.PROVIDER_URL, "jnp://" + hostAddress + ":" + port);
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
props.put("jnp.sotimeout", timeout);
ctx = new InitialContext(props);
Object rmiAdaptor = ctx.lookup("jmx/rmi/RMIAdaptor");
wrapper = new JBossConnectionWrapper(MBeanServerProxy.buildServerProxy(rmiAdaptor));
} catch (Throwable e) {
LOG.debug("JBossConnectionFactory - unable to get MBeanServer using RMI on {}:{}", hostAddress, port);
} finally {
try {
if (ctx != null) {
ctx.close();
}
} catch (Throwable e1) {
LOG.debug("JBossConnectionFactory error closing initial context");
}
}
} else if (connectionType.equals("HTTP")) {
InitialContext ctx = null;
String invokerSuffix = null;
final String hostAddress = InetAddressUtils.toUrlIpAddress(ipAddress);
try {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
props.put(Context.PROVIDER_URL, "http://" + hostAddress + ":" + port + "/invoker/JNDIFactory");
props.put("jnp.sotimeout", timeout);
ctx = new InitialContext(props);
Object rmiAdaptor = ctx.lookup("jmx/rmi/RMIAdaptor");
wrapper = new JBossConnectionWrapper(MBeanServerProxy.buildServerProxy(rmiAdaptor));
} catch (Throwable e) {
LOG.debug("JBossConnectionFactory - unable to get MBeanServer using HTTP on {}{}", hostAddress, invokerSuffix);
} finally {
try {
if (ctx != null)
ctx.close();
} catch (NamingException e1) {
LOG.debug("JBossConnectionFactory error closing initial context");
}
}
}
Thread.currentThread().setContextClassLoader(originalLoader);
return wrapper;
}
use of javax.naming.NamingException in project jdk8u_jdk by JetBrains.
the class IPv6NameserverPlatformParsingTest method main.
public static void main(String[] args) {
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, com.sun.jndi.dns.DnsContextFactory.class.getName());
String[] servers;
try {
Context ctx = NamingManager.getInitialContext(env);
if (!com.sun.jndi.dns.DnsContextFactory.platformServersAvailable()) {
throw new RuntimeException("FAIL: no platform servers available, test does not make sense");
}
DnsContext context = (DnsContext) ctx;
servers = getServersFromContext(context);
} catch (NamingException e) {
throw new RuntimeException(e);
}
for (String server : servers) {
System.out.println("DEBUG: 'nameserver = " + server + "'");
if (server.indexOf(':') >= 0 && server.indexOf('.') < 0) {
System.out.println("DEBUG: ==> Found IPv6 address in servers list: " + server);
foundIPv6 = true;
}
}
try {
new com.sun.jndi.dns.DnsClient(servers, 100, 1);
} catch (NumberFormatException e) {
throw new RuntimeException("FAIL: Tried to parse non-[]-encapsulated IPv6 address.", e);
} catch (Exception e) {
throw new RuntimeException("ERROR: Something unexpected happened.");
}
if (!foundIPv6) {
// platforms. See comment as to how to run this test.
throw new RuntimeException("ERROR: No IPv6 address returned from platform.");
}
System.out.println("PASS: Found IPv6 address and DnsClient parsed it correctly.");
}
use of javax.naming.NamingException in project jersey by jersey.
the class EjbComponentProvider method lookupFullyQualifiedForm.
private static Object lookupFullyQualifiedForm(InitialContext ic, Class<?> c, String name, EjbComponentProvider provider) throws NamingException {
if (provider.libNames.isEmpty()) {
String jndiName = "java:module/" + name + "!" + c.getName();
return ic.lookup(jndiName);
} else {
NamingException ne = null;
for (String moduleName : provider.libNames) {
String jndiName = "java:app/" + moduleName + "/" + name + "!" + c.getName();
Object result;
try {
result = ic.lookup(jndiName);
if (result != null) {
return result;
}
} catch (NamingException e) {
ne = e;
}
}
throw (ne != null) ? ne : new NamingException();
}
}
Aggregations