Using the HTTP Management API in JBoss EAP 6, 7 and 8

Solution Unverified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (JBoss EAP)
    • 6
    • 7
    • 8
  • HTTP/REST Api
  • Management

Issue

  • Where is the documentation?
  • Using the API

Resolution

These are the documentation links JBoss EAP 7: HTTP Management APIs and JBoss EAP 6: Management Application Programing Interfaces (APIs)

From there it just comes down to figuring out what you want to query or modify. It can query data with GET and call operations and write data via POST.

For instance, say I'm looking for datasource information.

I logged into the management console at http://localhost:9990/console/App.html to look and find out what the information I wanted was named and came up with the following query:

curl --digest -D - http://localhost:9990/management --header "Content-Type: application/json" -d '{"operation":"read-resource", "include-runtime":"true" , "recursive":"true", "address":["subsystem","datasources"], "json.pretty":1}' -u admin

Which returned the following result:

HTTP/1.1 401 Unauthorized
Content-length: 0
Www-authenticate: Digest realm="ManagementRealm",nonce="ece14dd47a195fdb0ac02fac60ea85c4"
Date: Tue, 31 Mar 2015 14:23:01 GMT

HTTP/1.1 200 OK
Transfer-encoding: chunked
Content-type: application/json
Date: Tue, 31 Mar 2015 14:23:01 GMT

{
    "outcome" : "success",
    "result" : {
        "installed-drivers" : [{
            "driver-name" : "h2",
            "deployment-name" : null,
            "driver-module-name" : "com.h2database.h2",
            "module-slot" : "main",
            "driver-datasource-class-name" : "",
            "driver-xa-datasource-class-name" : "org.h2.jdbcx.JdbcDataSource",
            "driver-class-name" : "org.h2.Driver",
            "driver-major-version" : 1,
            "driver-minor-version" : 3,
            "jdbc-compliant" : true
        }],
        "data-source" : {"ExampleDS" : {
            "allocation-retry" : null,
            "allocation-retry-wait-millis" : null,
            "allow-multiple-users" : false,
            "background-validation" : null,
            "background-validation-millis" : null,
            "blocking-timeout-wait-millis" : null,
            "check-valid-connection-sql" : null,
            "connection-url" : "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE",
            "datasource-class" : null,
            "driver-class" : null,
            "driver-name" : "h2",
            "enabled" : true,
            "exception-sorter-class-name" : null,
            "exception-sorter-properties" : null,
            "flush-strategy" : null,
            "idle-timeout-minutes" : null,
            "jndi-name" : "java:jboss/datasources/ExampleDS",
            "jta" : true,
            "max-pool-size" : null,
            "min-pool-size" : null,
            "new-connection-sql" : null,
            "password" : "sa",
            "pool-prefill" : null,
            "pool-use-strict-min" : null,
            "prepared-statements-cache-size" : null,
            "query-timeout" : null,
            "reauth-plugin-class-name" : null,
            "reauth-plugin-properties" : null,
            "security-domain" : null,
            "set-tx-query-timeout" : false,
            "share-prepared-statements" : false,
            "spy" : false,
            "stale-connection-checker-class-name" : null,
            "stale-connection-checker-properties" : null,
            "track-statements" : "NOWARN",
            "transaction-isolation" : null,
            "url-delimiter" : null,
            "url-selector-strategy-class-name" : null,
            "use-ccm" : true,
            "use-fast-fail" : false,
            "use-java-context" : true,
            "use-try-lock" : null,
            "user-name" : "sa",
            "valid-connection-checker-class-name" : null,
            "valid-connection-checker-properties" : null,
            "validate-on-match" : false,
            "connection-properties" : null,
            "statistics" : {
                "jdbc" : {
                    "PreparedStatementCacheAccessCount" : "0",
                    "PreparedStatementCacheAddCount" : "0",
                    "PreparedStatementCacheCurrentSize" : "0",
                    "PreparedStatementCacheDeleteCount" : "0",
                    "PreparedStatementCacheHitCount" : "0",
                    "PreparedStatementCacheMissCount" : "0"
                },
                "pool" : {
                    "ActiveCount" : "0",
                    "AvailableCount" : "20",
                    "AverageBlockingTime" : "0",
                    "AverageCreationTime" : "0",
                    "CreatedCount" : "0",
                    "DestroyedCount" : "0",
                    "InUseCount" : "0",
                    "MaxCreationTime" : "0",
                    "MaxUsedCount" : "0",
                    "MaxWaitCount" : "0",
                    "MaxWaitTime" : "0",
                    "TimedOut" : "0",
                    "TotalBlockingTime" : "0",
                    "TotalCreationTime" : "0"
                }
            }
        }},
        "jdbc-driver" : {"h2" : {
            "deployment-name" : null,
            "driver-class-name" : null,
            "driver-datasource-class-name" : null,
            "driver-major-version" : null,
            "driver-minor-version" : null,
            "driver-module-name" : "com.h2database.h2",
            "driver-name" : "h2",
            "driver-xa-datasource-class-name" : "org.h2.jdbcx.JdbcDataSource",
            "jdbc-compliant" : null,
            "module-slot" : null,
            "xa-datasource-class" : null
        }},
        "xa-data-source" : null
    }

As you figure out more specifically what you want to read it's just a matter of fine-tuning your query. For instance, if I decide that I just want to know about ExampleDS I can write:

curl --digest -D - http://localhost:9990/management --header "Content-Type: application/json" -d '{"operation":"read-resource", "include-runtime":"true" , "recursive":"true", "address":["subsystem","datasources","data-source","ExampleDS"], "json.pretty":1}'

and so on, drilling down until I get exactly what I'm looking for.

Example

- Getting server-state:

For the CLI command:

/:read-attribute(name=server-state)

The REST call would be:

curl -s --digest --user <admin-user>:<admin-password> "http://localhost:9990/management/?operation=attribute&name=server-state" 

or

curl -s --digest --user <admin-user>:<admin-password> "http://localhost:9990/management" --header "Content-Type: application/json" -d '{"operation":"read-attribute", "name":"server-state", "json.pretty":1}'

- Calling test-connection-in-pool on a data-source:

For the CLI command:

/subsystem=datasources/data-source=ExampleDS:test-connection-in-pool()

The REST call would be:

curl -s --digest --user <admin-user>:<admin-password> "http://localhost:9990/management" --header "Content-Type: application/json" -d '{"operation":"test-connection-in-pool", "address":["subsystem","datasources","data-source","ExampleDS"], "json.pretty":1}'

- Getting a specific attribute of a deployment:

For the CLI command:

/deployment=example.war:read-attribute(name=status)

The REST call would be:

$ curl -s --digest --user <admin-user>:<admin-password> "http://localhost:9990/management/deployment/example.war?operation=attribute&name=status"

or

curl -s --digest --user <admin-user>:<admin-password> "http://localhost:9990/management/" --header "Content-Type: application/json" -d '{"operation":"read-attribute", "name":"status", "address":["deployment","example.war"], "json.pretty":1}'

- Getting information of all deployments:

For the CLI command:

/deployment=*:read-resource(recursive=true)

or

deployment-info

The REST call would be:

curl -s --digest --user <admin-user>:<admin-password> "http://localhost:9990/management/deployment/*?operation=resource&json.pretty=1"

or

curl -s --digest --user <admin-user>:<admin-password> "http://localhost:9990/management/" --header "Content-Type: application/json" -d '{"operation": "read-children-resources", "child-type": "deployment", "include-runtime": true, "json.pretty": 1}'
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.