Class XServletHandlerRegistry


  • @NotThreadSafe
    public class XServletHandlerRegistry
    extends Object
    Wrapper around a map from EHttpMethod to IXServletHandler.
    Since:
    9.0.0
    Author:
    Philip Helger
    • Constructor Detail

      • XServletHandlerRegistry

        public XServletHandlerRegistry()
    • Method Detail

      • registerHandler

        public void registerHandler​(@Nonnull
                                    com.helger.commons.http.EHttpMethod eMethod,
                                    @Nonnull
                                    IXServletHandler aLowLevelHandler,
                                    boolean bAllowOverwrite)
        Register a handler for the provided HTTP method. If another handler is already registered, the new registration overwrites the old one.
        Parameters:
        eMethod - The HTTP method to register for. May not be null.
        aLowLevelHandler - The handler to register. May not be null.
        bAllowOverwrite - if true existing handler can be overwritten, if false this method will throw an IllegalStateException.
      • unregisterHandler

        @Nonnull
        public com.helger.commons.state.EChange unregisterHandler​(@Nullable
                                                                  com.helger.commons.http.EHttpMethod eMethod)
        Remove the handler for a certain HTTP method.
        Parameters:
        eMethod - The HTTP method to be used. May be null.
        Returns:
        EChange.CHANGED if removal was successful, EChange.UNCHANGED otherwise. Never null.
        Since:
        9.3.2
      • copyHandler

        public com.helger.commons.state.EChange copyHandler​(@Nonnull
                                                            com.helger.commons.http.EHttpMethod eFromMethod,
                                                            @Nonnull @Nonempty
                                                            Set<com.helger.commons.http.EHttpMethod> aToMethods)
        Copy an existing handler of a certain HTTP method to another HTTP method. The same instance of the handler is re-used!
        Parameters:
        eFromMethod - Source method. May not be null.
        aToMethods - Destination methods. May not be null and may not contain null values.
        Returns:
        EChange.UNCHANGED if no existing handler was found, EChange.CHANGED if at least one handler was copied.
        Throws:
        IllegalStateException - In another handler is already registered for one of the destination methods.
        See Also:
        copyHandlerToAll(EHttpMethod)
      • copyHandlerToAll

        @Nonnull
        public com.helger.commons.state.EChange copyHandlerToAll​(@Nonnull
                                                                 com.helger.commons.http.EHttpMethod eFromMethod)
        Copy the handler of the passed method to all other HTTP methods in the range of GET, POST, PUT, DELETE and PATCH.
        Parameters:
        eFromMethod - From method. May not be null. Should be one of GET, POST, PUT, DELETE or PATCH.
        Returns:
        EChange.UNCHANGED if no existing handler was found, EChange.CHANGED if at least one handler was copied.
        Throws:
        IllegalStateException - In another handler is already registered for one of the destination methods.
        See Also:
        copyHandler(EHttpMethod, Set)
      • getAllowedHTTPMethods

        @Nonnull
        @ReturnsMutableCopy
        public EnumSet<com.helger.commons.http.EHttpMethod> getAllowedHTTPMethods()
      • getAllowedHttpMethodsString

        @Nonnull
        public String getAllowedHttpMethodsString()
      • forEachHandlerThrowing

        public <EXTYPE extends Throwable> void forEachHandlerThrowing​(@Nonnull
                                                                      com.helger.commons.functional.IThrowingConsumer<? super IXServletHandler,​EXTYPE> aConsumer)
                                                               throws EXTYPE extends Throwable
        Throws:
        EXTYPE extends Throwable