Class RestControllerContext

java.lang.Object
com.bobocode.bring.web.servlet.RestControllerContext

public class RestControllerContext extends Object
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 Details

    • ERROR_ON_DUPLICATE_PATH

      public static final String ERROR_ON_DUPLICATE_PATH
      Error message prefix for duplicate paths.
      See Also:
    • JAVA_LANG_PACKAGE

      public static final String JAVA_LANG_PACKAGE
      Package name for java.lang.
      See Also:
    • REQUEST_HEADER_EXCEPTION_MESSAGE

      public static final String REQUEST_HEADER_EXCEPTION_MESSAGE
      Exception message for missing @RequestHeader annotation value.
      See Also:
    • REQUEST_BODY_EXCEPTION_MESSAGE

      public static final String REQUEST_BODY_EXCEPTION_MESSAGE
      Exception message for unsupported type in @RequestBody annotation.
      See Also:
    • bringServlets

      private final List<BringServlet> bringServlets
      List of registered BringServlet instances.
    • requestParamsResolvers

      private final List<RequestParamsResolver> 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

      public Map<String,List<RestControllerParams>> 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

      private void checkOnDuplicatePath(Map<String,List<String>> methodToPathsMap)
      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

      private void checkParameters(Map<String,List<RestControllerParams>> params)
      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.