org.glassfish.jersey.filter
Class LoggingFilter

java.lang.Object
  extended by org.glassfish.jersey.filter.LoggingFilter
All Implemented Interfaces:
ClientRequestFilter, ClientResponseFilter, ContainerRequestFilter, ContainerResponseFilter, WriterInterceptor

@PreMatching
@Priority(value=-2147483648)
public class LoggingFilter
extends Object
implements ContainerRequestFilter, ClientRequestFilter, ContainerResponseFilter, ClientResponseFilter, WriterInterceptor

Universal logging filter. Can be used on client or server side. Has the highest priority.

Author:
Pavel Bucek (pavel.bucek at oracle.com), Martin Matula (martin.matula at oracle.com)

Constructor Summary
LoggingFilter()
          Create a logging filter logging the request and response to a default JDK logger, named as the fully qualified class name of this class.
LoggingFilter(Logger logger, boolean printEntity)
          Create a logging filter with custom logger and custom settings of entity logging.
LoggingFilter(Logger logger, int maxEntitySize)
          Creates a logging filter with custom logger and entity logging turned on, but potentially limiting the size of entity to be buffered and logged.
 
Method Summary
 void aroundWriteTo(WriterInterceptorContext writerInterceptorContext)
          Interceptor method wrapping calls to MessageBodyWriter.writeTo(T, java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.OutputStream) method.
 void filter(ClientRequestContext context)
          Filter method called before a request has been dispatched to a client transport layer.
 void filter(ClientRequestContext requestContext, ClientResponseContext responseContext)
          Filter method called after a response has been provided for a request (either by a request filter or when the HTTP invocation returns.
 void filter(ContainerRequestContext context)
          Filter method called before a request has been dispatched to a resource.
 void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
          Filter method called after a response has been provided for a request (either by a request filter or by a matched resource method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggingFilter

public LoggingFilter()
Create a logging filter logging the request and response to a default JDK logger, named as the fully qualified class name of this class. Entity logging is turned off by default.


LoggingFilter

public LoggingFilter(Logger logger,
                     boolean printEntity)
Create a logging filter with custom logger and custom settings of entity logging.

Parameters:
logger - the logger to log requests and responses.
printEntity - if true, entity will be logged as well up to the default maxEntitySize, which is 10KB

LoggingFilter

public LoggingFilter(Logger logger,
                     int maxEntitySize)
Creates a logging filter with custom logger and entity logging turned on, but potentially limiting the size of entity to be buffered and logged.

Parameters:
logger - the logger to log requests and responses.
maxEntitySize - maximum number of entity bytes to be logged (and buffered) - if the entity is larger, logging filter will print (and buffer in memory) only the specified number of bytes and print "...more..." string at the end.
Method Detail

filter

public void filter(ClientRequestContext context)
            throws IOException
Description copied from interface: ClientRequestFilter
Filter method called before a request has been dispatched to a client transport layer. Filters in the filter chain are ordered according to their javax.annotation.Priority class-level annotation value.

Specified by:
filter in interface ClientRequestFilter
Parameters:
context - request context.
Throws:
IOException - if an I/O exception occurs.

filter

public void filter(ClientRequestContext requestContext,
                   ClientResponseContext responseContext)
            throws IOException
Description copied from interface: ClientResponseFilter
Filter method called after a response has been provided for a request (either by a request filter or when the HTTP invocation returns. Filters in the filter chain are ordered according to their javax.annotation.Priority class-level annotation value.

Specified by:
filter in interface ClientResponseFilter
Parameters:
requestContext - request context.
responseContext - response context.
Throws:
IOException - if an I/O exception occurs.

filter

public void filter(ContainerRequestContext context)
            throws IOException
Description copied from interface: ContainerRequestFilter
Filter method called before a request has been dispatched to a resource.

Filters in the filter chain are ordered according to their javax.annotation.Priority class-level annotation value. If a request filter produces a response by calling ContainerRequestContext.abortWith(javax.ws.rs.core.Response) method, the execution of the (either pre-match or post-match) request filter chain is stopped and the response is passed to the corresponding response filter chain (either pre-match or post-match). For example, a pre-match caching filter may produce a response in this way, which would effectively skip any post-match request filters as well as post-match response filters. Note however that a responses produced in this manner would still be processed by the pre-match response filter chain.

Specified by:
filter in interface ContainerRequestFilter
Parameters:
context - request context.
Throws:
IOException - if an I/O exception occurs.
See Also:
PreMatching

filter

public void filter(ContainerRequestContext requestContext,
                   ContainerResponseContext responseContext)
            throws IOException
Description copied from interface: ContainerResponseFilter
Filter method called after a response has been provided for a request (either by a request filter or by a matched resource method.

Filters in the filter chain are ordered according to their javax.annotation.Priority class-level annotation value.

Specified by:
filter in interface ContainerResponseFilter
Parameters:
requestContext - request context.
responseContext - response context.
Throws:
IOException - if an I/O exception occurs.

aroundWriteTo

public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext)
                   throws IOException,
                          WebApplicationException
Description copied from interface: WriterInterceptor
Interceptor method wrapping calls to MessageBodyWriter.writeTo(T, java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.OutputStream) method. The parameters of the wrapped method called are available from context. Implementations of this method SHOULD explicitly call WriterInterceptorContext.proceed() to invoke the next interceptor in the chain, and ultimately the wrapped MessageBodyWriter.writeTo method.

Specified by:
aroundWriteTo in interface WriterInterceptor
Parameters:
writerInterceptorContext - invocation context.
Throws:
IOException - if an IO error arises or is thrown by the wrapped MessageBodyWriter.writeTo method.
WebApplicationException - thrown by the wrapped MessageBodyWriter.writeTo method.


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.