use of fish.payara.microprofile.metrics.writer.JsonMetadataWriter in project Payara by payara.
the class MetricsResource method getOutputWriter.
private MetricsWriter getOutputWriter(HttpServletRequest request, HttpServletResponse response) throws IOException {
MetricsWriter outputWriter = null;
String method = request.getMethod();
Writer writer = response.getWriter();
String accept = request.getHeader(ACCEPT);
if (accept == null) {
accept = TEXT_PLAIN;
}
if (GET.equals(method)) {
if (accept.contains(APPLICATION_JSON)) {
outputWriter = new JsonMetricWriter(writer);
} else if (accept.contains(TEXT_PLAIN)) {
outputWriter = new PrometheusWriter(writer);
} else {
outputWriter = new PrometheusWriter(writer);
}
} else if (OPTIONS.equals(method)) {
if (accept.contains(APPLICATION_JSON)) {
outputWriter = new JsonMetadataWriter(writer);
} else {
response.sendError(SC_NOT_ACCEPTABLE, String.format("[%s] not acceptable", accept));
}
} else {
response.sendError(SC_METHOD_NOT_ALLOWED, String.format("HTTP method [%s] not allowed", method));
}
return outputWriter;
}
Aggregations