com.vaadin.hilla.
Class EndpointController
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 -
Constructor Summary
ConstructorsConstructorDescriptionEndpointController
(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 TypeMethodDescriptionvoid
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.
-
Field Details
-
BODY_PART_NAME
See Also:
-
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 contextendpointRegistry
- the registry used to store endpoint informationendpointInvoker
- then end point invokercsrfChecker
- 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 sensitivemethodName
- the method name to execute on an endpoint, not case sensitivebody
- optional request body, that should be specified if the method called has parametersrequest
- the current request which triggers the endpoint callresponse
- the current responseReturns:
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 sensitivemethodName
- the method name to execute on an endpoint, not case sensitiverequest
- the current multipart request which triggers the endpoint callresponse
- the current responseReturns:
execution result as a JSON string or an error message string
Throws:
-
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 sensitivemethodName
- the method name to execute on an endpoint, not case sensitivebody
- optional request body, that should be specified if the method called has parametersrequest
- the current request which triggers the endpoint callReturns:
execution result as a JSON string or an error message string
-