Interface HttpComponent<T extends HttpComponent<T>>
- Type Parameters:
T- the generic type of the component implementing this class.
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
HttpServer
- All Known Implementing Classes:
NettyHttpServer
Represents any http component, providing an abstract layer for registering listeners to it.
- Since:
- 4.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGet a http annotation parser which is associated with this component and can therefore be used to register annotated handlers to this component.Removes all handlers which were previously registered to this component.Get all handlers which were registered to this component.registerHandler(@NonNull String path, int priority, @NonNull HttpHandler... handlers) Registers the given handlers to this component.registerHandler(@NonNull String path, @NonNull HttpHandler... handlers) Registers the given handlers to this component.registerHandler(@NonNull String path, @Nullable Integer port, int priority, @NonNull HttpHandler... handlers) Registers the given handlers to this component.removeHandler(@NonNull HttpHandler handler) Unregisters the given handler from this component if it was registered previously.removeHandler(@NonNull ClassLoader classLoader) Removes all registered handlers from this component whose classes were loaded by the given class loader.booleanGets whether this component has ssl enabled or not.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
sslEnabled
boolean sslEnabled()Gets whether this component has ssl enabled or not.- Returns:
- whether this component has ssl enabled or not.
-
annotationParser
Get a http annotation parser which is associated with this component and can therefore be used to register annotated handlers to this component.- Returns:
- the associated http annotation parser instance.
-
registerHandler
@NonNull T registerHandler(@NonNull @NonNull String path, @NonNull @NonNull HttpHandler... handlers) Registers the given handlers to this component. The given handlers will get called when a request matches the given path. Equivalent tocomponent.registerHandler(path, HttpHandler.PRIORITY_NORMAL, handlers).- Parameters:
path- the path to register the handler to.handlers- the handlers to register.- Returns:
- the same component instance as used to call the method, for chaining.
- Throws:
NullPointerException- if either the given path or handlers are null.
-
registerHandler
@NonNull T registerHandler(@NonNull @NonNull String path, int priority, @NonNull @NonNull HttpHandler... handlers) Registers the given handlers to this component. The given handlers will get called when a request matches the given path. Equivalent tocomponent.registerHandler(path, null, priority, handlers).- Parameters:
path- the path to register the handler to.priority- the priority of the given handlers.handlers- the handlers to register.- Returns:
- the same component instance as used to call the method, for chaining.
- Throws:
NullPointerException- if either the given path or handlers are null.
-
registerHandler
@NonNull T registerHandler(@NonNull @NonNull String path, @Nullable @Nullable Integer port, int priority, @NonNull @NonNull HttpHandler... handlers) Registers the given handlers to this component. The given handlers will get called when a request matches the given path and (if provided) gets called on the same port as set here. The path may contain the following placeholders:*: Represents a wildcard character which matches anything provided in the path.{name}: Represents a path parameter you want to retrieve when handling the request.
- Parameters:
path- the path to register the handler to.port- the port on which the handlers should get called, null represents all ports.priority- the priority of the given handlers.handlers- the handlers to register.- Returns:
- the same component instance as used to call the method, for chaining.
- Throws:
NullPointerException- if either the given path or handlers are null.
-
removeHandler
Unregisters the given handler from this component if it was registered previously.- Parameters:
handler- the handler to unregister.- Returns:
- the same component instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given handler is null.
-
removeHandler
Removes all registered handlers from this component whose classes were loaded by the given class loader.- Parameters:
classLoader- the loader of the handler classes to unregister.- Returns:
- the same component instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given class loader is null.
-
httpHandlers
Get all handlers which were registered to this component.- Returns:
- all handlers which were registered to this component.
-
clearHandlers
Removes all handlers which were previously registered to this component.- Returns:
- the same component instance as used to call the method, for chaining.
-