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();
}
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;
}
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();
}
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");
}
}
}
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();
}
Aggregations