Search in sources :

Example 21 with ActionReportResult

use of org.glassfish.admin.rest.results.ActionReportResult 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 22 with ActionReportResult

use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.

the class EncodingTest method encodeAsJson.

@Test
public void encodeAsJson() {
    RestActionReporter ar = buildActionReport();
    ActionReportResultJsonProvider provider = new ActionReportResultJsonProvider();
    ActionReportResult result = new ActionReportResult("test", ar);
    String json = provider.getContent(result);
    Map responseMap = MarshallingUtils.buildMapFromDocument(json);
    assertEquals(7, responseMap.size());
    assertEquals(4, ((Map) responseMap.get("extraProperties")).size());
    assertTrue(responseMap.get("children") instanceof List);
    assertTrue(responseMap.get("subReports") instanceof List);
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ArrayList(java.util.ArrayList) List(java.util.List) ActionReportResultJsonProvider(org.glassfish.admin.rest.provider.ActionReportResultJsonProvider) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 23 with ActionReportResult

use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.

the class EncodingTest method encodeAsXml.

@Test
public void encodeAsXml() {
    RestActionReporter ar = buildActionReport();
    ActionReportResultXmlProvider provider = new ActionReportResultXmlProvider();
    ActionReportResult result = new ActionReportResult("test", ar);
    String xml = provider.getContent(result);
    Map responseMap = MarshallingUtils.buildMapFromDocument(xml);
    assertEquals(7, responseMap.size());
    assertEquals(4, ((Map) responseMap.get("extraProperties")).size());
    assertTrue(responseMap.get("children") instanceof List);
    assertTrue(responseMap.get("subReports") instanceof List);
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ArrayList(java.util.ArrayList) List(java.util.List) ActionReportResultXmlProvider(org.glassfish.admin.rest.provider.ActionReportResultXmlProvider) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 24 with ActionReportResult

use of org.glassfish.admin.rest.results.ActionReportResult 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

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