Managing JBoss - WildFly using HTTP/JSON API

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

Few JBoss / WildFly administrators are aware that the application server has a management interface based on HTTP/JSON based API. This can be an easy shortcut if you want to collect quickly information from your servers with as little as a browser bookmark.  

Let's see some examples. How to check the server status:
http://localhost:9990/management?operation=attribute&name=server-state

"running"

In the above example we have executed a read-attribute of the server-state, which will return "running" if the server is up.

If you are using a Linux shell, it's likely that you have curl available which, in spite of the longer syntax, makes intuitive translating the CLI commands into HTTP API:

curl --digest 'http://administrator:Password1!@localhost:9990/management' --header "Content-Type: application/json" -d '{"operation":"read-attribute","name":"server-state","json.pretty":1}'

{"outcome" : "success", "result" : "running"}

In the above example, we are feeding the --header parameter to curl which adds an extra header to the request (setting the content-type) and then submits the request using a POST action (-d), in the same way that a browser does when a user has filled in an HTML form and presses the submit button.

Here is one more example: How to dump the JNDI tree of the application server:

http://localhost:9990/management/subsystem/naming?name=jndi-view

And here's the corresponding command using curl:

curl --digest 'http://administrator:Password1!@localhost:9990/management' --header "Content-Type: application/json" -d '{"operation":"jndi-view", "address":["subsystem","naming"], "json.pretty":1}'

{
"outcome":"success",
"result":{
"java: contexts":{
"java:":{
"TransactionManager":{
"class-name":"com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate",
"value":"com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@63751307";
}
},
"java:jboss":{
"TransactionManager":{
"class-name":"com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate",
"value":"com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate@63751307";
},
"TransactionSynchronizationRegistry":{
"class-name":"com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple",
"value":"com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple@429bd23c";
},
"UserTransaction":{
"class-name":"javax.transaction.UserTransaction",
"value":"UserTransaction"
},
. . . .
}
}
},
"modules":null
}
}
}
}

I think it should be easier now to translate even more complex CLI commands into HTTP/JSON requests.

Here's how to restart server groups from "main-server-group" using curl:

curl --digest 'http://administrator:Password1!@localhost:9990/management' --header "Content-Type: application/json" -d '{"operation":"restart-servers","address":[{"server-group":"main-server-group"}]}'

{"outcome" : "success"}

And now how to execute an operation on a resource. How to check the Connections in a pool (the Default ExampleDS)

curl --digest 'http://administrator:Password1!@localhost:9990/management' --header "Content-Type: application/json" -d '{"operation":"test-connection-in-pool","address":[{"subsystem":"datasources"},{"data-source":"ExampleDS"}]}'

{"outcome" : "success", "result" : [true]}

How to check the status of an application (in this example remote-ejb-server.jar):

curl --digest 'http://administrator:Password1!@localhost:9990/management' --header "Content-Type: application/json" -d '{"operation":"read-attribute","name":"status","recursive":"true", "include-runtime":"true", "address":["deployment","remote-ejb-server.jar"], "json.pretty":1}'

{"outcome" : "success", "result" : "OK"}

How to redeploy an application (in this example remote-ejb-server.jar):
curl --digest 'http://administrator:Password1!@localhost:9990/management' --header "Content-Type: application/json" -d '{"operation":"redeploy","address":[{"deployment":"remote-ejb-server.jar"}]}'

{"outcome" : "success"}

Related articles available on mastertheboss.com

How do I get the list of MBeans with twiddle?

  JBoss provides a simple command line tool that allows for inte

How to count active session with twiddle ?

  There are some well known alternatives to count the number of

How do I run garbage collector from shell?

  You can suggest JBoss to run the garbage collector in differen

How do I check my application status from shell?

  This is a two process step: at first you need to retrieve the

How do you shut down multiple JBoss instances?

  Supposing you have configured 2 instances of JBoss, one on por

twiddle reference guide

Please note: twiddle is not available any more as default Command

Follow us on Twitter