Class LicenseFilter

  • All Implemented Interfaces:
    Filter

    public class LicenseFilter
    extends HttpFilter
    Allows to check license when accessing end-points.

    When the license is not verified, the filter strategy depends on the Accept header received:

    • For a known OSLC media type (application/rdf+xml, application/xml, text/xml, application/json, text/turtle), the filter chain is aborted and the response contains an OSLC Error entity.
    • For a text/html or a wildcard media type, the filter chain is processed and an error message is added as an attribute of the request. This enables the servlet to provide an HTML page which displays a license error message at its convenience, using the getLicenseError(HttpServletRequest) method.
    • For any other media types, the filter chain is aborted and the response contains an error message with a text/plain content type.
    Since:
    2.0.0
    See Also:
    getLicenseError(HttpServletRequest)
    • Constructor Detail

      • LicenseFilter

        public LicenseFilter()
    • Method Detail

      • getLicenseError

        public static Optional<String> getLicenseError​(HttpServletRequest request)
        Allows to request attribute containing a license error message, if any. This shall be used by a servlet producing HTML content to include the license error as part of the page, at its convenience.
        Parameters:
        request - the received request
        Returns:
        an optional string if an error message is present, optional empty otherwise.
      • handleLicenseException

        protected void handleLicenseException​(HttpServletRequest request,
                                              HttpServletResponse response,
                                              FilterChain chain,
                                              OslcError error)
                                       throws IOException,
                                              ServletException
        Handles the behavior of the filter when the license is not verified, depending on the received Accept header.
        Parameters:
        request - the received request
        response - the response to send
        chain - the filter chain to proceed
        error - the license error received when checking license
        Throws:
        IOException - exception can be thrown when writing response
        ServletException - exception can be thrown when processing filter
        Since:
        2.0.0