Search in sources :

Example 1 with ActionReportResultHtmlProvider

use of org.glassfish.admin.rest.provider.ActionReportResultHtmlProvider in project Payara by payara.

the class EncodingTest method encodeAsHtml.

@Test
public void encodeAsHtml() {
    RestActionReporter ar = buildActionReport();
    ActionReportResultHtmlProvider provider = new ActionReportResultHtmlProvider();
    ActionReportResult result = new ActionReportResult("test", ar);
    String html = provider.getContent(result);
// How to test this?
}
Also used : ActionReportResultHtmlProvider(org.glassfish.admin.rest.provider.ActionReportResultHtmlProvider) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Test(org.testng.annotations.Test)

Example 2 with ActionReportResultHtmlProvider

use of org.glassfish.admin.rest.provider.ActionReportResultHtmlProvider in project Payara by payara.

the class RestAdapter method reportError.

private void reportError(Request req, Response res, int statusCode, String msg) {
    try {
        // TODO: There's a lot of arm waving and flailing here.  I'd like this to be cleaner, but I don't
        // have time at the moment.  jdlee 8/11/10
        // getClientActionReport(req);
        RestActionReporter report = new RestActionReporter();
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setActionDescription("Error");
        report.setMessage(msg);
        BaseProvider<ActionReportResult> provider;
        String type = getAcceptedMimeType(req);
        if (null == type) {
            res.setContentType("text/html");
            provider = new ActionReportResultHtmlProvider();
        } else
            switch(type) {
                case "xml":
                    res.setContentType("application/xml");
                    provider = new ActionReportResultXmlProvider();
                    break;
                case "json":
                    res.setContentType("application/json");
                    provider = new ActionReportResultJsonProvider();
                    break;
                default:
                    res.setContentType("text/html");
                    provider = new ActionReportResultHtmlProvider();
                    break;
            }
        res.setStatus(statusCode);
        res.getOutputStream().write(provider.getContent(new ActionReportResult(report)).getBytes());
        res.getOutputStream().flush();
        res.finish();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ActionReportResultHtmlProvider(org.glassfish.admin.rest.provider.ActionReportResultHtmlProvider) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReportResultXmlProvider(org.glassfish.admin.rest.provider.ActionReportResultXmlProvider) ActionReportResultJsonProvider(org.glassfish.admin.rest.provider.ActionReportResultJsonProvider) LoginException(javax.security.auth.login.LoginException) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) RemoteAdminAccessException(org.glassfish.internal.api.RemoteAdminAccessException) IOException(java.io.IOException)

Aggregations

ActionReportResultHtmlProvider (org.glassfish.admin.rest.provider.ActionReportResultHtmlProvider)2 ActionReportResult (org.glassfish.admin.rest.results.ActionReportResult)2 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)2 IOException (java.io.IOException)1 LoginException (javax.security.auth.login.LoginException)1 ActionReportResultJsonProvider (org.glassfish.admin.rest.provider.ActionReportResultJsonProvider)1 ActionReportResultXmlProvider (org.glassfish.admin.rest.provider.ActionReportResultXmlProvider)1 EndpointRegistrationException (org.glassfish.api.container.EndpointRegistrationException)1 RemoteAdminAccessException (org.glassfish.internal.api.RemoteAdminAccessException)1 Test (org.testng.annotations.Test)1