use of javax.naming.NamingException in project Activiti by Activiti.
the class JndiEmailTest method setUp.
@BeforeClass
public void setUp() {
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.provider.class", MockEmailTransport.class.getName());
props.put("mail.smtp.class", MockEmailTransport.class.getName());
props.put("mail.smtp.provider.vendor", "test");
props.put("mail.smtp.provider.version", "0.0.0");
Provider provider = new Provider(Type.TRANSPORT, "smtp", MockEmailTransport.class.getName(), "test", "1.0");
Session mailSession = Session.getDefaultInstance(props);
SimpleNamingContextBuilder builder = null;
try {
mailSession.setProvider(provider);
builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
builder.bind("java:comp/env/Session", mailSession);
} catch (NamingException e) {
logger.error("Naming error in email setup", e);
} catch (NoSuchProviderException e) {
logger.error("provider error in email setup", e);
}
}
use of javax.naming.NamingException in project OpenClinica by OpenClinica.
the class SessionManager method setupDataSource.
public void setupDataSource() {
// end remove later
try {
Context ctx = new InitialContext();
Context env = (Context) ctx.lookup("java:comp/env");
dbName = CoreResources.getField("dataBase");
if ("oracle".equals(dbName)) {
logger.debug("looking up oracle...");
ds = (DataSource) env.lookup("SQLOracle");
} else if ("postgres".equals(dbName)) {
// logger.info("looking up postgres...");
ds = (DataSource) env.lookup("SQLPostgres");
}
} catch (NamingException ne) {
ne.printStackTrace();
logger.warn("This is :" + ne.getMessage() + " when we tried to get the connection");
}
}
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