use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class JmxServiceUrlsResource method getJmxServiceUrl.
@GET
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public ActionReportResult getJmxServiceUrl() {
try {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL[] urls = (JMXServiceURL[]) mBeanServer.getAttribute(getBootAMXMBeanObjectName(), "JMXServiceURLs");
List<String> jmxUrls = new ArrayList<String>();
for (JMXServiceURL url : urls) {
jmxUrls.add(url.getURLPath());
}
RestActionReporter ar = new RestActionReporter();
ar.setActionDescription("Get JMX Service URLs");
ar.setSuccess();
ar.getExtraProperties().put("jmxServiceUrls", jmxUrls);
return new ActionReportResult(ar);
} catch (final JMException e) {
throw new RuntimeException(e);
}
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class SystemPropertiesCliResource method deleteProperty.
protected Response deleteProperty(String parent, String propName) {
ParameterMap pm = new ParameterMap();
pm.add("DEFAULT", propName);
pm.add("target", (parent == null) ? getParent(uriInfo) : parent);
RestActionReporter actionReport = ResourceUtil.runCommand("delete-system-property", pm, getSubject());
ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
ActionReportResult results = new ActionReportResult(commandName, actionReport, new OptionsResult());
int status = HttpURLConnection.HTTP_OK;
/*200 - ok*/
if (exitCode == ActionReport.ExitCode.FAILURE) {
status = HttpURLConnection.HTTP_INTERNAL_ERROR;
}
return Response.status(status).entity(results).build();
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class ResourceUtil method runCommandWithSse.
public static EventOutput runCommandWithSse(final String commandName, final ParameterMap parameters, final Subject subject, final SseCommandHelper.ActionReportProcessor processor) {
CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class);
final RestActionReporter ar = new RestActionReporter();
final CommandInvocation commandInvocation = cr.getCommandInvocation(commandName, ar, subject).parameters(parameters);
return SseCommandHelper.invokeAsync(commandInvocation, new SseCommandHelper.ActionReportProcessor() {
@Override
public ActionReport process(ActionReport report, EventOutput ec) {
addCommandLog(ar, commandName, parameters);
if (processor != null) {
return processor.process(report, ec);
}
return ar;
}
});
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class ResourceUtil method getActionReportResult.
public static ActionReportResult getActionReportResult(ActionReport.ExitCode status, String message, HttpHeaders requestHeaders, UriInfo uriInfo) {
RestActionReporter ar = new RestActionReporter();
ar.setActionExitCode(status);
return getActionReportResult(ar, message, requestHeaders, uriInfo);
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class Util method getCurrentValues.
public static Map<String, String> getCurrentValues(String basePath, ServiceLocator habitat, Subject subject) {
Map<String, String> values = new HashMap<String, String>();
final String path = (basePath.endsWith(".")) ? basePath.substring(0, basePath.length() - 1) : basePath;
RestActionReporter gr = ResourceUtil.runCommand("get", new ParameterMap() {
{
add("DEFAULT", path);
}
}, subject);
MessagePart top = gr.getTopMessagePart();
for (MessagePart child : top.getChildren()) {
String message = child.getMessage();
if (message.contains("=")) {
String[] parts = message.split("=");
values.put(parts[0], (parts.length > 1) ? parts[1] : "");
}
}
return values;
}
Aggregations