use of org.glassfish.jersey.message.internal.TracingLogger in project jersey by jersey.
the class TracingUtils method initTracingSupport.
/**
* According to configuration/request header it initialize {@link TracingLogger} and put it to the request properties.
*
* @param type application-wide tracing configuration type.
* @param appThreshold application-wide tracing level threshold.
* @param containerRequest request instance to get runtime properties to store {@link TracingLogger} instance to
* if tracing support is enabled for the request.
*/
public static void initTracingSupport(TracingConfig type, TracingLogger.Level appThreshold, ContainerRequest containerRequest) {
final TracingLogger tracingLogger;
if (isTracingSupportEnabled(type, containerRequest)) {
tracingLogger = TracingLogger.create(getTracingThreshold(appThreshold, containerRequest), getTracingLoggerNameSuffix(containerRequest));
} else {
tracingLogger = TracingLogger.empty();
}
containerRequest.setProperty(TracingLogger.PROPERTY_NAME, tracingLogger);
}
use of org.glassfish.jersey.message.internal.TracingLogger in project jersey by jersey.
the class JspTemplateProcessor method writeTo.
@Override
public void writeTo(final String templateReference, final Viewable viewable, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream out) throws IOException {
if (!(viewable instanceof ResolvedViewable)) {
// This should not happen with default MVC message body writer implementation
throw new IllegalArgumentException(LocalizationMessages.ERROR_VIEWABLE_INCORRECT_INSTANCE());
}
// SPI could supply instance of ResolvedViewable but we would like to keep the backward
// compatibility, so the cast is here.
final ResolvedViewable resolvedViewable = (ResolvedViewable) viewable;
final TracingLogger tracingLogger = TracingLogger.getInstance(containerRequestProvider.get().getPropertiesDelegate());
if (tracingLogger.isLogEnabled(MvcJspEvent.JSP_FORWARD)) {
tracingLogger.log(MvcJspEvent.JSP_FORWARD, templateReference, resolvedViewable.getModel());
}
final RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(templateReference);
if (dispatcher == null) {
throw new ContainerException(LocalizationMessages.NO_REQUEST_DISPATCHER_FOR_RESOLVED_PATH(templateReference));
}
final RequestDispatcher wrapper = new RequestDispatcherWrapper(dispatcher, getBasePath(), resolvedViewable);
// OutputStream and Writer for HttpServletResponseWrapper.
final ServletOutputStream responseStream = new ServletOutputStream() {
@Override
public void write(final int b) throws IOException {
out.write(b);
}
};
final PrintWriter responseWriter = new PrintWriter(new OutputStreamWriter(responseStream, getEncoding()));
try {
wrapper.forward(requestProviderRef.get().get(), new HttpServletResponseWrapper(responseProviderRef.get().get()) {
@Override
public ServletOutputStream getOutputStream() throws IOException {
return responseStream;
}
@Override
public PrintWriter getWriter() throws IOException {
return responseWriter;
}
});
} catch (final Exception e) {
throw new ContainerException(e);
} finally {
responseWriter.flush();
}
}
Aggregations