com.vaadin.hilla.

Class EndpointController

java.lang.Object
com.vaadin.hilla.EndpointController
@RestController @Import({EndpointControllerConfiguration.class,EndpointProperties.class}) public class EndpointController extends Object

The controller that is responsible for processing Vaadin endpoint requests. Each class that is annotated with Endpoint or BrowserCallable 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 Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String

    A qualifier to override the request and response default json mapper.

  • Constructor Summary

    Constructors
    Constructor
    Description
    EndpointController(org.springframework.context.ApplicationContext context, EndpointRegistry endpointRegistry, EndpointInvoker endpointInvoker, CsrfChecker csrfChecker, com.fasterxml.jackson.databind.ObjectMapper objectMapper)

    A constructor used to initialize the controller.

  • Method Summary

    Modifier and Type
    Method
    Description
    void

    Initializes the controller by registering all endpoints found in the OpenApi definition or, as a fallback, in the Spring context.

    org.springframework.http.ResponseEntity<String>
    serveEndpoint(String endpointName, String methodName, com.fasterxml.jackson.databind.node.ObjectNode body, jakarta.servlet.http.HttpServletRequest request)

    Captures and processes the Vaadin endpoint requests.

    org.springframework.http.ResponseEntity<String>
    serveEndpoint(String endpointName, String methodName, com.fasterxml.jackson.databind.node.ObjectNode body, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)

    Captures and processes the Vaadin endpoint requests.

    org.springframework.http.ResponseEntity<String>
    serveMultipartEndpoint(String endpointName, String methodName, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)

    Captures and processes the Vaadin multipart endpoint requests.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BODY_PART_NAME

      public static final String BODY_PART_NAME

      See Also:

    • ENDPOINT_MAPPER_FACTORY_BEAN_QUALIFIER

      public static final String ENDPOINT_MAPPER_FACTORY_BEAN_QUALIFIER

      A qualifier to override the request and response default json mapper.

      See Also:

  • Constructor Details

    • EndpointController

      public EndpointController(org.springframework.context.ApplicationContext context, EndpointRegistry endpointRegistry, EndpointInvoker endpointInvoker, CsrfChecker csrfChecker, @Qualifier("hillaEndpointObjectMapper") com.fasterxml.jackson.databind.ObjectMapper objectMapper)

      A constructor used to initialize the controller.

      Parameters:

      context - The Spring application context

      endpointRegistry - the registry used to store endpoint information

      endpointInvoker - then end point invoker

      csrfChecker - the csrf checker to use

  • Method Details

    • registerEndpoints

      public void registerEndpoints()

      Initializes the controller by registering all endpoints found in the OpenApi definition or, as a fallback, in the Spring context.

    • serveEndpoint

      @PostMapping(path="/{endpoint}/{method}", consumes="application/json", 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, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)

      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

      response - the current response

      Returns:

      execution result as a JSON string or an error message string

    • serveMultipartEndpoint

      @PostMapping(path="/{endpoint}/{method}", consumes="multipart/form-data", produces="application/json") public org.springframework.http.ResponseEntity<String> serveMultipartEndpoint(@PathVariable("endpoint") String endpointName, @PathVariable("method") String methodName, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException

      Captures and processes the Vaadin multipart endpoint requests. They are used when there are uploaded files.

      This method works as serveEndpoint(String, String, ObjectNode, HttpServletRequest, HttpServletResponse), but it also captures the files uploaded in the request.

      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

      request - the current multipart request which triggers the endpoint call

      response - the current response

      Returns:

      execution result as a JSON string or an error message string

      Throws:

      IOException

    • serveEndpoint

      public org.springframework.http.ResponseEntity<String> serveEndpoint(String endpointName, String methodName, com.fasterxml.jackson.databind.node.ObjectNode body, jakarta.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