Search in sources :

Example 16 with ActionReportResult

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;
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) HashMap(java.util.HashMap) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) Properties(java.util.Properties) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) Produces(javax.ws.rs.Produces) OPTIONS(javax.ws.rs.OPTIONS)

Example 17 with ActionReportResult

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);
    }
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) WebApplicationException(javax.ws.rs.WebApplicationException) ActionReport(org.glassfish.api.ActionReport) MultiException(org.glassfish.hk2.api.MultiException) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 18 with ActionReportResult

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;
}
Also used : Dom(org.jvnet.hk2.config.Dom) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 19 with ActionReportResult

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);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 20 with ActionReportResult

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();
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) OptionsResult(org.glassfish.admin.rest.results.OptionsResult)

Aggregations

ActionReportResult (org.glassfish.admin.rest.results.ActionReportResult)24 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)23 OptionsResult (org.glassfish.admin.rest.results.OptionsResult)13 Produces (javax.ws.rs.Produces)9 GET (javax.ws.rs.GET)7 ArrayList (java.util.ArrayList)5 Consumes (javax.ws.rs.Consumes)5 MethodMetaData (org.glassfish.admin.rest.provider.MethodMetaData)5 ActionReport (org.glassfish.api.ActionReport)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Properties (java.util.Properties)4 Test (org.testng.annotations.Test)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 POST (javax.ws.rs.POST)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Response (javax.ws.rs.core.Response)2 ActionReportResultHtmlProvider (org.glassfish.admin.rest.provider.ActionReportResultHtmlProvider)2