Search in sources :

Example 66 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project Payara by payara.

the class RestResourceMetadata method toJson.

public JsonObject toJson() throws JsonException {
    JsonObjectBuilder o = Json.createObjectBuilder();
    if (!resourceMethods.isEmpty()) {
        final JsonObjectBuilder methods = Json.createObjectBuilder();
        for (String key : resourceMethods.keySet()) {
            for (RestMethodMetadata rmm : resourceMethods.get(key)) {
                methods.add(key, rmm.toJson());
            }
        }
        o.add("resourceMethods", methods);
    }
    if (!subResources.isEmpty()) {
        o.add("subResources", JsonUtil.getJsonValue(subResources));
    }
    return o.build();
}
Also used : JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 67 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project Payara by payara.

the class LegacySseResponseBody method toJson.

@Override
public JsonObject toJson() throws JsonException {
    JsonObjectBuilder jsonBuild = Json.createObjectBuilder(super.toJson());
    if (!headers.isEmpty()) {
        JsonObjectBuilder oBuild = Json.createObjectBuilder();
        for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
            final String key = entry.getKey();
            for (String value : entry.getValue()) {
                oBuild.add(key, value);
            }
        }
        jsonBuild.add("headers", oBuild);
    }
    return jsonBuild.build();
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) JsonObjectBuilder(javax.json.JsonObjectBuilder) Map(java.util.Map) HashMap(java.util.HashMap)

Example 68 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project Payara by payara.

the class Message method toJson.

public JsonObject toJson() throws JsonException {
    JsonObjectBuilder object = Json.createObjectBuilder();
    object.add("message", getMessage());
    object.add("severity", getSeverity().toString());
    String f = getField();
    if (f != null && f.length() > 0) {
        object.add("field", f);
    }
    return object.build();
}
Also used : JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 69 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project Payara by payara.

the class ActionReportJson2Provider method processReport.

@Override
protected JsonObject processReport(ActionReporter ar) throws JsonException {
    JsonObject result = super.processReport(ar);
    JsonObjectBuilder objectBuilder = Json.createObjectBuilder(result);
    String combinedMessage = result.getString("message", null);
    String msg = decodeEol(ar.getTopMessagePart().getMessage());
    if (combinedMessage != null && !combinedMessage.equals(msg)) {
        if (msg != null) {
            objectBuilder.add("top_message", msg);
        } else {
            objectBuilder.add("top_message", JsonValue.NULL);
        }
    }
    if (ar.getFailureCause() != null) {
        objectBuilder.add("failure_cause", ar.getFailureCause().getLocalizedMessage());
    }
    return objectBuilder.build();
}
Also used : JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 70 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project Payara by payara.

the class ActionReportJsonProvider method processReport.

/**
 * Converts an ActionReport into a JsonObject
 * @param ar
 * @return
 * @throws JsonException
 */
protected JsonObject processReport(ActionReporter ar) throws JsonException {
    JsonObjectBuilder result = Json.createObjectBuilder();
    if (ar instanceof RestActionReporter) {
        result.add("message", ((RestActionReporter) ar).getCombinedMessage());
    } else {
        String message = decodeEol(ar.getMessage());
        if (message != null) {
            result.add("message", message);
        }
    }
    String desc = ar.getActionDescription();
    if (desc != null) {
        result.add("command", ar.getActionDescription());
    } else {
        result.add("command", JsonValue.NULL);
    }
    result.add("exit_code", ar.getActionExitCode().toString());
    Properties properties = ar.getTopMessagePart().getProps();
    if ((properties != null) && (!properties.isEmpty())) {
        JsonObject propBuilder = Json.createObjectBuilder((Map) properties).build();
        result.add("properties", propBuilder);
    }
    Properties extraProperties = ar.getExtraProperties();
    if ((extraProperties != null) && (!extraProperties.isEmpty())) {
        result.add("extraProperties", getExtraProperties(extraProperties));
    }
    List<MessagePart> children = ar.getTopMessagePart().getChildren();
    if ((children != null) && (!children.isEmpty())) {
        result.add("children", processChildren(children));
    }
    List<ActionReporter> subReports = ar.getSubActionsReport();
    if ((subReports != null) && (!subReports.isEmpty())) {
        result.add("subReports", processSubReports(subReports));
    }
    return result.build();
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MessagePart(org.glassfish.api.ActionReport.MessagePart) JsonObject(javax.json.JsonObject) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReporter(com.sun.enterprise.v3.common.ActionReporter) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Aggregations

JsonObjectBuilder (javax.json.JsonObjectBuilder)76 JsonArrayBuilder (javax.json.JsonArrayBuilder)31 Map (java.util.Map)19 JsonObject (javax.json.JsonObject)19 JsonException (javax.json.JsonException)14 HashMap (java.util.HashMap)9 StringWriter (java.io.StringWriter)8 ArrayList (java.util.ArrayList)6 JsonValue (javax.json.JsonValue)6 List (java.util.List)5 JsonString (javax.json.JsonString)5 PrintWriter (java.io.PrintWriter)3 Entry (java.util.Map.Entry)3 JsonArray (javax.json.JsonArray)3 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)2 JavaSource (de.strullerbaumann.visualee.source.entity.JavaSource)2 File (java.io.File)2 JsonWriter (javax.json.JsonWriter)2 Resource (org.apache.sling.api.resource.Resource)2 ValueMap (org.apache.sling.api.resource.ValueMap)2