Class LoggingInterceptor

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  LoggingInterceptor.LoggingStream
      Helper class used to log an entity to the output stream up to the specified maximum number of bytes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.concurrent.atomic.AtomicLong _id  
      private static java.util.Comparator<java.util.Map.Entry<java.lang.String,​java.util.List<java.lang.String>>> COMPARATOR  
      (package private) static java.lang.String ENTITY_LOGGER_PROPERTY
      The entity stream property
      (package private) java.util.logging.Level level  
      (package private) java.util.logging.Logger logger  
      (package private) static java.lang.String LOGGING_ID_PROPERTY
      Logging record id property
      (package private) int maxEntitySize  
      private static java.lang.String NOTIFICATION_PREFIX  
      private static java.util.Set<javax.ws.rs.core.MediaType> READABLE_APP_MEDIA_TYPES  
      (package private) static java.lang.String REQUEST_PREFIX
      Prefix will be printed before requests
      (package private) static java.lang.String RESPONSE_PREFIX
      Prefix will be printed before response
      private static javax.ws.rs.core.MediaType TEXT_MEDIA_TYPE  
      (package private) LoggingFeature.Verbosity verbosity  
    • Constructor Summary

      Constructors 
      Constructor Description
      LoggingInterceptor​(java.util.logging.Logger logger, java.util.logging.Level level, LoggingFeature.Verbosity verbosity, 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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void aroundWriteTo​(javax.ws.rs.ext.WriterInterceptorContext writerInterceptorContext)  
      (package private) java.util.Set<java.util.Map.Entry<java.lang.String,​java.util.List<java.lang.String>>> getSortedHeaders​(java.util.Set<java.util.Map.Entry<java.lang.String,​java.util.List<java.lang.String>>> headers)  
      (package private) static boolean isReadable​(javax.ws.rs.core.MediaType mediaType)
      Returns true if specified MediaType is considered textual.
      (package private) void log​(java.lang.StringBuilder b)
      Logs a StringBuilder parameter at required level.
      (package private) java.io.InputStream logInboundEntity​(java.lang.StringBuilder b, java.io.InputStream stream, java.nio.charset.Charset charset)  
      private java.lang.StringBuilder prefixId​(java.lang.StringBuilder b, long id)  
      (package private) static boolean printEntity​(LoggingFeature.Verbosity verbosity, javax.ws.rs.core.MediaType mediaType)
      Returns true if entity has to be printed.
      (package private) void printPrefixedHeaders​(java.lang.StringBuilder b, long id, java.lang.String prefix, javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> headers)  
      (package private) void printRequestLine​(java.lang.StringBuilder b, java.lang.String note, long id, java.lang.String method, java.net.URI uri)  
      (package private) void printResponseLine​(java.lang.StringBuilder b, java.lang.String note, long id, int status)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • REQUEST_PREFIX

        static final java.lang.String REQUEST_PREFIX
        Prefix will be printed before requests
        See Also:
        Constant Field Values
      • RESPONSE_PREFIX

        static final java.lang.String RESPONSE_PREFIX
        Prefix will be printed before response
        See Also:
        Constant Field Values
      • ENTITY_LOGGER_PROPERTY

        static final java.lang.String ENTITY_LOGGER_PROPERTY
        The entity stream property
      • LOGGING_ID_PROPERTY

        static final java.lang.String LOGGING_ID_PROPERTY
        Logging record id property
      • NOTIFICATION_PREFIX

        private static final java.lang.String NOTIFICATION_PREFIX
        See Also:
        Constant Field Values
      • TEXT_MEDIA_TYPE

        private static final javax.ws.rs.core.MediaType TEXT_MEDIA_TYPE
      • READABLE_APP_MEDIA_TYPES

        private static final java.util.Set<javax.ws.rs.core.MediaType> READABLE_APP_MEDIA_TYPES
      • COMPARATOR

        private static final java.util.Comparator<java.util.Map.Entry<java.lang.String,​java.util.List<java.lang.String>>> COMPARATOR
      • logger

        final java.util.logging.Logger logger
      • level

        final java.util.logging.Level level
      • _id

        final java.util.concurrent.atomic.AtomicLong _id
      • maxEntitySize

        final int maxEntitySize
    • Constructor Detail

      • LoggingInterceptor

        LoggingInterceptor​(java.util.logging.Logger logger,
                           java.util.logging.Level level,
                           LoggingFeature.Verbosity verbosity,
                           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 messages to.
        level - level at which the messages will be logged.
        verbosity - verbosity of the logged messages. See LoggingFeature.Verbosity.
        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. Negative values are interpreted as zero.
    • Method Detail

      • log

        void log​(java.lang.StringBuilder b)
        Logs a StringBuilder parameter at required level.
        Parameters:
        b - message to log
      • prefixId

        private java.lang.StringBuilder prefixId​(java.lang.StringBuilder b,
                                                 long id)
      • printRequestLine

        void printRequestLine​(java.lang.StringBuilder b,
                              java.lang.String note,
                              long id,
                              java.lang.String method,
                              java.net.URI uri)
      • printResponseLine

        void printResponseLine​(java.lang.StringBuilder b,
                               java.lang.String note,
                               long id,
                               int status)
      • printPrefixedHeaders

        void printPrefixedHeaders​(java.lang.StringBuilder b,
                                  long id,
                                  java.lang.String prefix,
                                  javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> headers)
      • getSortedHeaders

        java.util.Set<java.util.Map.Entry<java.lang.String,​java.util.List<java.lang.String>>> getSortedHeaders​(java.util.Set<java.util.Map.Entry<java.lang.String,​java.util.List<java.lang.String>>> headers)
      • logInboundEntity

        java.io.InputStream logInboundEntity​(java.lang.StringBuilder b,
                                             java.io.InputStream stream,
                                             java.nio.charset.Charset charset)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • aroundWriteTo

        public void aroundWriteTo​(javax.ws.rs.ext.WriterInterceptorContext writerInterceptorContext)
                           throws java.io.IOException,
                                  javax.ws.rs.WebApplicationException
        Specified by:
        aroundWriteTo in interface javax.ws.rs.ext.WriterInterceptor
        Throws:
        java.io.IOException
        javax.ws.rs.WebApplicationException
      • isReadable

        static boolean isReadable​(javax.ws.rs.core.MediaType mediaType)
        Returns true if specified MediaType is considered textual.

        See READABLE_APP_MEDIA_TYPES.

        Parameters:
        mediaType - the media type of the entity
        Returns:
        true if specified MediaType is considered textual.
      • printEntity

        static boolean printEntity​(LoggingFeature.Verbosity verbosity,
                                   javax.ws.rs.core.MediaType mediaType)
        Returns true if entity has to be printed.
        Parameters:
        verbosity - the configured verbosity .
        mediaType - the media type of the payload.
        Returns:
        true if entity has to be printed.