Search in sources :

Example 1 with JsonArray

use of org.forgerock.openam.utils.JsonArray in project OpenAM by OpenRock.

the class RecordReport method getJVMInformation.

/**
     * Create the JVM information
     *
     * @return
     */
private JsonValue getJVMInformation() {
    JsonObject report = JsonValueBuilder.jsonValue();
    //Arguments
    List<String> arguments = runtimeMxBean.getInputArguments();
    JsonArray argumentsJson = report.array(JVM_ARGUMENTS_LABEL);
    for (String argument : arguments) {
        argumentsJson.add(argument);
    }
    // some useful jvm properties
    JsonObject propertiesJson = JsonValueBuilder.jsonValue();
    propertiesJson.put("java.vm.info", System.getProperty("java.vm.info"));
    propertiesJson.put("java.vm.name", System.getProperty("java.vm.info"));
    propertiesJson.put("java.vm.specification.name", System.getProperty("java.vm.specification.name"));
    propertiesJson.put("java.vm.specification.vendor", System.getProperty("java.vm.specification.vendor"));
    propertiesJson.put("java.vm.specification.version", System.getProperty("java.vm.specification.version"));
    propertiesJson.put("java.vm.vendor", System.getProperty("java.vm.vendor"));
    propertiesJson.put("java.vm.version", System.getProperty("java.vm.version"));
    report.put(JVM_PROPERTIES_LABEL, propertiesJson.build().asMap());
    report.put(JVM_JAVA_VERSION_LABEL, System.getProperty("java.version"));
    //Memory
    JsonObject memoryJson = JsonValueBuilder.jsonValue();
    memoryJson.put(JVM_UNIT_MEMORY_LABEL, FileSizeUnit.MB);
    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();
    //Print used memory
    memoryJson.put(JVM_USED_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.totalMemory() - runtime.freeMemory()));
    //Print free memory
    memoryJson.put(JVM_FREE_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.freeMemory()));
    //Print total available memory
    memoryJson.put(JVM_TOTAL_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.totalMemory()));
    //Print Maximum available memory
    memoryJson.put(JVM_MAX_MEMORY_LABEL, FileSizeUnit.B.toMB(runtime.maxMemory()));
    //GNU systems don't support the "sun.arch.data.model" property, so we print both
    memoryJson.put(JVM_BIT_SIZE_GNU_LABEL, System.getProperty("sun.arch.data.model"));
    memoryJson.put(JVM_BIT_SIZE_LABEL, System.getProperty("os.arch"));
    report.put(JVM_MEMORY_LABEL, memoryJson.build().asMap());
    return report.build();
}
Also used : JsonArray(org.forgerock.openam.utils.JsonArray) JsonObject(org.forgerock.openam.utils.JsonObject)

Example 2 with JsonArray

use of org.forgerock.openam.utils.JsonArray in project OpenAM by OpenRock.

the class Requester method query.

/**
     * Request to perform a query at a specified endpoint.
     *
     * @param location Endpoint destination of this request. May not be null.
     * @param queryId Specific query ID to perform. May be null.
     * @param context Context of this request.
     * @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
     * @throws ResourceException If any exception occurred during processing.
     */
public JsonValue query(String location, String queryId, Context context) throws ResourceException {
    Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
    final Router rootRouter = router.get();
    final QueryRequest queryRequest = Requests.newQueryRequest(location);
    if (queryId != null) {
        queryRequest.setQueryId(queryId);
    }
    final InMemoryQueryResourceHandler resourceHandler = new InMemoryQueryResourceHandler();
    return rootRouter.handleQuery(context, queryRequest, resourceHandler).thenAsync(new AsyncFunction<QueryResponse, JsonValue, ResourceException>() {

        @Override
        public Promise<JsonValue, ResourceException> apply(QueryResponse value) {
            final JsonArray responses = JsonValueBuilder.jsonValue().array("results");
            for (ResourceResponse resource : resourceHandler.getResources()) {
                responses.add(resource.getContent());
            }
            return newResultPromise(responses.build().build());
        }
    }).getOrThrowUninterruptibly();
}
Also used : JsonArray(org.forgerock.openam.utils.JsonArray) QueryRequest(org.forgerock.json.resource.QueryRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) JsonValue(org.forgerock.json.JsonValue) Router(org.forgerock.json.resource.Router) ResourceException(org.forgerock.json.resource.ResourceException) AsyncFunction(org.forgerock.util.AsyncFunction)

Example 3 with JsonArray

use of org.forgerock.openam.utils.JsonArray in project OpenAM by OpenRock.

the class AbstractRestAuthCallbackHandler method createJsonField.

/**
     * Creates a JSON field for a callback.
     *
     * @param name The name of the field.
     * @param values The array value of the field.
     * @return The JSON field object.
     */
final JsonValue createJsonField(String name, Object[] values) {
    JsonArray jsonArray = JsonValueBuilder.jsonValue().put("name", name == null ? "" : name).array("value");
    if (values != null) {
        for (Object value : values) {
            jsonArray.add(value);
        }
    }
    JsonObject jsonObject = jsonArray.build();
    return jsonObject.build();
}
Also used : JsonArray(org.forgerock.openam.utils.JsonArray) JsonObject(org.forgerock.openam.utils.JsonObject) JsonObject(org.forgerock.openam.utils.JsonObject)

Aggregations

JsonArray (org.forgerock.openam.utils.JsonArray)3 JsonObject (org.forgerock.openam.utils.JsonObject)2 JsonValue (org.forgerock.json.JsonValue)1 QueryRequest (org.forgerock.json.resource.QueryRequest)1 QueryResponse (org.forgerock.json.resource.QueryResponse)1 ResourceException (org.forgerock.json.resource.ResourceException)1 ResourceResponse (org.forgerock.json.resource.ResourceResponse)1 Router (org.forgerock.json.resource.Router)1 AsyncFunction (org.forgerock.util.AsyncFunction)1