Package com.bobocode.bring.web.servlet
Class RestControllerContext
java.lang.Object
com.bobocode.bring.web.servlet.RestControllerContext
The
RestControllerContext class represents the context for managing
REST controllers and their associated parameters in a web application.
This class is responsible for collecting and organizing information about controllers, resolving parameters and performing checks
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<BringServlet> List of registered BringServlet instances.static final StringError message prefix for duplicate paths.static final StringPackage name for java.lang.static final StringException message for unsupported type in @RequestBody annotation.static final StringException message for missing @RequestHeader annotation value.private final List<RequestParamsResolver> List of registered RequestParamsResolver instances. -
Constructor Summary
ConstructorsConstructorDescriptionRestControllerContext(List<BringServlet> bringServlets, List<RequestParamsResolver> requestParamsResolvers) Constructs a new RestControllerContext with the specified BringServlets and RequestParamsResolvers. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckOnDuplicatePath(Map<String, List<String>> methodToPathsMap) Checks for duplicate paths and throws an exception if found.private voidcheckParameters(Map<String, List<RestControllerParams>> params) Checks parameters for @RequestBody and @RequestHeader annotations.private voidcheckRequestBodyAnnotation(Method method, Parameter[] parameters, List<String> parameterNames, int index) Checks the type of parameter annotated with @RequestBody and throws an exception if unsupported.private voidcheckRequestHeaderAnnotation(Method method, Parameter[] parameters, List<String> parameterNames, int index) Checks the presence of a value in the @RequestHeader annotation for a method parameter.Retrieves a map containing controller paths and associated parameters.
-
Field Details
-
ERROR_ON_DUPLICATE_PATH
Error message prefix for duplicate paths.- See Also:
-
JAVA_LANG_PACKAGE
Package name for java.lang.- See Also:
-
REQUEST_HEADER_EXCEPTION_MESSAGE
Exception message for missing @RequestHeader annotation value.- See Also:
-
REQUEST_BODY_EXCEPTION_MESSAGE
Exception message for unsupported type in @RequestBody annotation.- See Also:
-
bringServlets
List of registered BringServlet instances. -
requestParamsResolvers
List of registered RequestParamsResolver instances.
-
-
Constructor Details
-
RestControllerContext
public RestControllerContext(List<BringServlet> bringServlets, List<RequestParamsResolver> requestParamsResolvers) Constructs a new RestControllerContext with the specified BringServlets and RequestParamsResolvers.- Parameters:
bringServlets- The list of BringServlet instances.requestParamsResolvers- The list of RequestParamsResolver instances.
-
-
Method Details
-
getParamsMap
Retrieves a map containing controller paths and associated parameters.- Returns:
- A map containing controller paths and associated parameters.
- Throws:
RequestPathDuplicateException- If duplicate paths are detected.RequestBodyTypeUnsupportedException- If an unsupported type is found in @RequestBody annotation.MissingRequestHeaderAnnotationValueException- If a missing @RequestHeader annotation value is detected.
-
checkOnDuplicatePath
Checks for duplicate paths and throws an exception if found.- Parameters:
methodToPathsMap- A map containing method names and associated paths.- Throws:
RequestPathDuplicateException- If duplicate paths are detected.
-
checkParameters
Checks parameters for @RequestBody and @RequestHeader annotations.- Parameters:
params- A map containing controller paths and associated parameters.- Throws:
RequestBodyTypeUnsupportedException- If an unsupported type is found in @RequestBody annotation.MissingRequestHeaderAnnotationValueException- If a missing @RequestHeader annotation value is detected.
-
checkRequestHeaderAnnotation
private void checkRequestHeaderAnnotation(Method method, Parameter[] parameters, List<String> parameterNames, int index) Checks the presence of a value in the @RequestHeader annotation for a method parameter.- Parameters:
method- The method containing the parameter.parameters- The array of parameters for the method.parameterNames- The list of parameter names for the method.index- The index of the parameter being checked.- Throws:
MissingRequestHeaderAnnotationValueException- If the @RequestHeader annotation value is blank.
-
checkRequestBodyAnnotation
private void checkRequestBodyAnnotation(Method method, Parameter[] parameters, List<String> parameterNames, int index) Checks the type of parameter annotated with @RequestBody and throws an exception if unsupported.- Parameters:
method- The method containing the parameter.parameters- The array of parameters for the method.parameterNames- The list of parameter names for the method.index- The index of the parameter being checked.- Throws:
RequestBodyTypeUnsupportedException- If the type annotated with @RequestBody is unsupported.
-