use of javax.json.JsonObjectBuilder in project Payara by payara.
the class JsonMetadataWriter method getJsonFromMetadata.
private JsonObject getJsonFromMetadata(Metadata metadata) {
JsonObjectBuilder payloadBuilder = Json.createObjectBuilder();
payloadBuilder.add(NAME, sanitizeMetadata(metadata.getName()));
payloadBuilder.add(DISPLAY_NAME, sanitizeMetadata(metadata.getDisplayName()));
payloadBuilder.add(DESCRIPTION, sanitizeMetadata(metadata.getDescription()));
payloadBuilder.add(TYPE, sanitizeMetadata(metadata.getType()));
payloadBuilder.add(UNIT, sanitizeMetadata(metadata.getUnit()));
payloadBuilder.add(TAGS, getPairFromMap(metadata.getTags()));
return payloadBuilder.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class JsonMetricWriter method getJsonFromMetrics.
private JsonObjectBuilder getJsonFromMetrics(Map<String, Metric> metricMap) {
JsonObjectBuilder payloadBuilder = Json.createObjectBuilder();
for (Map.Entry<String, Metric> entry : metricMap.entrySet()) {
String metricName = entry.getKey();
Metric metric = entry.getValue();
if (Counter.class.isInstance(metric)) {
payloadBuilder.add(metricName, ((Counter) metric).getCount());
} else if (Gauge.class.isInstance(metric)) {
Number value;
Object gaugeValue;
try {
gaugeValue = ((Gauge) metric).getValue();
} catch (IllegalStateException e) {
// The forwarding gauge is unloaded
continue;
}
if (!Number.class.isInstance(gaugeValue)) {
LOGGER.log(Level.FINER, "Skipping JSON output for Gauge: {0} of type {1}", new Object[] { metricName, gaugeValue.getClass() });
continue;
}
value = (Number) gaugeValue;
addValueToJsonObject(payloadBuilder, metricName, value);
} else if (Histogram.class.isInstance(metric)) {
payloadBuilder.add(metricName, getJsonFromMap(getHistogramNumbers((Histogram) metric)));
} else if (Meter.class.isInstance(metric)) {
payloadBuilder.add(metricName, getJsonFromMap(getMeterNumbers((Meter) metric)));
} else if (Timer.class.isInstance(metric)) {
payloadBuilder.add(metricName, getJsonFromMap(getTimerNumbers((Timer) metric)));
} else {
LOGGER.log(Level.WARNING, "Metric type '{0} for {1} is invalid", new Object[] { metric.getClass(), metricName });
}
}
return payloadBuilder;
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class InstanceDescriptorImpl method toJsonObject.
private JsonObject toJsonObject(boolean verbose) {
// Create a builder to store the object
JsonObjectBuilder configBuilder = Json.createObjectBuilder();
// Add all the instance information
configBuilder.add("Host", hostName.getCanonicalHostName());
configBuilder.add("Http Port(s)", Arrays.toString(getHttpPorts().toArray()).replaceAll("[\\[\\]]", ""));
configBuilder.add("Https Port(s)", Arrays.toString(getHttpsPorts().toArray()).replaceAll("[\\[\\]]", ""));
configBuilder.add("Instance Name", this.instanceName);
configBuilder.add("Instance Group", this.instanceGroup);
if (memberUUID != null) {
configBuilder.add("Hazelcast Member UUID", this.memberUUID);
}
// Create array of applications
JsonArrayBuilder deploymentBuilder = Json.createArrayBuilder();
getDeployedApplications().forEach(app -> {
// Construct object for each application
JsonObjectBuilder appBuilder = Json.createObjectBuilder();
// Add the name of the application
appBuilder.add("Name", app.getName());
// If there's only one module in the application, print the module info with the application name
if (app.getModuleDescriptors().size() == 1) {
ModuleDescriptor module = app.getModuleDescriptors().get(0);
appBuilder.add("Type", module.getType());
appBuilder.add("Context Root", (module.getContextRoot() == null) ? "N/A" : module.getContextRoot());
// List the module mappings if verbose is specified
if (verbose) {
JsonObjectBuilder servletMappings = Json.createObjectBuilder();
module.getServletMappings().forEach((key, value) -> {
servletMappings.add(key, value);
});
appBuilder.add("Mappings", servletMappings.build());
}
// If there's more modules, print info for each module
} else {
JsonArrayBuilder modules = Json.createArrayBuilder();
// Construct object for each module
app.getModuleDescriptors().forEach(module -> {
JsonObjectBuilder moduleBuilder = Json.createObjectBuilder();
// Add basic information for the module
moduleBuilder.add("Name", module.getName());
moduleBuilder.add("Type", module.getType());
moduleBuilder.add("Context Root", (module.getContextRoot() == null) ? "***" : module.getContextRoot());
// Create an object of mappings if verbose is specified
if (verbose) {
JsonObjectBuilder servletMappings = Json.createObjectBuilder();
module.getServletMappings().forEach((key, value) -> {
servletMappings.add(key, value);
});
moduleBuilder.add("Mappings", servletMappings.build());
}
modules.add(moduleBuilder.build());
});
appBuilder.add("Modules", modules.build());
}
deploymentBuilder.add(appBuilder.build());
});
configBuilder.add("Deployed", deploymentBuilder.build());
return Json.createObjectBuilder().add("Instance Configuration", configBuilder.build()).build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class MBeanReadHandler method getRequestObject.
@Override
public JsonObject getRequestObject() {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
try {
objectBuilder.add(RestMonitoringAppResponseToken.getMbeanNameKey(), mbeanname);
objectBuilder.add(RestMonitoringAppResponseToken.getRequestTypeKey(), requesttype);
} catch (JsonException ex) {
super.setStatus(Response.Status.INTERNAL_SERVER_ERROR);
}
return objectBuilder.build();
}
use of javax.json.JsonObjectBuilder in project Payara by payara.
the class MBeanReadHandler method buildAttributes.
private JsonObject buildAttributes(MBeanInfo mbean) throws JsonException {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
MBeanAttributeInfo[] attributes = mbean.getAttributes();
for (MBeanAttributeInfo attribute : attributes) {
String attributeName = attribute.getName();
MBeanAttributeReadHandler attributeHandler = new MBeanAttributeReadHandler(delegate, mbeanname, attributeName);
objectBuilder.add(attributeName, attributeHandler.getValueObject());
}
return objectBuilder.build();
}
Aggregations