4 Replies Latest reply on Jan 5, 2016 5:49 AM by julianfperez

    Injection of Java class and rebind to InitialContext

    julianfperez

      I try to rebind a java class called SomeProcess to the JNDI. This binding happens inside a singleton bean called ResourceBinder.

       

       

          InitialContext ctx = new InitialContext();

          ctx.rebind("SomeProcess", new SomeProcess());

          log.info(">>>>> SomeProcess bound");

       

       

      Later, this class is injected inside other ejb called SomeServiceBean.

       

       

          @Inject

          private SomeProcess process;

       

       

      However, I am getting this error:

       

       

      > org.jboss.naming.remote.protocol.NamingIOException: Failed to rebind

      > [Root exception is java.io.IOException:

      > java.lang.ClassNotFoundException:

      > de.brockhaus.userMgmt.control.process.SomeProcess from [Module

      > "org.jboss.remote-naming:main" from local module loader @ed17bee

      > (finder: local module finder @2a33fae0 (roots: C:\Program

      > Files\jboss\wildfly\modules,C:\Program

      > Files\jboss\wildfly\modules\system\layers\base))]] at

      > org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49)

      > 2015-12-28 20:33:02,302 DEBUG [main]

      > de.brockhaus.userMgmt.util.jndi.BeanLocator: Looking up for:

      > /BRO130_3_7_ResourceBinder-solution/SomeServiceBean!de.brockhaus.userMgmt.boundary.SomeService

      > at

      > org.jboss.naming.remote.protocol.v1.Protocol$3.execute(Protocol.java:306)

      > at

      > org.jboss.naming.remote.protocol.v1.Protocol$3.execute(Protocol.java:265)

      > at

      > org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.rebind(RemoteNamingStoreV1.java:116)

      > at

      > org.jboss.naming.remote.client.HaRemoteNamingStore$3.operation(HaRemoteNamingStore.java:302)

      > at

      > org.jboss.naming.remote.client.HaRemoteNamingStore$3.operation(HaRemoteNamingStore.java:299)

      > at

      > org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:137)

      > at

      > org.jboss.naming.remote.client.HaRemoteNamingStore.rebind(HaRemoteNamingStore.java:298)

      > at

      > org.jboss.naming.remote.client.RemoteContext.rebind(RemoteContext.java:163)

      > at

      > org.jboss.naming.remote.client.RemoteContext.rebind(RemoteContext.java:170)

      > at javax.naming.InitialContext.rebind(InitialContext.java:433) at

      > de.brockhaus.userMgmt.boundary.ResourceBinder.bindResources(ResourceBinder.java:32)

      > at

      > de.brockhaus.userMgmt.boundary.SomeServiceTest.bindResources(SomeServiceTest.java:21)

      > at

      > de.brockhaus.userMgmt.boundary.SomeServiceTest.main(SomeServiceTest.java:13)

      > Caused by: java.io.IOException: java.lang.ClassNotFoundException:

      > de.brockhaus.userMgmt.control.process.SomeProcess from [Module

      > "org.jboss.remote-naming:main" from local module loader @ed17bee

      > (finder: local module finder @2a33fae0 (roots: C:\Program

      > Files\jboss\wildfly\modules,C:\Program

      > Files\jboss\wildfly\modules\system\layers\base))] at

      > org.jboss.naming.remote.protocol.v1.Protocol$3.handleServerMessage(Protocol.java:329)

      > at

      > org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)

      > at

      > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

      > at

      > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

      > at java.lang.Thread.run(Thread.java:745) Caused by:

      > java.lang.ClassNotFoundException:

      > de.brockhaus.userMgmt.control.process.SomeProcess from [Module

      > "org.jboss.remote-naming:main" from local module loader @ed17bee

      > (finder: local module finder @2a33fae0 (roots: C:\Program

      > Files\jboss\wildfly\modules,C:\Program

      > Files\jboss\wildfly\modules\system\layers\base))] at

      > org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)

      > at

      > org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)

      > at

      > org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)

      > at

      > org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)

      > at

      > org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)

      > at java.lang.Class.forName0(Native Method) at

      > java.lang.Class.forName(Class.java:348) at

      > org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:131)

      > at

      > org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:112)

      > at

      > org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:948)

      > at

      > org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1255)

      > at

      > org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)

      > at

      > org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

      > at

      > org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)

      > at

      > org.jboss.naming.remote.protocol.v1.Protocol$3.handleServerMessage(Protocol.java:327)

      > ... 4 more

       

       

      I had tried to modify the maven pom file to include this dependency:

       

       

          <plugin>

              <groupId>org.apache.maven.plugins</groupId>

              <artifactId>maven-jar-plugin</artifactId>

              <version>2.3.1</version>

              <configuration>

              <archive>

              <manifestEntries>

              <Dependencies>org.jboss.remote-naming</Dependencies>

              </manifestEntries>

                  </archive>

              </configuration>   

          </plugin>

       

       

      And I have also modified the `module.xml` of the module `org.jboss.remote-naming` in WildFly 10 release.

       

       

          <module xmlns="urn:jboss:module:1.3" name="org.jboss.remote-naming">

              <resources>

                  <resource-root path="jboss-remote-naming-2.0.4.Final.jar"/>

                  <resource-root path="de/brockhaus/userMgmt/control/process"/>

              </resources>

              <dependencies>

                  <module name="javax.api"/>

                  <module name="org.jboss.ejb-client" optional="true"/>

                  <module name="org.jboss.remoting"/>

                  <module name="org.jboss.logging"/>

                  <module name="org.jboss.marshalling"/>

                  <module name="org.jboss.marshalling.river"/>

              </dependencies>

          </module>

       

       

      But all this does not work.

        • 1. Re: Injection of Java class and rebind to InitialContext
          jaysensharma

          Hello What kind of class is it "SomeProcess" ?   Normal plain java classes are not Injected using the @Inject. Which kind of class is it, I am asking this question because in your other post you mentioned putting this class in a separate module.https://developer.jboss.org/thread/266996

           

           

          Also why are you editing the "org.jboss.remote-naming"  JBoss provided  module (it is not recommended) .

           

          But if you are really want to test it then try the following  (NOT recommended though, and it's really a Bad idea)

           

              <module xmlns="urn:jboss:module:1.3" name="org.jboss.remote-naming">
                  <resources>
                      <resource-root path="jboss-remote-naming-2.0.4.Final.jar"/>
                      <resource-root path="."/>       
                      <!-- Assuming that you  the following path exists  "C:\Program Files\jboss\wildfly\modules\system\layers\base\org\jboss\remote-naming\main\de\brockhaus\userMgmt\control\process"  and the "SomeProcess.class" file is present in this directory. -->
                  </resources>
                  .
                  .
              </module>
          
          
          

           

           

           

          Also your singleton JAR should not need to explicitly define a dependency to " <Dependencies>org.jboss.remote-naming</Dependencies>"   because that dependency should be available to ever deployed application by default.   

           

          Regards

          Jay SenSharma

          • 2. Re: Injection of Java class and rebind to InitialContext
            julianfperez

            I am editing the "org.jboss.remote-naming"  JBoss provided  module because I got an error message in the server that told: " the class de.brockhaus.userMgmt.control.process.SomeProcess can not found by the module org.jboss.remote-naming. I have already found a solution for this problem: I have created a module where I save the jar of the proyect.  However, now I have a new error message:

            12:57:47,998 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0006: Starting Services for CDI deployment: BRO130_3_7_ResourceBinder-solution.jar

            12:57:48,062 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0009: Starting weld service for deployment BRO130_3_7_ResourceBinder-solution.jar

            12:57:52,775 INFO  [org.jboss.as.server] (management-handler-thread - 7) WFLYSRV0016: Replaced deployment "BRO130_3_7_ResourceBinder-solution.jar" with deployment "BRO130_3_7_ResourceBinder-solution.jar"

            12:57:52,786 INFO  [org.jboss.as.repository] (management-handler-thread - 7) WFLYDR0002: Content removed from location C:\Program Files\jboss\wildfly\standalone\data\content\2b\b4eeb8cf37ff36b8f9e992b4a112af6e364fe6\content

            12:58:19,656 ERROR [org.jboss.as.naming] (pool-3-thread-1) WFLYNAM0008: Unexpected internal error: java.lang.UnsupportedOperationException: WFLYNAM0043: Naming context is read-only

              at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:161)

              at org.jboss.as.naming.WritableServiceBasedNamingStore.rebind(WritableServiceBasedNamingStore.java:109)

              at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:301)

              at org.jboss.naming.remote.protocol.v1.Protocol$3.handleServerMessage(Protocol.java:335)

              at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

              at java.lang.Thread.run(Thread.java:745)

             

             

            12:58:20,200 ERROR [org.jboss.as.naming] (pool-3-thread-2) WFLYNAM0008: Unexpected internal error: java.lang.UnsupportedOperationException: WFLYNAM0043: Naming context is read-only

              at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:161)

              at org.jboss.as.naming.WritableServiceBasedNamingStore.rebind(WritableServiceBasedNamingStore.java:109)

              at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:301)

              at org.jboss.naming.remote.protocol.v1.Protocol$3.handleServerMessage(Protocol.java:335)

              at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

            • 3. Re: Injection of Java class and rebind to InitialContext
              jaysensharma

              The error which you mentioned like [WFLYNAM0043: Naming context is read-only]   you will get if you will try to bind custom objects to read only contexts like  "java:module" or "java:module", "java:comp" ..etc"

               

                                   InitialContext ic = new InitialContext();
                                   aaa.bbb.Test  test = new aaa.bbb.Test();
                                   ic.rebind("java:app/SomeProcess",test);     // WRONG
                                                //  OR
                                   ic.rebind("java:module/SomeProcess",test);        // WRONG
                                                //  OR
                                   ic.rebind("java:comp/SomeProcess",test);     // WRONG        
              

               

               

              Regards

              Jay SenSharma

              • 4. Re: Injection of Java class and rebind to InitialContext
                julianfperez

                As you can see in the question statement, I use the following code

                           InitialContext ctx = new InitialContext();

                           ctx.rebind("SomeProcess", new SomeProcess());

                           log.info(">>>>> SomeProcess bound");

                I am new with all this, but I think I do not use java:* contexts.