JBoss 7.1.1 changing JNDI binding in runtime

6.6k views Asked by At

In JBoss 7.1.1 in standalone mode all JNDI bindings are configured in standalone.xml file in jboss:domain:naming:1.1 subsystem. According to documentation standalone.xml cannot be modified when server is running. I've tried to use JBoss CLI but I don't know how to write/modify resource.

How to change value in JNDI without restarting jboss?

3

There are 3 answers

0
s_bighead On

I was looking exactly for how to add or modify a JNDI binding at runtime, but I needed to to do this in a Wildfly 9 domain (cluster) configuration (not standalone), which is pretty much the same configuration as JBoss 7. However, I couldn't figure out a way to effectively apply changes without restarting all servers.

To start with, enter the JBoss command line interface and connect to your server domain controller:

./jboss-cli.sh
connect

First, you need to find which profile is active on the server group, so as, on the server root /, enter the following commands:

cd server-group=
ls

Afterwards, you should enter the only server group shown in the listing command (ls) by typing cd {{your_server_group_name}}, then type ls again and look for an entry named profile to check which one is active. Let's consider full-ha as an active profile for our example.

Next, go back to the root configuration folder / by typing cd .. and enter the following commands to navigate and view all JNDI bindings available with their current values:

cd profile=full-ha/subsystem=naming/binding=
:read-resource(recursive=true)

By doing this, you'll be able to see all available JNDI bindings and their attributes, if you want to list only binding names, type ls instead of the last command.

In order to modify a binding, type cd and the name of the binding listed in the previous command. Let's suppose you want to change the value of a binding named java:/webservice.url, then you should enter

cd java\:\/webservice.url

Notice that is necessary to quote some characters in your binding name such as : (colon) and / (slash) with a backslash (\).

To modify an attribute within this binding you should use the :write-attribute command. In this example, let's suppose you want to modify (or add) an attribute named "value" with its content as "this is a value":

:write-attribute(name=value,value="this is a value")

So as to apply this change, you'll need to restart all servers in the cluster by typing the following command:

/server-group={{server-group-name}}:restart-servers

If you want to know more commands to add or remove JNDI bindings check this jboss-cli snippets page

This configuration has been tested successfully in Wildfly 9.0.1

0
ragnor On

The question has a lot of views so I'll answer to it. Inspired by @mik response I've figured out that to change value of some JNDI key e.g. java:jboss/api/key to newApiKey run JBoss CLI and execute:

connect
/subsystem=naming/binding=java\:jboss\/api\/key/:write-attribute(name=value,value=newApiKey)

The change will be immediately visible on server and also stored (updated) in standalone.xmlso it won't get lost after server restart.

0
mik On

Should help you: https://docs.jboss.org/author/display/AS71/JNDI+Reference

Topic - Binding entries to JNDI:

An example standalone.xml might look like:

<subsystem xmlns="urn:jboss:domain:naming:1.1" >
  <bindings>
    <simple name="java:global/a" value="100" type="int" />
    <object-factory name="java:global/b" module="com.acme" class="org.acme.MyObjectFactory" />
    <lookup name="java:global/c" lookup="java:global/b" />
 </bindings>
</subsystem>

To add these entries via the CLI:

/subsystem=naming/binding=java\:global\/mybinding:add(binding-type=simple, type=long, value=1000)

To see all all options that are taken by the add command (this can actually be used to get the description of any CLI command):

/subsystem=naming/binding=*:read-operation-description(name=add)

Have not tried, but i hope this helps!

UPDATE - with tested examples:

  • Add JDNI name binding java:global/a:
/subsystem=naming/binding=java\:global\/a:add(value=10,binding-type=simple,type=java.lang.Integer)
  • Read existing JDNI name binding java:global/a:
/subsystem=naming/binding=java\:global\/a:read-resource(include-defaults=true)
  • Modify JDNI name binding value java:global/a:
/subsystem=naming/binding=java\:global\/a:write-attribute(name=value, value=20)
  • Remove JDNI name binding java:global/a:
/subsystem=naming/binding=java\:global\/a:remove()

Executing command directly from shell:

./jboss-cli.sh --connect --command="/subsystem=naming/binding=java\:global\/a:read-resource(include-defaults=true)"