Package org.glassfish.admin.rest.utils.xml

Examples of org.glassfish.admin.rest.utils.xml.RestActionReporter


    }

    public static Map<String, String> getCurrentValues(String basePath, ServiceLocator habitat) {
        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);
        }}, habitat, "");

        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] : "");
View Full Code Here


     *
     * @param changes
     * @param basePath
     */
    public void applyChanges(Map<String, String> changes, String basePath) {
        RestActionReporter ar = Util.applyChanges(changes, basePath);
        if (!ar.getActionExitCode().equals(ExitCode.SUCCESS)) {
            throw new WebApplicationException(Response.status(Status.BAD_REQUEST).
                    entity(ar.getCombinedMessage()).build());
        }
    }
View Full Code Here

     * @param throwBadRequest (vs. NOT_FOUND)
     * @param throwOnWarning  (vs.ignore warning)
     * @return
     */
    public ActionReporter executeCommand(Subject subject, String command, ParameterMap parameters, boolean throwBadRequest, boolean throwOnWarning) {
        RestActionReporter ar = ResourceUtil.runCommand(command, parameters,
                Globals.getDefaultHabitat(), "", subject); //TODO The last parameter is resultType and is not used. Refactor the called method to remove it
        ExitCode code = ar.getActionExitCode();
        if (code.equals(ExitCode.FAILURE) || (code.equals(ExitCode.WARNING) && throwOnWarning)) {
            if (throwBadRequest) {
                throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
                        .entity(ar.getCombinedMessage())
                        .build());
            } else {
                // TODO: Why NOT_FOUND?
                throw new WebApplicationException(Status.NOT_FOUND);
            }
View Full Code Here

    protected Habitat habitat;

    @GET
    public ActionReportResult proxyRequest() {

        RestActionReporter ar = new RestActionReporter();
        ar.setActionDescription("Proxied Data");
        ar.setSuccess();

        ActionReportResult result = new ActionReportResult(ar);

        Properties proxiedResponse = new ManagementProxyImpl().proxyRequest(uriInfo, habitat);
        ar.setExtraProperties(proxiedResponse);
        return result;
    }
View Full Code Here

    @Produces({
            MediaType.APPLICATION_JSON,
            "text/html;qs=2",
            MediaType.APPLICATION_XML})
    public ActionReportResult options() {
        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(),  habitat, RestService.logger);
View Full Code Here

        ret.setCommandDisplayName(commandDisplayName);
        return ret;
    }

    protected Response executeCommand(ParameterMap data) {
        RestActionReporter actionReport = ResourceUtil.runCommand(commandName, data, habitat,
                ResourceUtil.getResultType(requestHeaders));
        ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
        ActionReportResult option = options();
        ActionReportResult results = new ActionReportResult(commandName, actionReport, option.getMetaData());
        results.getActionReport().getExtraProperties().putAll(option.getActionReport().getExtraProperties());
        results.setCommandDisplayName(commandDisplayName);
        int status =HttpURLConnection.HTTP_OK; /*200 - ok*/
        if (exitCode == ActionReport.ExitCode.FAILURE) {
            status = HttpURLConnection.HTTP_INTERNAL_ERROR;
            results.setErrorMessage(actionReport.getCombinedMessage());
        }
        return Response.status(status).entity(results).build();

    }
View Full Code Here

        return runCommand(commandName, p, habitat, resultType);
    }

    public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Habitat habitat, String resultType) {
        CommandRunner cr = habitat.getComponent(CommandRunner.class);
        RestActionReporter ar = new RestActionReporter();

        cr.getCommandInvocation(commandName, ar).parameters(parameters).execute();
        return ar;
    }
View Full Code Here

    public static ActionReportResult getActionReportResult(ActionReport.ExitCode status, String message, HttpHeaders requestHeaders, UriInfo uriInfo) {
        if (isBrowser(requestHeaders)) {
            message = getHtml(message, uriInfo, false);
        }
        RestActionReporter ar = new RestActionReporter();
        ActionReportResult result = new ActionReportResult(ar);
       
        if (status != ActionReport.ExitCode.SUCCESS && status != ActionReport.ExitCode.WARNING) {
            result.setErrorMessage(message);
            result.setIsError(true);
        }

        ar.setActionExitCode(status);
        ar.setMessage(message);
        return result;
    }
View Full Code Here

    public Response options() {
        return Response.ok(buildActionReportResult()).build();
    }

    protected ActionReportResult buildActionReportResult() {
        RestActionReporter ar = new RestActionReporter();
        final String typeKey = upperCaseFirstLetter((decode(getName())));
        ar.setActionDescription(typeKey);
        ar.getExtraProperties().put("leafList", getEntity());

        OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
        Map<String, MethodMetaData> mmd = getMethodMetaData();
        optionsResult.putMethodMetaData("GET", mmd.get("GET"));
        optionsResult.putMethodMetaData("POST", mmd.get("POST"));
View Full Code Here

            }
        }
        if (!parameters.entrySet().isEmpty()) {
           return ResourceUtil.runCommand("set", parameters, habitat, ""); //TODO The last parameter is resultType and is not used. Refactor the called method to remove it
        } else {
            return new RestActionReporter(); // noop
        }
    }
View Full Code Here

TOP

Related Classes of org.glassfish.admin.rest.utils.xml.RestActionReporter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.