4 Replies Latest reply on Apr 6, 2017 11:52 AM by andey

    Binding a JNDI name from a remote client

    kc7bfi

      I have a Java application that connects to my WildFly 10 server. I want to be able to bind a name for my client into the JNDI on the standalone WildFly server. I am trying to bind the name: java:/Name-1 However, I keep getting the error:

       

      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)

       

      Is it possible to bind a name to WildFly's JNDI from a remote client? If so, can you point me in the right direction as what I am doing wrong? Thanks, David

        • 1. Re: Binding a JNDI name from a remote client
          andey

          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         

          • 2. Re: Binding a JNDI name from a remote client
            kc7bfi

            Thanks for the clarification. What are the contexts that are writable? I've tried java:global and java: all with the same read-only error. David

            • 3. Re: Binding a JNDI name from a remote client
              kc7bfi

              This is how I am setting up my remote client to bind to WildFly's JNDI

               

              Properties jndiProperties = new Properties();

              jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

              jndiProperties.put(Context.SECURITY_PRINCIPAL, "jmsuser");

              jndiProperties.put(Context.SECURITY_CREDENTIALS, "jm5us3r");

              jndiProperties.put(Context.PROVIDER_URL, "http-remoting://" + host1 + ":8080");

              TheInitialContext = new InitialContext(jndiProperties);

               

              David

              • 4. Re: Binding a JNDI name from a remote client
                andey

                Are there any jndi.properties files in any of your applications, if so, they should be removed

                Are there any system properties set such as -Djava.naming.provider.url

                Make sure new InitialContext() is used and no properties are being passed in.

                 

                Section EE.5.3.4 of the Java EE spec says:

                The container must ensure that the application component instances have only

                read access to their naming context. The container must throw the

                javax.naming.OperationNotSupportedException from all the methods of the

                javax.naming.Context interface that modify the environment naming context and

                its subcontexts.

                 

                It seems pretty natural and handy to allow one application publish something to the JNDI at runtime and let other application to access it.

                 

                 

                The easiest way to bind those objects would be to use a @javax.ejb.Startup @javax.ejb.Singleton and bind them in @PostConstruct method. You won't have to do anything additional and you won't even need the sar (assuming that's the only thing you are using it for):

                 

                ~~~

                @Singleton 

                @Startup 

                public class SomeServiceManager { 

                 

                @PostConstruct 

                private void onConstruct() { 

                Context context = new InitialContext(); 

                     try { 

                          context.bind(SERVICE_NAME, this); // where SERVICE_NAME is "java:/SomeServiceManager" or similar 

                     } catch(NamingException e ) { 

                          logger.error("Failed to bind name in context", e); 

                     } 

                ...  

                 

                ~~~

                 

                Is that something that you want to try?