Package com.helger.xservlet.handler
Class XServletHandlerRegistry
- java.lang.Object
-
- com.helger.xservlet.handler.XServletHandlerRegistry
-
@NotThreadSafe public class XServletHandlerRegistry extends Object
Wrapper around a map fromEHttpMethodtoIXServletHandler.- Since:
- 9.0.0
- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description XServletHandlerRegistry()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.helger.commons.state.EChangecopyHandler(com.helger.commons.http.EHttpMethod eFromMethod, Set<com.helger.commons.http.EHttpMethod> aToMethods)Copy an existing handler of a certain HTTP method to another HTTP method.com.helger.commons.state.EChangecopyHandlerToAll(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.voidforEachHandler(Consumer<? super IXServletHandler> aConsumer)<EXTYPE extends Throwable>
voidforEachHandlerThrowing(com.helger.commons.functional.IThrowingConsumer<? super IXServletHandler,EXTYPE> aConsumer)EnumSet<com.helger.commons.http.EHttpMethod>getAllowedHTTPMethods()StringgetAllowedHttpMethodsString()IXServletHandlergetHandler(com.helger.commons.http.EHttpMethod eHttpMethod)voidregisterHandler(com.helger.commons.http.EHttpMethod eMethod, com.helger.servlet.async.ServletAsyncSpec aAsyncSpec, IXServletSimpleHandler aSimpleHandler)voidregisterHandler(com.helger.commons.http.EHttpMethod eMethod, IXServletHandler aLowLevelHandler, boolean bAllowOverwrite)Register a handler for the provided HTTP method.voidregisterHandler(com.helger.commons.http.EHttpMethod eMethod, IXServletSimpleHandler aSimpleHandler)StringtoString()com.helger.commons.state.EChangeunregisterHandler(com.helger.commons.http.EHttpMethod eMethod)Remove the handler for a certain HTTP method.
-
-
-
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 benull.aLowLevelHandler- The handler to register. May not benull.bAllowOverwrite- iftrueexisting handler can be overwritten, iffalsethis method will throw anIllegalStateException.
-
registerHandler
public void registerHandler(@Nonnull com.helger.commons.http.EHttpMethod eMethod, @Nonnull IXServletSimpleHandler aSimpleHandler)
-
registerHandler
public void registerHandler(@Nonnull com.helger.commons.http.EHttpMethod eMethod, @Nonnull com.helger.servlet.async.ServletAsyncSpec aAsyncSpec, @Nonnull IXServletSimpleHandler aSimpleHandler)
-
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 benull.- Returns:
EChange.CHANGEDif removal was successful,EChange.UNCHANGEDotherwise. Nevernull.- 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 benull.aToMethods- Destination methods. May not benulland may not containnullvalues.- Returns:
EChange.UNCHANGEDif no existing handler was found,EChange.CHANGEDif 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 benull. Should be one of GET, POST, PUT, DELETE or PATCH.- Returns:
EChange.UNCHANGEDif no existing handler was found,EChange.CHANGEDif 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()
-
getHandler
@Nullable public IXServletHandler getHandler(@Nonnull com.helger.commons.http.EHttpMethod eHttpMethod)
-
forEachHandler
public void forEachHandler(@Nonnull Consumer<? super IXServletHandler> aConsumer)
-
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
-
-