use of fish.payara.microprofile.metrics.exception.NoSuchRegistryException in project Payara by payara.
the class MetricsResource method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>OPTIONS</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MetricsService metricsService = Globals.getDefaultBaseServiceLocator().getService(MetricsService.class);
if (!metricsService.isMetricsEnabled()) {
response.sendError(SC_FORBIDDEN, "MP Metrics is disabled");
return;
}
if (!request.isSecure() && metricsService.isMetricsSecure()) {
response.sendError(SC_FORBIDDEN, "MP Metrics security is enabled");
return;
}
MetricsRequest metricsRequest = new MetricsRequest(request);
try {
if (metricsRequest.isRegistryRequested() && !REGISTRY_NAMES.contains(metricsRequest.getRegistryName())) {
throw new NoSuchRegistryException(metricsRequest.getRegistryName());
}
MetricsWriter outputWriter = getOutputWriter(request, response);
if (outputWriter != null) {
setContentType(outputWriter, response);
if (metricsRequest.isRegistryRequested() && metricsRequest.isMetricRequested()) {
outputWriter.write(metricsRequest.getRegistryName(), metricsRequest.getMetricName());
} else if (metricsRequest.isRegistryRequested()) {
outputWriter.write(metricsRequest.getRegistryName());
} else {
outputWriter.write();
}
}
} catch (NoSuchRegistryException ex) {
response.sendError(SC_NOT_FOUND, String.format("[%s] registry not found", metricsRequest.getRegistryName()));
} catch (NoSuchMetricException ex) {
response.sendError(SC_NOT_FOUND, String.format("[%s] metric not found", metricsRequest.getMetricName()));
}
}
use of fish.payara.microprofile.metrics.exception.NoSuchRegistryException in project Payara by payara.
the class JsonWriter method write.
@Override
public void write() throws IOException {
JsonObjectBuilder payloadBuilder = Json.createObjectBuilder();
JsonObjectBuilder applicationBuilder = Json.createObjectBuilder();
for (String registryName : service.getAllRegistryNames()) {
try {
JsonObjectBuilder value = getJsonData(registryName);
if (!BASE.getName().equals(registryName) && !VENDOR.getName().equals(registryName)) {
applicationBuilder.addAll(value);
} else {
payloadBuilder.add(registryName, value.build());
}
} catch (NoSuchRegistryException e) {
// Ignore
}
}
JsonObject applicationObject = applicationBuilder.build();
if (!applicationObject.isEmpty()) {
payloadBuilder.add(APPLICATION.getName(), applicationObject);
}
serialize(payloadBuilder.build());
}
Aggregations