Class EndpointController
- java.lang.Object
-
- dev.hilla.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 ObjectThe controller that is responsible for processing Vaadin endpoint requests. Each class that is annotated withEndpointgets its public methods exposed so that those can be triggered by a correct POST request, including the methods inherited from the other classes, excludingObjectclass ones. Other methods (non-public) are not considered by the controller.For example, if a class with name
TestClassthat has the only public methodtestMethodwas 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 StringVAADIN_ENDPOINT_MAPPER_BEAN_QUALIFIERA 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)A constructor used to initialize the controller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.http.ResponseEntity<String>serveEndpoint(String endpointName, String methodName, com.fasterxml.jackson.databind.node.ObjectNode body, javax.servlet.http.HttpServletRequest request)Captures and processes the Vaadin endpoint requests.
-
-
-
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 withEndpointfromendpointRegistry- the registry used to store endpoint informationendpointInvoker- then end point invokercsrfChecker- 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 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 call- Returns:
- execution result as a JSON string or an error message string
-
-