Search in sources :

Example 6 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class GetGroupNamesCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    Config tmp = null;
    try {
        tmp = configs.getConfigByName(target);
    } catch (Exception ex) {
    }
    if (tmp != null) {
        config = tmp;
    }
    if (tmp == null) {
        Server targetServer = domain.getServerNamed(target);
        if (targetServer != null) {
            config = domain.getConfigNamed(targetServer.getConfigRef());
        }
        com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
        if (cluster != null) {
            config = domain.getConfigNamed(cluster.getConfigRef());
        }
    }
    ActionReporter report = (ActionReporter) context.getActionReport();
    try {
        String[] list = getGroupNames(realmName, userName);
        List<String> ret = Arrays.asList(list);
        report.setActionExitCode(ExitCode.SUCCESS);
        Properties props = new Properties();
        props.put("groups", ret);
        report.setExtraProperties(props);
        report.setMessage("" + ret);
    } catch (NoSuchRealmException | BadRealmException | InvalidOperationException | NoSuchUserException ex) {
        report.setFailureCause(ex);
        report.setActionExitCode(ExitCode.FAILURE);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException) Properties(java.util.Properties) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) InvalidOperationException(com.sun.enterprise.security.auth.realm.InvalidOperationException) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) InvalidOperationException(com.sun.enterprise.security.auth.realm.InvalidOperationException) ActionReporter(com.sun.enterprise.admin.report.ActionReporter)

Example 7 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class ActionReportResultXmlProvider method getContent.

@Override
public String getContent(ActionReportResult proxy) {
    ActionReporter ar = proxy.getActionReport();
    ActionReportXmlProvider provider = new ActionReportXmlProvider();
    return provider.getContent(ar);
}
Also used : ActionReporter(com.sun.enterprise.admin.report.ActionReporter)

Example 8 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class ActionReportJsonProvider method processReport.

/**
 * Converts an ActionReport into a JsonObject
 * @param ar
 * @return
 * @throws JsonException
 */
protected JsonObject processReport(ActionReporter ar) throws JsonException {
    JsonObjectBuilder result = Json.createObjectBuilder();
    if (ar instanceof RestActionReporter) {
        result.add("message", ((RestActionReporter) ar).getCombinedMessage());
    } else {
        String message = decodeEol(ar.getMessage());
        if (message != null) {
            result.add("message", message);
        }
    }
    String desc = ar.getActionDescription();
    if (desc != null) {
        result.add("command", ar.getActionDescription());
    } else {
        result.add("command", JsonValue.NULL);
    }
    result.add("exit_code", ar.getActionExitCode().toString());
    Properties properties = ar.getTopMessagePart().getProps();
    if ((properties != null) && (!properties.isEmpty())) {
        JsonObject propBuilder = Json.createObjectBuilder((Map) properties).build();
        result.add("properties", propBuilder);
    }
    Properties extraProperties = ar.getExtraProperties();
    if ((extraProperties != null) && (!extraProperties.isEmpty())) {
        result.add("extraProperties", getExtraProperties(extraProperties));
    }
    List<MessagePart> children = ar.getTopMessagePart().getChildren();
    if ((children != null) && (!children.isEmpty())) {
        result.add("children", processChildren(children));
    }
    List<ActionReporter> subReports = ar.getSubActionsReport();
    if ((subReports != null) && (!subReports.isEmpty())) {
        result.add("subReports", processSubReports(subReports));
    }
    return result.build();
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MessagePart(org.glassfish.api.ActionReport.MessagePart) JsonObject(javax.json.JsonObject) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReporter(com.sun.enterprise.admin.report.ActionReporter) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 9 with ActionReporter

use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.

the class AdminCommandStateJsonProvider method processState.

public JsonObject processState(AdminCommandState state) throws JsonException {
    JsonObjectBuilder result = Json.createObjectBuilder();
    result.add("state", state.getState().name());
    result.add("id", state.getId());
    result.add("empty-payload", state.isOutboundPayloadEmpty());
    ActionReporter ar = (ActionReporter) state.getActionReport();
    addActionReporter(ar, result);
    return result.build();
}
Also used : ActionReporter(com.sun.enterprise.admin.report.ActionReporter) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Aggregations

ActionReporter (com.sun.enterprise.admin.report.ActionReporter)9 Properties (java.util.Properties)3 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)3 PlainTextActionReporter (com.sun.enterprise.admin.report.PlainTextActionReporter)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 ActionReport (org.glassfish.api.ActionReport)2 MessagePart (org.glassfish.api.ActionReport.MessagePart)2 ParamsWithPayload (com.sun.enterprise.admin.remote.ParamsWithPayload)1 RestPayloadImpl (com.sun.enterprise.admin.remote.RestPayloadImpl)1 PropsFileActionReporter (com.sun.enterprise.admin.report.PropsFileActionReporter)1 CachedCommandModel (com.sun.enterprise.admin.util.CachedCommandModel)1 Config (com.sun.enterprise.config.serverbeans.Config)1 Server (com.sun.enterprise.config.serverbeans.Server)1 BadRealmException (com.sun.enterprise.security.auth.realm.BadRealmException)1 InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)1 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)1 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)1 TreeMap (java.util.TreeMap)1 JsonObject (javax.json.JsonObject)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1