use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.
the class TemplateExecCommand method optionsLegacyFormat.
@OPTIONS
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ActionReportResult optionsLegacyFormat() {
RestActionReporter ar = new RestActionReporter();
ar.setExtraProperties(new Properties());
ar.setActionDescription(commandDisplayName);
OptionsResult optionsResult = new OptionsResult(resourceName);
Map<String, MethodMetaData> mmd = new HashMap<String, MethodMetaData>();
MethodMetaData methodMetaData = ResourceUtil.getMethodMetaData(commandName, getCommandParams(), locatorBridge.getRemoteLocator());
optionsResult.putMethodMetaData(commandMethod, methodMetaData);
mmd.put(commandMethod, methodMetaData);
ResourceUtil.addMethodMetaData(ar, mmd);
ActionReportResult ret = new ActionReportResult(ar, null, optionsResult);
ret.setCommandDisplayName(commandDisplayName);
return ret;
}
use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.
the class TemplateListOfResource method createResource.
@POST
// create
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public Response createResource(HashMap<String, String> data) {
if (data == null) {
data = new HashMap<String, String>();
}
try {
if (data.containsKey("error")) {
String errorMessage = localStrings.getLocalString("rest.request.parsing.error", "Unable to parse the input entity. Please check the syntax.");
ActionReportResult arr = ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, errorMessage, requestHeaders, uriInfo);
return Response.status(400).entity(arr).build();
}
ResourceUtil.purgeEmptyEntries(data);
// Command to execute
String commandName = getPostCommand();
String resourceToCreate = uriInfo.getAbsolutePath() + "/";
if (null != commandName) {
// adjusting for DEFAULT is required only while executing a CLI command
ResourceUtil.adjustParameters(data);
if (data.containsKey("name")) {
resourceToCreate += data.get("name");
} else {
resourceToCreate += data.get("DEFAULT");
}
RestActionReporter actionReport = ResourceUtil.runCommand(commandName, data, getSubject());
ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
if (exitCode != ActionReport.ExitCode.FAILURE) {
String successMessage = localStrings.getLocalString("rest.resource.create.message", "\"{0}\" created successfully.", resourceToCreate);
ActionReportResult arr = ResourceUtil.getActionReportResult(actionReport, successMessage, requestHeaders, uriInfo);
return Response.ok(arr).build();
}
String errorMessage = getErrorMessage(data, actionReport);
ActionReportResult arr = ResourceUtil.getActionReportResult(actionReport, errorMessage, requestHeaders, uriInfo);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(arr).build();
} else {
ActionReportResult arr = ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, "No CRUD Create possible.", requestHeaders, uriInfo);
return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(arr).build();
}
} catch (Exception e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.
the class FindHttpProtocolResource method get.
@GET
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public ActionReportResult get() {
Dom dom = getEntity();
NetworkListener nl = dom.createProxy(NetworkListener.class);
Protocol p = nl.findHttpProtocol();
RestActionReporter ar = new RestActionReporter();
ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ar.getTopMessagePart().getProps().put("protocol", p.getName());
ActionReportResult result = new ActionReportResult("find-http-protocol", ar, new OptionsResult());
return result;
}
use of org.glassfish.admin.rest.results.ActionReportResult 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.results.ActionReportResult 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();
}
Aggregations