package org.jboss.resteasy.tracing;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.HttpHeaders;
import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.tracing.api.RESTEasyTracing;
import org.jboss.resteasy.tracing.api.RESTEasyTracingConfig;
import org.jboss.resteasy.tracing.api.RESTEasyTracingLevel;
public class RESTEasyTracingUtils {
static final List<String> = new ArrayList<>();
static {
SUMMARY_HEADERS.add(HttpHeaders.ACCEPT.toLowerCase());
SUMMARY_HEADERS.add(HttpHeaders.ACCEPT_ENCODING.toLowerCase());
SUMMARY_HEADERS.add(HttpHeaders.ACCEPT_CHARSET.toLowerCase());
SUMMARY_HEADERS.add(HttpHeaders.ACCEPT_LANGUAGE.toLowerCase());
SUMMARY_HEADERS.add(HttpHeaders.CONTENT_TYPE.toLowerCase());
SUMMARY_HEADERS.add(HttpHeaders.CONTENT_LENGTH.toLowerCase());
}
private RESTEasyTracingUtils() {
}
static String getTracingThreshold(RESTEasyTracingLevel appThreshold, HttpRequest request) {
final String thresholdText = getHeaderString(request, RESTEasyTracing.HEADER_THRESHOLD);
return (thresholdText == null) ? appThreshold.toString() : thresholdText;
}
static String (HttpRequest request, String header) {
if (request == null) {
return null;
}
if (request.getHttpHeaders() != null) {
return request.getHttpHeaders().getHeaderString(header);
}
return null;
}
static String toStringOrNA(Object object) {
if (object == null) {
return "n/a";
} else {
return String.valueOf(object);
}
}
static boolean isTracingSupportEnabled(RESTEasyTracingConfig type, HttpRequest request) {
return (type == RESTEasyTracingConfig.ALL)
|| ((type == RESTEasyTracingConfig.ON_DEMAND) && (getHeaderString(request, RESTEasyTracing.HEADER_ACCEPT) != null));
}
static RESTEasyTracingConfig getRESTEasyTracingConfig(Configuration configuration) {
final Object tracingText = configuration.getProperty(ResteasyContextParameters.RESTEASY_TRACING_TYPE);
final RESTEasyTracingConfig result;
if (tracingText != null) {
result = RESTEasyTracingConfig.valueOf((String) tracingText);
} else {
result = RESTEasyTracingConfig.OFF;
}
return result;
}
static String getTracingLoggerNameSuffix(HttpRequest request) {
return getHeaderString(request, RESTEasyTracing.HEADER_LOGGER);
}
static RESTEasyTracingLevel getRESTEasyTracingThreshold(Configuration configuration) {
final Object thresholdText = configuration.getProperty(ResteasyContextParameters.RESTEASY_TRACING_THRESHOLD);
return (thresholdText == null) ? RESTEasyTracing.DEFAULT_LEVEL : RESTEasyTracingLevel.valueOf((String) thresholdText);
}
protected static String getTracingInfoFormat(HttpRequest request) {
return getHeaderString(request, RESTEasyTracing.HEADER_ACCEPT_FORMAT);
}
}