Search in sources :

Example 71 with InitialContext

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;
}
Also used : InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) CommunicationException(javax.naming.CommunicationException)

Example 72 with InitialContext

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>");
}
Also used : Status(org.compiere.interfaces.Status) Server(org.compiere.interfaces.Server) Connection(java.sql.Connection) NamingEnumeration(javax.naming.NamingEnumeration) DatabaseMetaData(java.sql.DatabaseMetaData) InitialContext(javax.naming.InitialContext) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) DataSource(javax.sql.DataSource)

Example 73 with InitialContext

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;
}
Also used : NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 74 with InitialContext

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));
}
Also used : Hashtable(java.util.Hashtable) BundleMock(org.apache.aries.mocks.BundleMock) Skeleton(org.apache.aries.unittest.mocks.Skeleton) Properties(java.util.Properties) MethodCall(org.apache.aries.unittest.mocks.MethodCall) InitialContext(javax.naming.InitialContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 75 with InitialContext

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();
}
Also used : BundleMock(org.apache.aries.mocks.BundleMock) Properties(java.util.Properties) MethodCall(org.apache.aries.unittest.mocks.MethodCall) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

InitialContext (javax.naming.InitialContext)1068 Test (org.junit.Test)325 EJBException (javax.ejb.EJBException)228 Properties (java.util.Properties)213 Context (javax.naming.Context)194 RemoteException (java.rmi.RemoteException)173 TestFailureException (org.apache.openejb.test.TestFailureException)172 NamingException (javax.naming.NamingException)168 AssertionFailedError (junit.framework.AssertionFailedError)168 JMSException (javax.jms.JMSException)167 RemoveException (javax.ejb.RemoveException)66 CreateException (javax.ejb.CreateException)57 DataSource (javax.sql.DataSource)55 Hashtable (java.util.Hashtable)54 Assembler (org.apache.openejb.assembler.classic.Assembler)47 EjbJar (org.apache.openejb.jee.EjbJar)41 NameNotFoundException (javax.naming.NameNotFoundException)40 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)38 Connection (java.sql.Connection)37 StatelessBean (org.apache.openejb.jee.StatelessBean)30