use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.
the class ResourceMethodInvoker method invokeOnTarget.
protected BuiltResponse invokeOnTarget(HttpRequest request, HttpResponse response, Object target) {
final RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
final long timestamp = tracingLogger.timestamp("METHOD_INVOKE");
final long msTimeStamp = methodStatisticsLogger.timestamp();
try {
// we don't pop so writer interceptors can get at this
ResteasyContext.pushContext(ResourceInfo.class, resourceInfo);
ResteasyContext.pushContext(Configuration.class, resourceMethodProviderFactory);
if (requestFilters != null && requestFilters.length > 0) {
PostMatchContainerRequestContext requestContext = new PostMatchContainerRequestContext(request, this, requestFilters, () -> invokeOnTargetAfterFilter(request, response, target));
// let it handle the continuation
return requestContext.filter();
} else {
return invokeOnTargetAfterFilter(request, response, target);
}
} finally {
methodStatisticsLogger.duration(msTimeStamp);
if (resource instanceof SingletonResource) {
tracingLogger.logDuration("METHOD_INVOKE", timestamp, ((SingletonResource) resource).traceInfo(), method.getMethod());
} else {
tracingLogger.logDuration("METHOD_INVOKE", timestamp, resource, method.getMethod());
}
}
}
use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.
the class PreMatchContainerRequestContext method filter.
public synchronized BuiltResponse filter() {
RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(httpRequest);
final long totalTimestamp = tracingLogger.timestamp("REQUEST_FILTER_SUMMARY");
while (requestFilters != null && currentFilter < requestFilters.length) {
ContainerRequestFilter filter = requestFilters[currentFilter++];
try {
suspended = false;
response = null;
throwable = null;
inFilter = true;
final long timestamp = tracingLogger.timestamp("REQUEST_FILTER");
filter.filter(this);
tracingLogger.logDuration("REQUEST_FILTER", timestamp, filter);
} catch (IOException e) {
throw new ApplicationException(e);
} finally {
inFilter = false;
}
if (suspended) {
if (!httpRequest.getAsyncContext().isSuspended())
httpRequest.getAsyncContext().suspend();
// ignore any abort request until we are resumed
filterReturnIsMeaningful = false;
response = null;
return null;
}
BuiltResponse serverResponse = (BuiltResponse) getResponseAbortedWith();
if (serverResponse != null) {
// handle the case where we've been suspended by a previous filter
if (filterReturnIsMeaningful)
return serverResponse;
else {
httpRequest.getAsyncContext().getAsyncResponse().resume(serverResponse);
return null;
}
}
if (throwable != null) {
// handle the case where we've been suspended by a previous filter
if (filterReturnIsMeaningful)
SynchronousDispatcher.rethrow(throwable);
else {
writeException(throwable);
return null;
}
}
}
tracingLogger.logDuration("REQUEST_FILTER_SUMMARY", totalTimestamp, requestFilters == null ? 0 : requestFilters.length);
// here it means we reached the last filter
// some frameworks don't support async request filters, in which case suspend() is forbidden
// so if we get here we're still synchronous and don't have a continuation, which must be in
// the caller
startedContinuation = true;
if (continuation == null)
return null;
// in any case, return the continuation: sync will use it, and async will ignore it
return continuation.get();
}
use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.
the class ContainerResponseContextImpl method filter.
public synchronized void filter() throws IOException {
RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
while (currentFilter < responseFilters.length) {
ContainerResponseFilter filter = responseFilters[currentFilter++];
try {
suspended = false;
throwable = null;
inFilter = true;
final long timestamp = logger.timestamp("RESPONSE_FILTER");
filter.filter(requestContext, this);
logger.logDuration("RESPONSE_FILTER", timestamp, filter);
} catch (IOException e) {
throw new ApplicationException(e);
} finally {
inFilter = false;
}
if (suspended) {
if (!request.getAsyncContext().isSuspended()) {
request.getAsyncContext().suspend();
weSuspended = true;
}
// ignore any abort request until we are resumed
filterReturnIsMeaningful = false;
return;
}
if (throwable != null) {
// handle the case where we've been suspended by a previous filter
if (filterReturnIsMeaningful)
SynchronousDispatcher.rethrow(throwable);
else {
writeException(throwable);
return;
}
}
}
// the caller
if (continuation == null)
return;
// if we've never been suspended, the caller is valid so let it handle any exception
if (filterReturnIsMeaningful) {
continuation.run(onComplete);
return;
}
// try to write it out
try {
continuation.run((t) -> {
onComplete.accept(t);
if (weSuspended) {
// if we're the ones who turned the request async, nobody will call complete() for us, so we have to
request.getAsyncContext().complete();
}
});
} catch (IOException e) {
LogMessages.LOGGER.unknownException(request.getHttpMethod(), request.getUri().getPath(), e);
}
}
use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.
the class ExceptionHandler method handleException.
public Response handleException(HttpRequest request, Throwable e) {
Response jaxrsResponse = null;
RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
// lookup mapper on class name of exception
jaxrsResponse = executeExactExceptionMapper(e, logger);
if (jaxrsResponse == null) {
if (e instanceof ClientErrorException) {
// These are BadRequestException and NotFoundException exceptions
jaxrsResponse = executeExceptionMapper(e, logger);
if (jaxrsResponse == null) {
jaxrsResponse = handleClientErrorException(request, (ClientErrorException) e);
}
} else if (e instanceof WebApplicationException) {
/*
* If the response property of the exception does not
* contain an entity and an exception mapping provider
* (see section 4.4) is available for
* WebApplicationException an implementation MUST use the
* provider to create a new Response instance, otherwise
* the response property is used directly.
*/
WebApplicationException wae = (WebApplicationException) e;
if (wae.getResponse() != null && wae.getResponse().getEntity() != null) {
jaxrsResponse = wae.getResponse();
} else {
// look at exception's subClass tree for possible mappers
jaxrsResponse = executeExceptionMapper(e, logger);
if (jaxrsResponse == null) {
jaxrsResponse = handleWebApplicationException((WebApplicationException) e);
}
}
} else if (e instanceof Failure) {
// known exceptions that extend from Failure
if (e instanceof WriterException) {
jaxrsResponse = handleWriterException(request, (WriterException) e, logger);
} else if (e instanceof ReaderException) {
jaxrsResponse = handleReaderException(request, (ReaderException) e, logger);
} else {
jaxrsResponse = executeExceptionMapper(e, logger);
if (jaxrsResponse == null) {
jaxrsResponse = handleFailure(request, (Failure) e);
}
}
} else {
if (e instanceof ApplicationException) {
jaxrsResponse = handleApplicationException(request, (ApplicationException) e, logger);
} else {
jaxrsResponse = executeExceptionMapper(e, logger);
}
}
}
if (jaxrsResponse == null) {
throw new UnhandledException(e);
}
return jaxrsResponse;
}
Aggregations