7 Replies Latest reply on Feb 22, 2013 1:37 AM by pmm

    ExternalContext in AS7?


      We're currently using an ExternalContextMBean as described on the Wiki to load a serialized JNDI context. Does this work in AS7?


      I assume I need modules for the Sun JNDI classes (RefFSContextFactory) and friends. Is there some place I can get them? If the serialized JNDI context also contains other serialized classes, does it work if I have modules for them as well?

        • 1. Re: ExternalContext in AS7?


          • 2. Re: ExternalContext in AS7?

            I have the same problem while proting my configuration from JBoss 6.1 to JBoss 7.1. I have configured the JNDI connection to LDAP. Does the configuration still work

            with AS 7 or by which means can it be replaced?



            • 3. Re: ExternalContext in AS7?

              To answer my own question:

              • even though org.jboss.system.ServiceMBean and org.jboss.system.ServiceMBeanSupport are gone SARs are still supproted so in theory it could be ported to AS7
              • however the JNDI context is read-only in AS7 so this won't work
              • I'm now looking into creating programatic JNDI bindings
              • 4. Re: ExternalContext in AS7?

                Hi Philippe,


                We'ere currently migrating from JBoss 4.2.3 to JBoss AS7 and are using ExternalContexts. Do you have an example on how to replace a <mbean code="org.jboss.naming.ExternalContext"...>?

                Is there any way to avoid programatic JNDI bindings and initialize a remote context at startup?


                Basically I'm trying to avoid having to define and create and InitialContext for remote ejbs calls (on another server) . For example:


                  Properties properties = new Properties();

                  properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                  properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                  properties.put("jnp.socket.Factory", "org.jnp.interfaces.TimedSocketFactory");

                  properties.setProperty("java.naming.provider.url", "jnp://"+ otherhost +":"+port);

                  InvestorService remoteBean = (InvestorService) new InitialContext(properties).lookup("investor-service/InvestorService/remote");



                Can "investor-service" be added to the jndi context so it is already available?



                • 5. Re: ExternalContext in AS7?

                  Hello Holger,


                  yes something like that is poosible.


                  You have to Implement the Interface "javax.naming.spi.ObjectFactory", put it as module in the "modules" folder of JBoss and then you have to register this class(es) in the standalone.xml/domain.xml:





                  I found how to do it here: http://middlewaremagic.com/jboss/?p=1690


                  Good luck;-)


                  • 6. Re: ExternalContext in AS7?

                    Hi Jochen,


                    Thanks for the link. I've created an ObjectFactory which initializes the external context to do remote ejb lookups. Is there any way to integrate/bind this external context so I can do lookups such as:



                      private InvestorService investorService;


                    Here's my ObjectFactory code:


                    public class JBoss4InitialContext implements ObjectFactory {

                              private static final Log LOG = LogFactory.getLog(JBoss4InitialContext.class);

                              private InitialContext context;



                              public JBoss4InitialContext() throws NamingException {

                                        LOG.info("Initializing JBoss4InitialContext");

                                        String host = "localhost";

                                        String port = "10399";

                                        Properties properties = new Properties();

                                        properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                                        properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                                        properties.put("jnp.socket.Factory", "org.jnp.interfaces.TimedSocketFactory");

                                        properties.setProperty("java.naming.provider.url", "jnp://" + host + ":" + port);

                                        context = new InitialContext(properties);





                              public Object getObjectInstance(Object obj, Name name, Context nameCtx,

                                                  Hashtable<?, ?> environment) throws Exception {

                                        Object result = context.lookup(name);

                                        return result;







                    • 7. Re: ExternalContext in AS7?

                      To which version of JBoss AS 7 are you migrating? JBoss AS 7.2 again has full mbean support like previous versions. I don't know whether this is also available in JBoss AS 7.1.3. In the end we ended up putting the JNDI code from ExternalContextMBean into a resource adapter because that's a portable solution.