Package dev.hilla

Class EndpointController


  • @RestController
    @Import({EndpointControllerConfiguration.class,EndpointProperties.class})
    @NpmPackage(value="@hilla/frontend",version="1.3.21") @NpmPackage(value="@hilla/form",version="1.3.21")
    public class EndpointController
    extends Object
    The controller that is responsible for processing Vaadin endpoint requests. Each class that is annotated with Endpoint gets its public methods exposed so that those can be triggered by a correct POST request, including the methods inherited from the other classes, excluding Object class ones. Other methods (non-public) are not considered by the controller.

    For example, if a class with name TestClass that has the only public method testMethod was annotated with the annotation, it can be called via http://${base_url}/testclass/testmethod POST call, where ${base_url} is the application base url, configured by the user. Class name and method name case in the request URL does not matter, but if the method has parameters, the request body should contain a valid JSON with all parameters in the same order as they are declared in the method. The parameter types should also correspond for the request to be successful.

    • Field Detail

      • VAADIN_ENDPOINT_MAPPER_BEAN_QUALIFIER

        public static final String VAADIN_ENDPOINT_MAPPER_BEAN_QUALIFIER
        A qualifier to override the request and response default json mapper.
        See Also:
        Constant Field Values
    • Constructor Detail

      • EndpointController

        public EndpointController​(org.springframework.context.ApplicationContext context,
                                  EndpointRegistry endpointRegistry,
                                  EndpointInvoker endpointInvoker,
                                  CsrfChecker csrfChecker)
        A constructor used to initialize the controller.
        Parameters:
        context - Spring context to extract beans annotated with Endpoint from
        endpointRegistry - the registry used to store endpoint information
        endpointInvoker - then end point invoker
        csrfChecker - the csrf checker to use
    • Method Detail

      • serveEndpoint

        @PostMapping(path="/{endpoint}/{method}",
                     produces="application/json;charset=UTF-8")
        public org.springframework.http.ResponseEntity<String> serveEndpoint​(@PathVariable("endpoint")
                                                                             String endpointName,
                                                                             @PathVariable("method")
                                                                             String methodName,
                                                                             @RequestBody(required=false)
                                                                             com.fasterxml.jackson.databind.node.ObjectNode body,
                                                                             javax.servlet.http.HttpServletRequest request)
        Captures and processes the Vaadin endpoint requests.

        Matches the endpoint name and a method name with the corresponding Java class and a public method in the class. Extracts parameters from a request body if the Java method requires any and applies in the same order. After the method call, serializes the Java method execution result and sends it back.

        If an issue occurs during the request processing, an error response is returned instead of the serialized Java method return value.

        Parameters:
        endpointName - the name of an endpoint to address the calls to, not case sensitive
        methodName - the method name to execute on an endpoint, not case sensitive
        body - optional request body, that should be specified if the method called has parameters
        request - the current request which triggers the endpoint call
        Returns:
        execution result as a JSON string or an error message string