Search code examples
undertowwildfly-10

Wildfly 10 - read configuration parameter programmatically


I have this in my standalone.xml:

<subsystem xmlns="urn:jboss:domain:undertow:3.0">
       <server name="default-server">
            <http-listener name="default" max-post-size="10000000" ...

Is there a way to read the value of max-post-size programmatically?


Solution

  • Yes. Start by having a look at the Management API reference documentation. That will give you an overview of management model.

    You can read the attribute with the HTTP API, CLI scripting, or using the native management client. Below is an example using the native management client.

    try (final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) {
        final ModelNode address = Operations.createAddress("subsystem", "undertow", "server", "default-server", "http-listener", "default");
        final ModelNode op = Operations.createReadAttributeOperation(address, "max-post-size");
        final ModelNode result = client.execute(op);
        if (Operations.isSuccessfulOutcome(result)) {
            System.out.println(Operations.readResult(result).asLong());
        } else {
            throw new RuntimeException(Operations.getFailureDescription(result).asString());
        }
    }
    

    If you're using maven you'd just need a dependency on org.wildfly.core:wildfly-controller-client:2.2.0.Final. There's also a jboss-client.jar in the $JBOSS_HOME/bin/client directory that can be placed on the class path which will have all the required binaries.