users@glassfish.java.net

Re: Glassfish V3 + Standalone client lookup session bean JNDI

From: <glassfish_at_javadesktop.org>
Date: Fri, 21 May 2010 09:24:54 PDT

Here is the code that we use to connect from Eclipse RCP client to GFv3 (this worked fine for GFv2.1.1):


1.) First we create the properties for the InitialContext:

                final Properties props = new Properties();
            props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
            props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
            props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
            
            // Only needed if server is running on a different host than localhost:
            if (!StringUtils.isEmpty(getServer()))
                    props.setProperty("org.omg.CORBA.ORBInitialHost", getServer());
            // Optional. Defaults to 3700. Only needed if target orb port is not 3700.
            if (!StringUtils.isEmpty(getPortNumber()))
                    props.setProperty("org.omg.CORBA.ORBInitialPort", getPortNumber());


2.) then we create the InitialContext using ProgrammaticLogin for proper permission handling:

                // --------------------- <Set JAAS Config, so we don't have to read from config file> -----------------------

                Configuration.setConfiguration(new Configuration() {

                        @Override
                        public AppConfigurationEntry[] getAppConfigurationEntry(final String name) {
                                
                                final Map<String,Boolean> options = new HashMap<String, Boolean>();
                                options.put("debug", new Boolean(false));
                                
                                if ("default".equals(name))
                                        return new AppConfigurationEntry[] {new AppConfigurationEntry("com.sun.enterprise.security.auth.login.ClientPasswordLoginModule", LoginModuleControlFlag.REQUIRED, options)};
                                if ("certificate".equals(name))
                                        return new AppConfigurationEntry[] {new AppConfigurationEntry("com.sun.enterprise.security.auth.login.ClientCertificateLoginModule", LoginModuleControlFlag.REQUIRED, options)};
                                
                                throw new TTRuntimeException("New Configuration was asked for: " + name + ", but it should have been default or certificate!");
                        }

                        @Override
                        public void refresh() {
                                // we don't need to refresh anything!
                        }
                        
                });
                
                final ProgrammaticLogin pm = new ProgrammaticLogin();
                final boolean success = pm.login(getUser(), getPassword());
                if (!success)
                        log.warn("Setup of login unsuccessful!");

            try {
                        context = new InitialContext(createPropertiesExisting());
                } catch (final NamingException e) {
                        throw new TTRuntimeException("Error while logging in", e);
                }


3.) Then we execute the lookup:

                        try {
                                activityTrackerBean = (ActivityTrackerBeanRemote) context.lookup(ActivityTrackerBeanRemote.JNDIName);
                        } catch (final NamingException e) {
                                throw new RuntimeException("Error looking up ActivityTrackerBeanRemote: ", e);
                        }


JNDI Name:
ActivityTrackerBeanRemote.JNDIName
 = "java:global/com.ansis.timetracker.server/timetracker-ejb/ActivityTrackerBean"

This is written out by GFv3 at deployment as portable JNDI name.


This code works properly when executed from a unit test environment, ie. javaSE on same machine, with all GFv3/modules Jars on class path.

However, as described earlier, when running within our Eclipse plugin, it produces the above described exceptions when looking up the SECOND session bean. The order of lookup doesn't matter, the first is always looked up. When we try to lookup the second, we hit the exception.


What is the plugin architecture you are using? Could you post your structure and your MANIFEST.MF's of your plugins?
[Message sent by forum member 'ansis']

http://forums.java.net/jive/thread.jspa?messageID=470909