All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wildfly.swarm.jolokia.access.JolokiaAccess Maven / Gradle / Ivy

Go to download

Deploys the jolokia.war to activate JMX-HTTP bridge as an alternative to JSR-160 connectors

There is a newer version: 2018.5.0
Show newest version
package org.wildfly.swarm.jolokia.access;

import java.util.ArrayList;
import java.util.List;

/**
 * API for jolokia-access.xml configuration.
 *
 * @author Bob McWhirter
 */
public class JolokiaAccess {

    public JolokiaAccess() {
    }

    public JolokiaAccess host(String host) {
        this.hosts.add(host);
        return this;
    }

    public JolokiaAccess command(String command) {
        this.commands.add(command);
        return this;
    }

    public JolokiaAccess httpMethod(String method) {
        this.methods.add(method);
        return this;
    }

    public JolokiaAccess allowOrigin(String origin) {
        this.origins.add(origin);
        return this;
    }

    public JolokiaAccess strictChecking() {
        this.strictChecking = true;
        return this;
    }

    public JolokiaAccess allow(Section.Consumer config) {
        Section rule = Section.allow();
        config.accept(rule);
        this.sections.add(rule);
        return this;
    }

    public JolokiaAccess deny(Section.Consumer config) {
        Section rule = Section.deny();
        config.accept(rule);
        this.sections.add(rule);
        return this;
    }

    public String toXML() {
        StringBuilder builder = new StringBuilder();

        builder.append("\n");
        builder.append("\n");

        if (!this.hosts.isEmpty()) {
            builder.append("  \n");
            this.hosts.forEach(e -> {
                builder.append("    ").append(e).append("\n");
            });
            builder.append("  \n");
        }

        if (!this.methods.isEmpty()) {
            builder.append("  \n");
            this.methods.forEach(e -> {
                builder.append("    ").append(e).append("\n");
            });
            builder.append("  \n");
        }

        if (!this.origins.isEmpty()) {
            builder.append("  \n");
            this.origins.forEach(e -> {
                builder.append("    ").append(e).append("\n");
            });
            if (this.strictChecking) {
                builder.append("    \n");
            }
            builder.append("  \n");
        }

        if (!this.commands.isEmpty()) {
            builder.append("  \n");
            this.commands.forEach(e -> {
                builder.append("    ").append(e).append("\n");
            });
            builder.append("  \n");
        }

        if (!this.sections.isEmpty()) {
            this.sections.forEach(e -> {
                builder.append("  <" + e.type() + ">\n");
                e.mbeans().forEach(mbean -> {
                    builder.append("    \n");
                    builder.append("      ").append(mbean.name()).append("\n");
                    mbean.attributes().forEach(attr -> {
                        builder.append("      ").append(mbean.name()).append("\n");
                    });
                    mbean.operations().forEach(attr -> {
                        builder.append("      ").append(mbean.name()).append("\n");
                    });
                    builder.append("    \n");
                });
                builder.append("  \n");
            });
        }

        builder.append("\n");

        return builder.toString();
    }

    private List hosts = new ArrayList<>();

    private List origins = new ArrayList<>();

    private List methods = new ArrayList<>();

    private List commands = new ArrayList<>();

    private boolean strictChecking = false;

    private List
sections = new ArrayList<>(); public interface Supplier extends java.util.function.Supplier { } public interface Consumer extends java.util.function.Consumer { } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy