1 Reply Latest reply on Feb 15, 2014 1:25 PM by Eduardo Martins

    InitialContext.rebind() throws UnsupportedOperationException

    Ali Cheaito Newbie

      The code below throws an UnsupportedOperationException (JBAS011859: Naming context is read-only) during deployment on Wildfly 8.0.0.Final. This same code was working fine under jBoss EAP 6.0.1. 

       

       

      @Startup
      @Singleton
      public class StartupBean {
      
        @PostConstruct
        private void addObjectToJNDI() throws NamingException {
        Context initialContext = new InitialContext();
        Context ctx = null;
        try {
             ctx = (Context) initialContext.lookup("java:comp/env/tst");
        } catch (NamingException exp) {
             ctx = initialContext.createSubcontext("java:comp/env/tst");
        }
      
        ctx.rebind("someObject", new Object());
        }
      }
      

       

      13:22:45,755 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 62) MSC000001: Failed to start service jboss.deployment.unit."com.company.tst.project-web.war".component.StartupBean.START: org.jboss.msc.service.StartException in service jboss.deployment.unit."com.company.tst.project-web.war".component.StartupBean.START: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance

        at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:57) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_45]

        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_45]

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]

        at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]

        at org.jboss.threads.JBossThread.run(JBossThread.java:122)

      Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance

        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:162) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:133) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:89) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:122)

        at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:137)

        at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:54) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        ... 6 more

      Caused by: com.company.tst.project.common.exceptions.StartupException: StartupBean.init: Problem during application startup

        at com.company.tst.project.core.producer.StartupBean.init(StartupBean.java:87)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_45]

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_45]

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45]

        at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45]

        at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:114)

        at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:103)

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55)

        at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:53)

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.weld.ejb.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:94)

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273)

        at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:369)

        at org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor.processInvocation(LifecycleCMTTxInterceptor.java:66)

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43)

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]

        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:160) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final]

        ... 11 more

      Caused by: java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only

        at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:276) [wildfly-naming-8.0.0.Final.jar:8.0.0.Final]

        at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:282) [wildfly-naming-8.0.0.Final.jar:8.0.0.Final]

        at com.company.tst.project.core.producer.StartupBean.addObjectToJNDI(StartupBean.java:106)

        ... 53 more

       

       

      What's the correct way to bind an object to JNDI under Wildfly 8?

       

      Thank you

        • 1. Re: InitialContext.rebind() throws UnsupportedOperationException
          Eduardo Martins Apprentice

          WildFly 8 complies to Java EE 7 platform specification, which defines that java:comp, java:module and java:app namespaces are all read only with respect Java EE component instances. These namespaces are modified through annotations, such as @Resource, and XML descriptors. Your application may write instead in java:global namespace, if you want to stick with the standard and portable namespaces, otherwise you may use proprietary ones such as java:jboss.


          --E