use of javax.naming.InitialContext in project adempiere by adempiere.
the class CConnection method getInitialContext.
/**
* Get Application Server Initial Context
* @param useCache if true, use existing cache
* @return Initial Context or null
*/
public InitialContext getInitialContext(boolean useCache) {
if (useCache && m_iContext != null)
return m_iContext;
// Set Environment
if (m_env == null || !useCache) {
SecurityPrincipal sp = (SecurityPrincipal) Env.getCtx().get(SECURITY_PRINCIPAL);
String principal = sp != null ? sp.principal : null;
String credential = sp != null ? sp.credential : null;
m_env = getInitialEnvironment(getAppsHost(), getAppsPort(), false, principal, credential);
}
String connect = (String) m_env.get(Context.PROVIDER_URL);
Env.setContext(Env.getCtx(), Context.PROVIDER_URL, connect);
// Get Context
m_iContext = null;
try {
m_iContext = new InitialContext(m_env);
} catch (Exception ex) {
m_okApps = false;
m_appsException = ex;
if (connect == null)
connect = (String) m_env.get(Context.PROVIDER_URL);
log.severe(connect + "\n - " + ex.toString() + "\n - " + m_env);
if (CLogMgt.isLevelFinest())
ex.printStackTrace();
}
return m_iContext;
}
use of javax.naming.InitialContext in project adempiere by adempiere.
the class StatusInfo method doGet.
/**
* Get
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Status Info</title></head>");
out.println("<body>");
InitialContext context = null;
try {
context = new InitialContext();
} catch (Exception ex) {
out.println("<p><b>" + ex + "</b></p>");
}
try {
Status status = (Status) context.lookup(Status.JNDI_NAME);
out.println("<p>" + status.getStatus() + "</p>");
} catch (Exception ex) {
out.println("<p><b>" + ex + "</b></p>");
}
try {
Server server = (Server) context.lookup(Server.JNDI_NAME);
out.println("<p>" + server.getStatus() + "</p>");
} catch (Exception ex) {
out.println("<p><b>" + ex + "</b></p>");
}
try {
out.println("<h2>-- /</h2>");
NamingEnumeration ne = context.list("/");
while (ne.hasMore()) out.println("<br> " + ne.nextElement());
out.println("<h2>-- java</h2>");
ne = context.list("java:");
while (ne.hasMore()) out.println("<br> " + ne.nextElement());
out.println("<h2>-- ejb</h2>");
ne = context.list("ejb");
while (ne.hasMore()) out.println("<br> " + ne.nextElement());
//
out.println("<h2>-- DS</h2>");
DataSource ds = (DataSource) context.lookup("java:/OracleDS");
out.println("<br> DataSource " + ds.getClass().getName() + " LoginTimeout=" + ds.getLoginTimeout());
Connection con = ds.getConnection("adempiere", "adempiere");
out.println("<br> Connection ");
getServletContext().log("Connection closed=" + con.isClosed());
DatabaseMetaData dbmd = con.getMetaData();
getServletContext().log("DB " + dbmd.getDatabaseProductName());
getServletContext().log("DB V " + dbmd.getDatabaseProductVersion());
getServletContext().log("Driver " + dbmd.getDriverName());
getServletContext().log("Driver V " + dbmd.getDriverVersion());
getServletContext().log("JDBC " + dbmd.getJDBCMajorVersion());
getServletContext().log("JDBC mV " + dbmd.getJDBCMinorVersion());
getServletContext().log("User " + dbmd.getUserName());
getServletContext().log("ANSI 92 " + dbmd.supportsANSI92FullSQL());
getServletContext().log("Connection Alter Table ADD" + dbmd.supportsAlterTableWithAddColumn());
getServletContext().log("Connection Alter Table DROP " + dbmd.supportsAlterTableWithDropColumn());
getServletContext().log("Connection DDL&DML " + dbmd.supportsDataDefinitionAndDataManipulationTransactions());
getServletContext().log("Connection CatalogsIn DML " + dbmd.supportsCatalogsInDataManipulation());
getServletContext().log("Connection Schema In DML " + dbmd.supportsSchemasInDataManipulation());
con.close();
} catch (Exception e) {
out.println("<p><b>" + e + "</b></p>");
}
out.println("</body></html>");
}
use of javax.naming.InitialContext in project adempiere by adempiere.
the class Ini method getAdempiereHome.
// isLoaded
/**
* Get Adempiere Home from Environment
* @return AdempiereHome or null
*/
public static String getAdempiereHome() {
String env = System.getProperty(ENV_PREFIX + ADEMPIERE_HOME);
if (env == null)
env = System.getProperty(ADEMPIERE_HOME);
if (env == null && !isClient()) {
InitialContext context;
try {
context = new InitialContext();
env = (String) context.lookup("java:comp/env/" + ADEMPIERE_HOME);
} catch (NamingException e) {
// teo_sarca: if you uncomment the line below you will get an NPE when generating models
//log.fine( "Not found 'java:comp/env/"+ADEMPIERE_HOME+"' in Initial Context. " +e.getMessage());
}
}
if (// Fallback
env == null || "".equals(env))
env = File.separator + "Adempiere";
return env;
}
use of javax.naming.InitialContext in project aries by apache.
the class ServiceRegistryContextTest method simpleJNDILookup.
/**
* This test does a simple JNDI lookup to prove that works.
* @throws NamingException
*/
@Test
public void simpleJNDILookup() throws NamingException {
System.setProperty(Context.URL_PKG_PREFIXES, "helloMatey");
InitialContext ctx = new InitialContext(new Hashtable<Object, Object>());
BundleMock mock = new BundleMock("scooby.doo.1", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
Runnable s = (Runnable) ctx.lookup("osgi:service/java.lang.Runnable");
assertNotNull("We didn't get a service back from our lookup :(", s);
s.run();
Skeleton.getSkeleton(service).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
Skeleton skel = Skeleton.getSkeleton(mock.getBundleContext());
skel.assertCalled(new MethodCall(BundleContext.class, "getServiceReferences", "java.lang.Runnable", null));
ctx = new InitialContext(new Hashtable<Object, Object>());
mock = new BundleMock("scooby.doo.2", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
s = (Runnable) ctx.lookup("osgi:service/java.lang.Runnable");
// Check we have the packages set correctly
String packages = System.getProperty(Context.URL_PKG_PREFIXES, null);
assertTrue(ctx.getEnvironment().containsValue(packages));
assertNotNull("We didn't get a service back from our lookup :(", s);
s.run();
Skeleton.getSkeleton(service).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 2);
skel = Skeleton.getSkeleton(mock.getBundleContext());
skel.assertCalled(new MethodCall(BundleContext.class, "getServiceReferences", "java.lang.Runnable", null));
}
use of javax.naming.InitialContext in project aries by apache.
the class ServiceRegistryContextTest method checkProxyWhenServiceGoes.
@Test(expected = ServiceException.class)
public void checkProxyWhenServiceGoes() throws ServiceException, NamingException {
BundleMock mock = new BundleMock("scooby.doo", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
InitialContext ctx = new InitialContext();
Runnable r = (Runnable) ctx.lookup("osgi:service/java.lang.Runnable");
r.run();
Skeleton.getSkeleton(service).assertCalled(new MethodCall(Runnable.class, "run"));
reg.unregister();
r.run();
}
Aggregations