Search in sources :

Example 1 with ActionReporter

use of com.sun.enterprise.v3.common.ActionReporter in project Payara by payara.

the class ActionReportResultHtmlProvider method processReport.

protected String processReport(ActionReporter ar) {
    StringBuilder result = new StringBuilder();
    String des = ar.getActionDescription();
    // check for no description, make it blank
    if (des == null) {
        des = "";
    }
    final String message = ResourceUtil.encodeString((ar instanceof RestActionReporter) ? ((RestActionReporter) ar).getCombinedMessage() : ar.getMessage());
    if (message != null) {
        result.append("<h2>").append(des).append(" output:</h2><h3>").append("<pre>").append(message).append("</pre>").append("</h3>");
    }
    if (ar.getActionExitCode() != ExitCode.SUCCESS) {
        result.append("<h3>Exit Code: ").append(ar.getActionExitCode().toString()).append("</h3>");
    }
    Properties properties = ar.getTopMessagePart().getProps();
    if (!properties.isEmpty()) {
        result.append(processProperties(properties));
    }
    Properties extraProperties = ar.getExtraProperties();
    if ((extraProperties != null) && (!extraProperties.isEmpty())) {
        if ((extraProperties.size() == 1) && (extraProperties.get("methods") != null)) {
        // do not show only methods metadata in html, not really needed
        } else {
            result.append(getExtraProperties(extraProperties));
        }
    }
    List<ActionReport.MessagePart> children = ar.getTopMessagePart().getChildren();
    if (children.size() > 0) {
        result.append(processChildren(children));
    }
    List<ActionReporter> subReports = ar.getSubActionsReport();
    if (subReports.size() > 0) {
        result.append(processSubReports(subReports));
    }
    return result.toString();
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReporter(com.sun.enterprise.v3.common.ActionReporter) Properties(java.util.Properties)

Example 2 with ActionReporter

use of com.sun.enterprise.v3.common.ActionReporter in project Payara by payara.

the class ActionReportXmlProvider method processReport.

protected XmlObject processReport(ActionReporter ar) {
    XmlMap result = new XmlMap("map");
    result.put("message", (ar instanceof RestActionReporter) ? ((RestActionReporter) ar).getCombinedMessage() : ar.getMessage());
    result.put("command", ar.getActionDescription());
    result.put("exit_code", ar.getActionExitCode().toString());
    Properties properties = ar.getTopMessagePart().getProps();
    if ((properties != null) && (!properties.isEmpty())) {
        result.put("properties", new XmlMap("properties", properties));
    }
    Properties extraProperties = ar.getExtraProperties();
    if ((extraProperties != null) && (!extraProperties.isEmpty())) {
        result.put("extraProperties", getExtraProperties(result, extraProperties));
    }
    List<MessagePart> children = ar.getTopMessagePart().getChildren();
    if ((children != null) && (!children.isEmpty())) {
        result.put("children", processChildren(children));
    }
    List<ActionReporter> subReports = ar.getSubActionsReport();
    if ((subReports != null) && (!subReports.isEmpty())) {
        result.put("subReports", processSubReports(subReports));
    }
    return result;
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MessagePart(org.glassfish.api.ActionReport.MessagePart) XmlMap(org.glassfish.admin.rest.utils.xml.XmlMap) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReporter(com.sun.enterprise.v3.common.ActionReporter)

Example 3 with ActionReporter

use of com.sun.enterprise.v3.common.ActionReporter in project Payara by payara.

the class CommandResource method executeCommand.

private Response executeCommand(CommandName commandName, Payload.Inbound inbound, ParameterMap params, boolean supportsMultiparResult, String xIndentHeader, String modelETag, Cookie jSessionId) throws WebApplicationException {
    // Scope support
    if (RestLogging.restLogger.isLoggable(Level.FINEST)) {
        RestLogging.restLogger.log(Level.FINEST, "executeCommand(): ", commandName);
    }
    // Check command model
    CommandModel model = getCommandModel(commandName);
    checkCommandModelETag(model, modelETag);
    // Execute it
    boolean notifyOption = false;
    if (params != null) {
        notifyOption = params.containsKey("notify");
    }
    // new RestActionReporter(); //Must use PropsFileActionReporter because some commands react diferently on it :-(
    ActionReporter ar = new PropsFileActionReporter();
    final RestPayloadImpl.Outbound outbound = new RestPayloadImpl.Outbound(false);
    final CommandRunner.CommandInvocation commandInvocation = getCommandRunner().getCommandInvocation(commandName.getScope(), commandName.getName(), ar, getSubject(), notifyOption);
    if (inbound != null) {
        commandInvocation.inbound(inbound);
    }
    commandInvocation.outbound(outbound).parameters(params).execute();
    ar = (ActionReporter) commandInvocation.report();
    fixActionReporterSpecialCases(ar);
    ActionReport.ExitCode exitCode = ar.getActionExitCode();
    int status = HttpURLConnection.HTTP_OK;
    /*200 - ok*/
    if (exitCode == ActionReport.ExitCode.FAILURE) {
        status = HttpURLConnection.HTTP_INTERNAL_ERROR;
    }
    ResponseBuilder rb = Response.status(status);
    if (xIndentHeader != null) {
        rb.header("X-Indent", xIndentHeader);
    }
    if (supportsMultiparResult && outbound.size() > 0) {
        ParamsWithPayload pwp = new ParamsWithPayload(outbound, ar);
        rb.entity(pwp);
    } else {
        rb.type(MediaType.APPLICATION_JSON_TYPE);
        rb.entity(ar);
    }
    if (isSingleInstanceCommand(model)) {
        rb.cookie(getJSessionCookie(jSessionId));
    }
    return rb.build();
}
Also used : PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) ActionReport(org.glassfish.api.ActionReport) PlainTextActionReporter(com.sun.enterprise.v3.common.PlainTextActionReporter) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) ActionReporter(com.sun.enterprise.v3.common.ActionReporter) CachedCommandModel(com.sun.enterprise.admin.util.CachedCommandModel) ParamsWithPayload(com.sun.enterprise.admin.remote.ParamsWithPayload) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) RestPayloadImpl(com.sun.enterprise.admin.remote.RestPayloadImpl)

Example 4 with ActionReporter

use of com.sun.enterprise.v3.common.ActionReporter in project Payara by payara.

the class CommandResource method fixActionReporterSpecialCases.

/**
 * Some ActionReporters has special logic which must be reflected here
 */
private void fixActionReporterSpecialCases(ActionReporter ar) {
    if (ar == null) {
        return;
    }
    if (ar instanceof PlainTextActionReporter) {
        PlainTextActionReporter par = (PlainTextActionReporter) ar;
        StringBuilder finalOutput = new StringBuilder();
        par.getCombinedMessages(par, finalOutput);
        String outs = finalOutput.toString();
        if (!StringUtils.ok(outs)) {
            par.getTopMessagePart().setMessage(strings.getLocalString("get.mon.no.data", "No monitoring data to report.") + "\n");
        }
    }
}
Also used : PlainTextActionReporter(com.sun.enterprise.v3.common.PlainTextActionReporter)

Example 5 with ActionReporter

use of com.sun.enterprise.v3.common.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.v3.common.ActionReporter) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Aggregations

ActionReporter (com.sun.enterprise.v3.common.ActionReporter)8 Properties (java.util.Properties)3 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)3 PlainTextActionReporter (com.sun.enterprise.v3.common.PlainTextActionReporter)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 MessagePart (org.glassfish.api.ActionReport.MessagePart)2 ParamsWithPayload (com.sun.enterprise.admin.remote.ParamsWithPayload)1 RestPayloadImpl (com.sun.enterprise.admin.remote.RestPayloadImpl)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 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)1 TreeMap (java.util.TreeMap)1 JsonObject (javax.json.JsonObject)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 XmlMap (org.glassfish.admin.rest.utils.xml.XmlMap)1