use of org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher in project stdlib by petergeneric.
the class GuicedResteasy method getDispatcher.
private synchronized ServletContainerDispatcher getDispatcher() throws ServletException {
if (!registered.get()) {
dispatcher = new ServletContainerDispatcher();
configure(dispatcher);
registered.set(true);
}
return dispatcher;
}
use of org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher in project stdlib by petergeneric.
the class GuicedResteasy method call.
public void call(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, NotFoundException {
final HttpCallContext ctx = HttpCallContext.set(request, response, context);
if (forceUTF8DefaultCharset && requestCharsetHelper != null)
requestCharsetHelper.applyDefaultCharset(request);
Timer.Context timer = null;
if (httpCalls != null)
timer = httpCalls.time();
final String oldThreadName;
final Thread thread;
if (ctx.isVerbose() || renameThreads) {
thread = Thread.currentThread();
oldThreadName = thread.getName();
} else {
thread = null;
oldThreadName = null;
}
try {
if (thread != null && oldThreadName != null)
thread.setName(ctx.getLogId() + " " + ctx.getRequestInfo());
// Share the call id to log4j
Tracing.start(ctx.getLogId(), ctx.isVerbose());
// Share the call id to log4j
MDC.put(TracingConstants.MDC_HTTP_REMOTE_ADDR, ctx.getRequest().getRemoteAddr());
MDC.put(TracingConstants.MDC_SERVLET_CONTEXT_PATH, ctx.getServletContext().getContextPath());
MDC.put(TracingConstants.MDC_HTTP_REQUEST_URI, ctx.getRequest().getRequestURI());
// Add the session id (if present)
final HttpSession session = ctx.getRequest().getSession(false);
if (session != null) {
MDC.put(TracingConstants.MDC_HTTP_SESSION_ID, session.getId());
}
try {
// Optionally log the request
if (log.isDebugEnabled())
log.debug(ctx.getRequestInfo());
// Get or create the dispatcher
ServletContainerDispatcher dispatcher = getDispatcher();
dispatcher.service(request.getMethod(), request, response, handleNotFoundException);
} catch (NotFoundException e) {
if (httpNotFoundExceptions != null)
httpNotFoundExceptions.mark();
// let the caller handle this
throw e;
} catch (ServletException | IOException | RuntimeException | Error e) {
if (httpExceptions != null)
httpExceptions.mark();
// try to pretty print, otherwise rethrow
tryHandleException(ctx, response, e);
}
} finally {
if (timer != null)
timer.stop();
HttpCallContext.clear();
Tracing.stop(ctx.getLogId());
MDC.clear();
if (oldThreadName != null && thread != null)
thread.setName(oldThreadName);
}
}
Aggregations