use of com.sun.enterprise.admin.report.PropsFileActionReporter in project Payara by payara.
the class CommandResource method executeSseCommand.
private Response executeSseCommand(CommandName commandName, Payload.Inbound inbound, ParameterMap params, String modelETag, Cookie jSessionId) throws WebApplicationException {
// Scope support
if (RestLogging.restLogger.isLoggable(Level.FINEST)) {
RestLogging.restLogger.log(Level.FINEST, "executeSseCommand(): ", commandName);
}
// Check command model
CommandModel model = getCommandModel(commandName);
checkCommandModelETag(model, modelETag);
// Execute it
boolean notifyOption = false;
if (params != null) {
notifyOption = params.containsKey("notify");
}
final CommandRunner.CommandInvocation commandInvocation = getCommandRunner().getCommandInvocation(commandName.getScope(), commandName.getName(), new PropsFileActionReporter(), getSubject(), notifyOption);
if (inbound != null) {
commandInvocation.inbound(inbound);
}
commandInvocation.outbound(new RestPayloadImpl.Outbound(false)).managedJob().parameters(params);
ResponseBuilder rb = Response.status(HttpURLConnection.HTTP_OK);
if (isSingleInstanceCommand(model)) {
rb.cookie(getJSessionCookie(jSessionId));
}
rb.entity(SseCommandHelper.invokeAsync(commandInvocation, null));
return rb.build();
}
use of com.sun.enterprise.admin.report.PropsFileActionReporter 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.PropsFileActionReporter in project Payara by payara.
the class ListCommand method execute.
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
/* Issue 5918 Used in ManifestManager to keep output sorted */
try {
PropsFileActionReporter reporter = (PropsFileActionReporter) report;
reporter.useMainChildrenAttribute(true);
} catch (ClassCastException e) {
// ignore, this is not a manifest output
}
if (monitor) {
listMonitorElements(context);
return;
}
List<Map.Entry> matchingNodesSorted = sortNodesByDottedName(matchingNodes);
for (Map.Entry<Dom, String> node : matchingNodesSorted) {
ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setChildrenType("DottedName");
if (parentNodes[0].name.isEmpty()) {
part.setMessage(node.getValue());
} else {
part.setMessage(parentNodes[0].name + "." + node.getValue());
}
}
}
use of com.sun.enterprise.admin.report.PropsFileActionReporter in project Payara by payara.
the class CreateJndiResourceTest method setUp.
@Before
public void setUp() {
habitat = getHabitat();
resources = habitat.<Domain>getService(Domain.class).getResources();
server = habitat.getService(Server.class);
parameters = new ParameterMap();
context = new AdminCommandContextImpl(LogDomains.getLogger(CreateJndiResourceTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
cr = habitat.getService(CommandRunner.class);
}
use of com.sun.enterprise.admin.report.PropsFileActionReporter in project Payara by payara.
the class ListJndiResourcesTest method testExecuteSuccessListNoResource.
/**
* Test of execute method, of class ListJndiResource.
* delete-jndi-resource resource
* list-jndi-resources
*/
@Test
public void testExecuteSuccessListNoResource() {
createJndiResource();
parameters = new ParameterMap();
org.glassfish.resources.admin.cli.ListJndiResources listCommand = habitat.getService(org.glassfish.resources.admin.cli.ListJndiResources.class);
cr.getCommandInvocation("list-jndi-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
List<ActionReport.MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
assertEquals(origNum + 1, list.size());
// as we newly created a resource after test "setup".
origNum = origNum + 1;
deleteJndiResource();
ParameterMap parameters = new ParameterMap();
listCommand = habitat.getService(org.glassfish.resources.admin.cli.ListJndiResources.class);
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJndiResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
cr.getCommandInvocation("list-jndi-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
list = context.getActionReport().getTopMessagePart().getChildren();
if ((origNum - 1) == 0) {
// Nothing to list.
} else {
assertEquals(origNum - 1, list.size());
}
List<String> listStr = new ArrayList<String>();
for (ActionReport.MessagePart mp : list) {
listStr.add(mp.getMessage());
}
assertFalse(listStr.contains("resource"));
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Aggregations