JNDIContext implements InitialContextFactory, Context { @Override public Context getInitialContext(final Hashtable environment) throws NamingException { if (environment == null) { throw new NamingException("Invalid argument, hashtable cannot be null."); } else { env = (Hashtable) environment.clone(); } final String userID = (String) env.get(Context.SECURITY_PRINCIPAL); final String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS); String providerUrl = (String) env.get(Context.PROVIDER_URL); moduleId = (String) env.get("openejb.client.moduleId"); final URI location; try { providerUrl = addMissingParts(providerUrl); location = new URI(providerUrl); } catch (URISyntaxException e) { throw (ConfigurationException) new ConfigurationException("Property value for " + Context.PROVIDER_URL + " invalid: " + providerUrl + " - " + e.getMessage()).initCause(e); } this.server = new ServerMetaData(location); final Client.Context context = Client.getContext(this.server); context.getProperties().putAll(environment); final String strategy = context.getOptions().get("openejb.client.connection.strategy", "default"); context.getClusterMetaData().setConnectionStrategy(strategy); Client.fireEvent(new RemoteInitialContextCreated(location)); if (userID != null) { authenticate(userID, psswrd); } else { client = new ClientMetaData(); } return this; } JNDIContext();  JNDIContext(final JNDIContext that); @Override Context getInitialContext(final Hashtable environment); void authenticate(final String userID, final String psswrd); EJBHomeProxy createEJBHomeProxy(final EJBMetaDataImpl ejbData); @Override Object lookup(String name); @Override Object lookup(final Name name); @SuppressWarnings("unchecked") @Override NamingEnumeration<NameClassPair> list(String name); @Override NamingEnumeration<NameClassPair> list(final Name name); @SuppressWarnings("unchecked") @Override NamingEnumeration<Binding> listBindings(final String name); @Override NamingEnumeration<Binding> listBindings(final Name name); @Override Object lookupLink(final String name); @Override Object lookupLink(final Name name); @Override NameParser getNameParser(final String name); @Override NameParser getNameParser(final Name name); @Override String composeName(final String name, final String prefix); @Override Name composeName(final Name name, final Name prefix); @SuppressWarnings("unchecked") @Override Object addToEnvironment(final String key, final Object value); @Override Object removeFromEnvironment(final String key); @Override Hashtable getEnvironment(); @Override String getNameInNamespace(); @Override void close(); @Override void bind(final String name, final Object obj); @Override void bind(final Name name, final Object obj); @Override void rebind(final String name, final Object obj); @Override void rebind(final Name name, final Object obj); @Override void unbind(final String name); @Override void unbind(final Name name); @Override void rename(final String oldname, final String newname); @Override void rename(final Name oldname, final Name newname); @Override void destroySubcontext(final String name); @Override void destroySubcontext(final Name name); @Override Context createSubcontext(final String name); @Override Context createSubcontext(final Name name); static final String DEFAULT_PROVIDER_URL; }
@Test public void testGetInitialContext() throws Exception { final int port = Integer.parseInt(System.getProperty("ejbd.port", "4201")); final JNDIContext jndiContext = new JNDIContext(); final Hashtable<String, String> env = new Hashtable<String, String>(); assertEquals(jndiContext, "ejbd: assertEquals(jndiContext, "http: assertEquals(jndiContext, "anything: assertEquals(jndiContext, " assertEquals(jndiContext, "localhost", "ejbd: assertEquals(jndiContext, "localhost:" + port, "ejbd: assertEquals(jndiContext, "", "ejbd: assertEquals(jndiContext, "ejbd: assertEquals(jndiContext, "http: assertEquals(jndiContext, "anything: assertEquals(jndiContext, " assertEquals(jndiContext, "127.0.0.1", "ejbd: assertEquals(jndiContext, "127.0.0.1:" + port, "ejbd: }