Class ReportPortalRestAssuredLoggingFilter

  • All Implemented Interfaces:
    io.restassured.filter.Filter, io.restassured.filter.OrderedFilter

    public class ReportPortalRestAssuredLoggingFilter
    extends com.epam.reportportal.formatting.AbstractHttpFormatter<ReportPortalRestAssuredLoggingFilter>
    implements io.restassured.filter.OrderedFilter
    REST Assured Request/Response logging filter for Report Portal.

    The filter intercept and logs all Requests and Responses issued by REST Assured into Report Portal in Markdown format, including multipart requests. It recognizes payload types and attach them in corresponding manner: image types will be logged as images with thumbnails, binary types will be logged as entry attachments, text types will be formatted and logged in Markdown code blocks.

    Basic usage:

         RestAssured.filters(new ReportPortalRestAssuredLoggingFilter(42, LogLevel.INFO));
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String NULL_RESPONSE  
      protected java.util.function.Function<com.epam.reportportal.formatting.http.entities.Param,​java.lang.String> paramConverter  
      • Fields inherited from class com.epam.reportportal.formatting.AbstractHttpFormatter

        cookieConverter, headerConverter, logLevel, partHeaderConverter, uriConverter
      • Fields inherited from interface io.restassured.filter.OrderedFilter

        DEFAULT_PRECEDENCE, HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      Constructor Description
      ReportPortalRestAssuredLoggingFilter​(int filterOrder, com.epam.reportportal.listeners.LogLevel defaultLogLevel)
      Create an ordered REST Assured filter with the log level.
      ReportPortalRestAssuredLoggingFilter​(int filterOrder, com.epam.reportportal.listeners.LogLevel defaultLogLevel, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> headerConvertFunction, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> partHeaderConvertFunction)
      Create an ordered REST Assured filter with the log level and header converters.
      ReportPortalRestAssuredLoggingFilter​(int filterOrder, com.epam.reportportal.listeners.LogLevel defaultLogLevel, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> headerConvertFunction, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> partHeaderConvertFunction, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Cookie,​java.lang.String> cookieConvertFunction)
      Create an ordered REST Assured filter with the log level and different converters.
      ReportPortalRestAssuredLoggingFilter​(int filterOrder, com.epam.reportportal.listeners.LogLevel defaultLogLevel, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> headerConvertFunction, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> partHeaderConvertFunction, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Cookie,​java.lang.String> cookieConvertFunction, java.util.function.Function<java.lang.String,​java.lang.String> uriConverterFunction)
      Create an ordered REST Assured filter with the log level and different converters.z
      ReportPortalRestAssuredLoggingFilter​(int filterOrder, com.epam.reportportal.listeners.LogLevel defaultLogLevel, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> headerConvertFunction, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> partHeaderConvertFunction, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Cookie,​java.lang.String> cookieConvertFunction, java.util.function.Function<java.lang.String,​java.lang.String> uriConverterFunction, java.util.function.Function<com.epam.reportportal.formatting.http.entities.Param,​java.lang.String> paramConverter)
      Create an ordered REST Assured filter with the log level and different converters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ReportPortalRestAssuredLoggingFilter addRequestFilter​(java.util.function.Predicate<io.restassured.specification.FilterableRequestSpecification> requestFilter)
      Add a request filter to the filter.
      io.restassured.response.Response filter​(io.restassured.specification.FilterableRequestSpecification requestSpec, io.restassured.specification.FilterableResponseSpecification responseSpec, io.restassured.filter.FilterContext ctx)  
      int getOrder()  
      • Methods inherited from class com.epam.reportportal.formatting.AbstractHttpFormatter

        attachAsBinary, emitLog, getBodyTypeMap, getContentPrettifiers, logMultiPartRequest, setBodyTypeMap, setContentPrettifiers
      • Methods inherited from class java.lang.Object

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

      • paramConverter

        protected final java.util.function.Function<com.epam.reportportal.formatting.http.entities.Param,​java.lang.String> paramConverter
    • Constructor Detail

      • ReportPortalRestAssuredLoggingFilter

        public ReportPortalRestAssuredLoggingFilter​(int filterOrder,
                                                    @Nonnull
                                                    com.epam.reportportal.listeners.LogLevel defaultLogLevel,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> headerConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> partHeaderConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Cookie,​java.lang.String> cookieConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<java.lang.String,​java.lang.String> uriConverterFunction,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Param,​java.lang.String> paramConverter)
        Create an ordered REST Assured filter with the log level and different converters.
        Parameters:
        filterOrder - if you have different filters which modify requests on fly this parameter allows you to control the order when Report Portal logger will be called, and therefore log or don't log some data.
        defaultLogLevel - log level on which REST Assured requests/responses will appear on Report Portal
        headerConvertFunction - if you want to preprocess your HTTP Headers before they appear on Report Portal provide this custom function for the class, default function formats it like that: header.getName() + ": " + header.getValue()
        partHeaderConvertFunction - the same as fot HTTP Headers, but for parts in Multipart request
        cookieConvertFunction - the same as 'headerConvertFunction' param but for Cookies, default function formats Cookies with toString method
        uriConverterFunction - the same as 'headerConvertFunction' param but for URI, default function returns URI "as is"
        paramConverter - the same as 'headerConvertFunction' param but for Web Form Params, default function returns param.getName() + ": " + param.getValue()
      • ReportPortalRestAssuredLoggingFilter

        public ReportPortalRestAssuredLoggingFilter​(int filterOrder,
                                                    @Nonnull
                                                    com.epam.reportportal.listeners.LogLevel defaultLogLevel,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> headerConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> partHeaderConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Cookie,​java.lang.String> cookieConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<java.lang.String,​java.lang.String> uriConverterFunction)
        Create an ordered REST Assured filter with the log level and different converters.z
        Parameters:
        filterOrder - if you have different filters which modify requests on fly this parameter allows you to control the order when Report Portal logger will be called, and therefore log or don't log some data.
        defaultLogLevel - log level on which REST Assured requests/responses will appear on Report Portal
        headerConvertFunction - if you want to preprocess your HTTP Headers before they appear on Report Portal provide this custom function for the class, default function formats it like that: header.getName() + ": " + header.getValue()
        partHeaderConvertFunction - the same as fot HTTP Headers, but for parts in Multipart request
        cookieConvertFunction - the same as 'headerConvertFunction' param but for Cookies, default function formats Cookies with toString method
        uriConverterFunction - the same as 'headerConvertFunction' param but for URI, default function returns URI "as is"
      • ReportPortalRestAssuredLoggingFilter

        public ReportPortalRestAssuredLoggingFilter​(int filterOrder,
                                                    @Nonnull
                                                    com.epam.reportportal.listeners.LogLevel defaultLogLevel,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> headerConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> partHeaderConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Cookie,​java.lang.String> cookieConvertFunction)
        Create an ordered REST Assured filter with the log level and different converters.
        Parameters:
        filterOrder - if you have different filters which modify requests on fly this parameter allows you to control the order when Report Portal logger will be called, and therefore log or don't log some data.
        defaultLogLevel - log level on which REST Assured requests/responses will appear on Report Portal
        headerConvertFunction - if you want to preprocess your HTTP Headers before they appear on Report Portal provide this custom function for the class, default function formats it like that: header.getName() + ": " + header.getValue()
        partHeaderConvertFunction - the same as fot HTTP Headers, but for parts in Multipart request
        cookieConvertFunction - the same as 'headerConvertFunction' param but for Cookies, default function formats Cookies with toString method
      • ReportPortalRestAssuredLoggingFilter

        public ReportPortalRestAssuredLoggingFilter​(int filterOrder,
                                                    @Nonnull
                                                    com.epam.reportportal.listeners.LogLevel defaultLogLevel,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> headerConvertFunction,
                                                    @Nullable
                                                    java.util.function.Function<com.epam.reportportal.formatting.http.entities.Header,​java.lang.String> partHeaderConvertFunction)
        Create an ordered REST Assured filter with the log level and header converters.
        Parameters:
        filterOrder - if you have different filters which modify requests on fly this parameter allows you to control the order when Report Portal logger will be called, and therefore log or don't log some data.
        defaultLogLevel - log level on which REST Assured requests/responses will appear on Report Portal
        headerConvertFunction - if you want to preprocess your HTTP Headers before they appear on Report Portal provide this custom function for the class, default function formats it like that: header.getName() + ": " + header.getValue()
        partHeaderConvertFunction - the same as fot HTTP Headers, but for parts in Multipart request
      • ReportPortalRestAssuredLoggingFilter

        public ReportPortalRestAssuredLoggingFilter​(int filterOrder,
                                                    @Nonnull
                                                    com.epam.reportportal.listeners.LogLevel defaultLogLevel)
        Create an ordered REST Assured filter with the log level.
        Parameters:
        filterOrder - if you have different filters which modify requests on fly this parameter allows you to control the order when Report Portal logger will be called, and therefore log or don't log some data.
        defaultLogLevel - log level on which REST Assured requests/responses will appear on Report Portal
    • Method Detail

      • getOrder

        public int getOrder()
        Specified by:
        getOrder in interface io.restassured.filter.OrderedFilter
      • filter

        public io.restassured.response.Response filter​(io.restassured.specification.FilterableRequestSpecification requestSpec,
                                                       io.restassured.specification.FilterableResponseSpecification responseSpec,
                                                       io.restassured.filter.FilterContext ctx)
        Specified by:
        filter in interface io.restassured.filter.Filter
      • addRequestFilter

        @Nonnull
        public ReportPortalRestAssuredLoggingFilter addRequestFilter​(@Nonnull
                                                                     java.util.function.Predicate<io.restassured.specification.FilterableRequestSpecification> requestFilter)
        Add a request filter to the filter.

        The filter is used to determine whether the request should be logged or not. If the filter returns true, the request will be skipped, otherwise it will be logged.

        Parameters:
        requestFilter - the request filter
        Returns:
        the filter instance