0 Replies Latest reply on Mar 13, 2014 7:21 AM by Govind Sukumar

    Dynamic Proxy for JBoss Initial Context EJB3

    Govind Sukumar Newbie



      We have an application which was developed for JBoss 5.1 and are in the middle of migrating from 5.1 to JBoss 6 eap and encountered the following issue.


      In Jboss 5.1, We had implemented a dynamic proxy for the InitialContext class

          //JNDI Properties...


           config.setProperty("java.naming.factory.initial", "MyInitialContextFactoryImpl");

           config.setProperty("delegate.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");


      The getInitialContext() method of MyInitialContextFactoryImpl class basically does the following.


      public Context getInitialContext(Hashtable environment) throws NamingException {

        Hashtable env = (Hashtable) environment.clone();



        env.put(Context.INITIAL_CONTEXT_FACTORY, (String) environment.get(DELEGATE_INITIAL_CONTEXT_FACTORY));


        Context context = new InitialContext(env);


        return (Context) Proxy.newProxyInstance(


        new Class[] { Context.class },

        new ProxyInitialContextInvocationHandler(context));



      private static ClassLoader getClassLoader(Class clazz) {

        ClassLoader classLoader;



        if(clazz == null) {

        classLoader = Thread.currentThread().getContextClassLoader();

        } else {

        classLoader = clazz.getClassLoader();

        if(classLoader == null) {

        classLoader = Thread.currentThread().getContextClassLoader();







        return classLoader;


      where ProxyInitialContextInvocationHandler implements InvocationHandler and Serializable.

      In the invoke method of the ProxyInitialContextInvocationHandler we were checking for the lookup method call and performing some logic.


      public class ProxyInitialContextInvocationHandler implements InvocationHandler, Serializable {


      private Context proxiedContext;


        public ProxyInitialContextInvocationHandler(Context proxiedContext) {

        this.proxiedContext = proxiedContext;




      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

           if("lookup".equals(method.getName()) {

                //Some logic


           return method.invoke(proxiedContext, args)









      All this was working fine till we started trying to migrate to JBoss 6.1 eap where we saw that the invocation handler was not being invoked for the

      context.lookup method call. (This invoke method however was being called for other method calls like context.getEnvironment() etc...).


      Is this intentionally disabled? If so is there any other way to achieve the desired result?


      Any help in this regard would be highly appreciated.


      Thanks in advance..