use of com.sun.enterprise.admin.report.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.admin.report.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(HEADING_END);
}
if (ar.getActionExitCode() != ExitCode.SUCCESS) {
result.append("<h3>Exit Code: ").append(ar.getActionExitCode().toString()).append(HEADING_END);
}
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.isEmpty()) {
result.append(processChildren(children));
}
List<ActionReporter> subReports = ar.getSubActionsReport();
if (!subReports.isEmpty()) {
result.append(processSubReports(subReports));
}
return result.toString();
}
use of com.sun.enterprise.admin.report.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.admin.report.ActionReporter in project Payara by payara.
the class PlainTextActionReporterTest method aggregateTest.
@Test
public void aggregateTest() {
ActionReporter successfulRoot = new PlainTextActionReporter();
assert successfulRoot.hasSuccesses();
assert !successfulRoot.hasFailures();
assert !successfulRoot.hasWarnings();
ActionReport failedChild = successfulRoot.addSubActionsReport();
failedChild.setActionExitCode(ActionReport.ExitCode.FAILURE);
assert successfulRoot.hasSuccesses();
assert successfulRoot.hasFailures();
assert !successfulRoot.hasWarnings();
assert !failedChild.hasSuccesses();
assert !failedChild.hasWarnings();
assert failedChild.hasFailures();
ActionReport warningChild = failedChild.addSubActionsReport();
warningChild.setActionExitCode(ActionReport.ExitCode.WARNING);
assert successfulRoot.hasSuccesses();
assert successfulRoot.hasFailures();
assert successfulRoot.hasWarnings();
assert !failedChild.hasSuccesses();
assert failedChild.hasWarnings();
assert failedChild.hasFailures();
assert warningChild.hasWarnings();
assert !warningChild.hasSuccesses();
ActionReport successfulChild = warningChild.addSubActionsReport();
assert failedChild.hasSuccesses();
assert warningChild.hasSuccesses();
assert !warningChild.hasFailures();
StringBuilder sb = new StringBuilder();
successfulRoot.setMessage("sr");
successfulRoot.getCombinedMessages(successfulRoot, sb);
assertEquals("sr", sb.toString());
warningChild.setMessage("wc");
sb = new StringBuilder();
successfulRoot.getCombinedMessages(successfulRoot, sb);
assertEquals("sr\nwc", sb.toString());
failedChild.setMessage("fc");
sb = new StringBuilder();
successfulRoot.getCombinedMessages(successfulRoot, sb);
assertEquals("sr\nfc\nwc", sb.toString());
}
use of com.sun.enterprise.admin.report.ActionReporter in project Payara by payara.
the class GetTokensCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReporter report = (ActionReporter) context.getActionReport();
PropertyResolver resolver = new PropertyResolver(domain, target);
String sep = "";
String eol = System.getProperty("line.separator");
StringBuilder output = new StringBuilder();
Map<String, String> values = new TreeMap<String, String>();
Properties properties = new Properties();
properties.put("tokens", values);
for (String token : tokens) {
String value = resolver.getPropertyValue(token);
if ((value == null) && (checkSystemProperties)) {
value = System.getProperty(token);
}
output.append(sep).append(token).append(" = ").append(value);
sep = eol;
values.put(token, value);
}
report.setMessage(output.toString());
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
report.setExtraProperties(properties);
}
Aggregations