use of org.glassfish.jersey.message.internal.TracingLogger in project jersey by jersey.
the class TracingUtils method logStart.
/**
* Log tracing messages START events.
*
* @param request container request instance to get runtime properties
* to check if tracing support is enabled for the request.
*/
public static void logStart(ContainerRequest request) {
TracingLogger tracingLogger = TracingLogger.getInstance(request);
if (tracingLogger.isLogEnabled(ServerTraceEvent.START)) {
StringBuilder textSB = new StringBuilder();
textSB.append(String.format("baseUri=[%s] requestUri=[%s] method=[%s] authScheme=[%s]", request.getBaseUri(), request.getRequestUri(), request.getMethod(), toStringOrNA(request.getSecurityContext().getAuthenticationScheme())));
for (String header : SUMMARY_HEADERS) {
textSB.append(String.format(" %s=%s", header, toStringOrNA(request.getRequestHeaders().get(header))));
}
tracingLogger.log(ServerTraceEvent.START, textSB.toString());
}
if (tracingLogger.isLogEnabled(ServerTraceEvent.START_HEADERS)) {
StringBuilder textSB = new StringBuilder();
for (String header : request.getRequestHeaders().keySet()) {
if (!SUMMARY_HEADERS.contains(header)) {
textSB.append(String.format(" %s=%s", header, toStringOrNA(request.getRequestHeaders().get(header))));
}
}
if (textSB.length() > 0) {
textSB.insert(0, "Other request headers:");
}
tracingLogger.log(ServerTraceEvent.START_HEADERS, textSB.toString());
}
}
use of org.glassfish.jersey.message.internal.TracingLogger in project jersey by jersey.
the class PathMatchingRouter method apply.
@Override
public Router.Continuation apply(final RequestProcessingContext context) {
final RoutingContext rc = context.routingContext();
// Peek at matching information to obtain path to match
String path = rc.getFinalMatchingGroup();
final TracingLogger tracingLogger = TracingLogger.getInstance(context.request());
tracingLogger.log(ServerTraceEvent.MATCH_PATH_FIND, path);
Router.Continuation result = null;
final Iterator<Route> iterator = acceptedRoutes.iterator();
while (iterator.hasNext()) {
final Route acceptedRoute = iterator.next();
final PathPattern routePattern = acceptedRoute.routingPattern();
final MatchResult m = routePattern.match(path);
if (m != null) {
// Push match result information and rest of path to match
rc.pushMatchResult(m);
result = Router.Continuation.of(context, acceptedRoute.next());
//tracing
tracingLogger.log(ServerTraceEvent.MATCH_PATH_SELECTED, routePattern.getRegex());
break;
} else {
tracingLogger.log(ServerTraceEvent.MATCH_PATH_NOT_MATCHED, routePattern.getRegex());
}
}
if (tracingLogger.isLogEnabled(ServerTraceEvent.MATCH_PATH_SKIPPED)) {
while (iterator.hasNext()) {
tracingLogger.log(ServerTraceEvent.MATCH_PATH_SKIPPED, iterator.next().routingPattern().getRegex());
}
}
if (result == null) {
// No match
return Router.Continuation.of(context);
}
return result;
}
use of org.glassfish.jersey.message.internal.TracingLogger in project jersey by jersey.
the class RoutingStage method apply.
/**
* {@inheritDoc}
* <p/>
* Routing stage navigates through the nested {@link Router routing hierarchy}
* using a depth-first transformation strategy until a request-to-response
* inflector is {@link org.glassfish.jersey.process.internal.Inflecting found on
* a leaf stage node}, in which case the request routing is terminated and an
* {@link org.glassfish.jersey.process.Inflector inflector} (if found) is pushed
* to the {@link RoutingContext routing context}.
*/
@Override
public Continuation<RequestProcessingContext> apply(final RequestProcessingContext context) {
final ContainerRequest request = context.request();
context.triggerEvent(RequestEvent.Type.MATCHING_START);
final TracingLogger tracingLogger = TracingLogger.getInstance(request);
final long timestamp = tracingLogger.timestamp(ServerTraceEvent.MATCH_SUMMARY);
try {
final RoutingResult result = _apply(context, routingRoot);
Stage<RequestProcessingContext> nextStage = null;
if (result.endpoint != null) {
context.routingContext().setEndpoint(result.endpoint);
nextStage = getDefaultNext();
}
return Continuation.of(result.context, nextStage);
} finally {
tracingLogger.logDuration(ServerTraceEvent.MATCH_SUMMARY, timestamp);
}
}
use of org.glassfish.jersey.message.internal.TracingLogger in project jersey by jersey.
the class AbstractJavaResourceMethodDispatcher method invoke.
/**
* Use the underlying invocation handler to invoke the underlying Java method
* with the supplied input method argument values on a given resource instance.
*
* @param containerRequest container request.
* @param resource resource class instance.
* @param args input argument values for the invoked Java method.
* @return invocation result.
* @throws ProcessingException (possibly {@link MappableException mappable})
* container exception in case the invocation failed.
*/
final Object invoke(final ContainerRequest containerRequest, final Object resource, final Object... args) throws ProcessingException {
try {
// Validate resource class & method input parameters.
if (validator != null) {
validator.validateResourceAndInputParams(resource, resourceMethod, args);
}
final PrivilegedAction invokeMethodAction = new PrivilegedAction() {
@Override
public Object run() {
final TracingLogger tracingLogger = TracingLogger.getInstance(containerRequest);
final long timestamp = tracingLogger.timestamp(ServerTraceEvent.METHOD_INVOKE);
try {
return methodHandler.invoke(resource, method, args);
} catch (IllegalAccessException | IllegalArgumentException | UndeclaredThrowableException ex) {
throw new ProcessingException(LocalizationMessages.ERROR_RESOURCE_JAVA_METHOD_INVOCATION(), ex);
} catch (InvocationTargetException ex) {
throw mapTargetToRuntimeEx(ex.getCause());
} catch (Throwable t) {
throw new ProcessingException(t);
} finally {
tracingLogger.logDuration(ServerTraceEvent.METHOD_INVOKE, timestamp, resource, method);
}
}
};
final SecurityContext securityContext = containerRequest.getSecurityContext();
final Object invocationResult = (securityContext instanceof SubjectSecurityContext) ? ((SubjectSecurityContext) securityContext).doAsSubject(invokeMethodAction) : invokeMethodAction.run();
// Validate response entity.
if (validator != null) {
validator.validateResult(resource, resourceMethod, invocationResult);
}
return invocationResult;
} catch (ValidationException ex) {
// handle validation exceptions -> potentially mappable
throw new MappableException(ex);
}
}
use of org.glassfish.jersey.message.internal.TracingLogger in project jersey by jersey.
the class ContainerFilteringStage method apply.
@Override
@SuppressWarnings("unchecked")
public Continuation<RequestProcessingContext> apply(RequestProcessingContext context) {
Iterable<ContainerRequestFilter> sortedRequestFilters;
final boolean postMatching = responseFilters == null;
final ContainerRequest request = context.request();
final TracingLogger tracingLogger = TracingLogger.getInstance(request);
if (postMatching) {
// post-matching
final ArrayList<Iterable<RankedProvider<ContainerRequestFilter>>> rankedProviders = new ArrayList<>(2);
rankedProviders.add(requestFilters);
rankedProviders.add(request.getRequestFilters());
sortedRequestFilters = Providers.mergeAndSortRankedProviders(new RankedComparator<ContainerRequestFilter>(), rankedProviders);
context.monitoringEventBuilder().setContainerRequestFilters(sortedRequestFilters);
context.triggerEvent(RequestEvent.Type.REQUEST_MATCHED);
} else {
// pre-matching (response filter stage is pushed in pre-matching phase, so that if pre-matching filter
// throws exception, response filters get still invoked)
context.push(new ResponseFilterStage(context, responseFilters, tracingLogger));
sortedRequestFilters = Providers.sortRankedProviders(new RankedComparator<ContainerRequestFilter>(), requestFilters);
}
final TracingLogger.Event summaryEvent = (postMatching ? ServerTraceEvent.REQUEST_FILTER_SUMMARY : ServerTraceEvent.PRE_MATCH_SUMMARY);
final long timestamp = tracingLogger.timestamp(summaryEvent);
int processedCount = 0;
try {
final TracingLogger.Event filterEvent = (postMatching ? ServerTraceEvent.REQUEST_FILTER : ServerTraceEvent.PRE_MATCH);
for (ContainerRequestFilter filter : sortedRequestFilters) {
final long filterTimestamp = tracingLogger.timestamp(filterEvent);
try {
filter.filter(request);
} catch (Exception exception) {
throw new MappableException(exception);
} finally {
processedCount++;
tracingLogger.logDuration(filterEvent, filterTimestamp, filter);
}
final Response abortResponse = request.getAbortResponse();
if (abortResponse != null) {
// abort accepting & return response
return Continuation.of(context, Stages.asStage(new Endpoint() {
@Override
public ContainerResponse apply(final RequestProcessingContext requestContext) {
return new ContainerResponse(requestContext.request(), abortResponse);
}
}));
}
}
} finally {
if (postMatching) {
context.triggerEvent(RequestEvent.Type.REQUEST_FILTERED);
}
tracingLogger.logDuration(summaryEvent, timestamp, processedCount);
}
return Continuation.of(context, getDefaultNext());
}
Aggregations