-
1. Re: Binding a JNDI name from a remote client
andey Apr 6, 2017 10:35 AM (in response to kc7bfi)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 Apr 6, 2017 11:01 AM (in response to andey)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 Apr 6, 2017 11:05 AM (in response to 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 Apr 6, 2017 11:52 AM (in response to kc7bfi)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?