use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class TemplateExecCommand method executeCommand.
protected CommandResult executeCommand(ParameterMap data) {
RestActionReporter actionReport = ResourceUtil.runCommand(commandName, data, getSubject());
ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
if (exitCode == ActionReport.ExitCode.FAILURE) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(actionReport.getMessage()).build());
}
CommandResult cr = CompositeUtil.instance().getModel(CommandResult.class);
cr.setMessage(actionReport.getMessage());
cr.setProperties(actionReport.getTopMessagePart().getProps());
cr.setExtraProperties(getExtraProperties(actionReport));
return cr;
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class TemplateListOfResource method createResource.
// called in case of POST on application resource (deployment).
// resourceToCreate is the name attribute if provided.
private Response createResource(HashMap<String, String> data, String resourceToCreate) {
try {
if (data.containsKey("error")) {
String errorMessage = localStrings.getLocalString("rest.request.parsing.error", "Unable to parse the input entity. Please check the syntax.");
return Response.status(400).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, errorMessage, requestHeaders, uriInfo)).build();
}
ResourceUtil.purgeEmptyEntries(data);
// Command to execute
String commandName = getPostCommand();
ResourceUtil.defineDefaultParameters(data);
if ((resourceToCreate == null) || (resourceToCreate.equals(""))) {
String newResourceName = data.get("DEFAULT");
if (newResourceName != null) {
if (newResourceName.contains("/")) {
newResourceName = Util.getName(newResourceName, '/');
} else {
if (newResourceName.contains("\\")) {
newResourceName = Util.getName(newResourceName, '\\');
}
}
resourceToCreate = uriInfo.getAbsolutePath() + "/" + newResourceName;
}
} else {
resourceToCreate = uriInfo.getAbsolutePath() + "/" + resourceToCreate;
}
if (null != commandName) {
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.", new Object[] { resourceToCreate });
return Response.ok().entity(ResourceUtil.getActionReportResult(actionReport, successMessage, requestHeaders, uriInfo)).build();
}
String errorMessage = getErrorMessage(data, actionReport);
return Response.status(400).entity(ResourceUtil.getActionReportResult(actionReport, errorMessage, requestHeaders, uriInfo)).build();
}
String message = localStrings.getLocalString("rest.resource.post.forbidden", "POST on \"{0}\" is forbidden.", new Object[] { resourceToCreate });
return Response.status(403).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, message, requestHeaders, uriInfo)).build();
} catch (Exception e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter 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.utils.xml.RestActionReporter in project Payara by payara.
the class TemplateRestResource method doCreateOrUpdate.
/**
* This method performs the creation or updating of an entity, regardless of the
* request's mime type. If an error occurs, a <code>WebApplicationException</code>
* is thrown, so if the method returns, the create/update was successful.
* @param data
* @return
*/
protected RestActionReporter doCreateOrUpdate(HashMap<String, String> data) {
if (data == null) {
data = new HashMap<String, String>();
}
try {
// data.remove("submit");
removeAttributesToBeSkipped(data);
if (data.containsKey("error")) {
throw new WebApplicationException(Response.status(400).entity(ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, localStrings.getLocalString("rest.request.parsing.error", "Unable to parse the input entity. Please check the syntax."), requestHeaders, uriInfo)).build());
}
ResourceUtil.purgeEmptyEntries(data);
// client POST request for delete operation to DELETE method.
if ("__deleteoperation".equals(data.get("operation"))) {
data.remove("operation");
delete(data);
return new RestActionReporter();
}
// just update it.
data = ResourceUtil.translateCamelCasedNamesToXMLNames(data);
RestActionReporter ar = Util.applyChanges(data, uriInfo, getSubject());
if (ar.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
// i18n
throwError(Status.BAD_REQUEST, "Could not apply changes: " + ar.getMessage());
}
return ar;
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception ex) {
throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter 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;
}
Aggregations