Search in sources :

Example 6 with TracingLogger

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);
}
Also used : TracingLogger(org.glassfish.jersey.message.internal.TracingLogger)

Example 7 with 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();
    }
}
Also used : ResolvedViewable(org.glassfish.jersey.server.mvc.spi.ResolvedViewable) ServletOutputStream(javax.servlet.ServletOutputStream) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) TracingLogger(org.glassfish.jersey.message.internal.TracingLogger) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher) IOException(java.io.IOException) ContainerException(org.glassfish.jersey.server.ContainerException) ContainerException(org.glassfish.jersey.server.ContainerException) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Aggregations

TracingLogger (org.glassfish.jersey.message.internal.TracingLogger)7 MappableException (org.glassfish.jersey.server.internal.process.MappableException)2 RequestProcessingContext (org.glassfish.jersey.server.internal.process.RequestProcessingContext)2 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 MatchResult (java.util.regex.MatchResult)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServletResponseWrapper (javax.servlet.http.HttpServletResponseWrapper)1 ValidationException (javax.validation.ValidationException)1 ProcessingException (javax.ws.rs.ProcessingException)1 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)1 Response (javax.ws.rs.core.Response)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 RankedComparator (org.glassfish.jersey.model.internal.RankedComparator)1