public abstract class SynchronizedRequestHandler extends Object implements RequestHandler
synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse)
is called and unlocked after it has completed.| Modifier and Type | Class and Description |
|---|---|
static interface |
SynchronizedRequestHandler.ResponseWriter
ResponseWriter is optionally returned by request handlers which implement
synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse, String)
The ResponseWriter will be executed by
handleRequest(VaadinSession, VaadinRequest, VaadinResponse)
without holding Vaadin session lock. |
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_BUFFER_SIZE |
| Constructor and Description |
|---|
SynchronizedRequestHandler() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
canHandleRequest(VaadinRequest request)
Check whether a request may be handled by this handler.
|
static long |
getMaxRequestBodySize(VaadinRequest request)
Gets the configured maximum request body size for the given request, in
characters.
|
static String |
getRequestBody(Reader reader)
Reads the entire request body from the given reader without any size
limit.
|
static String |
getRequestBody(Reader reader,
long maxBodySize)
Reads the request body from the given reader, rejecting it once it
exceeds
maxBodySize characters. |
boolean |
handleRequest(VaadinSession session,
VaadinRequest request,
VaadinResponse response)
Called when a request needs to be handled.
|
boolean |
isReadAndWriteOutsideSessionLock()
Gets if request body should be read and the response written without
holding
VaadinSession lock |
abstract boolean |
synchronizedHandleRequest(VaadinSession session,
VaadinRequest request,
VaadinResponse response)
Identical to
handleRequest(VaadinSession, VaadinRequest, VaadinResponse)
except the VaadinSession is locked before this is called and
unlocked after this has completed. |
Optional<SynchronizedRequestHandler.ResponseWriter> |
synchronizedHandleRequest(VaadinSession session,
VaadinRequest request,
VaadinResponse response,
String requestBody)
Identical to
synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse)
except the VaadinSession is locked before this is called and the
response requestBody has been read before locking the session and is
provided as a separate parameter. |
public static final int MAX_BUFFER_SIZE
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
RequestHandlertrue to indicate that no more request
handlers should be invoked for the request.
Note that request handlers by default do not lock the session. If you are
using VaadinSession or anything inside the VaadinSession you must ensure
the session is locked. This can be done by extending
SynchronizedRequestHandler or by using
VaadinSession.accessSynchronously(Command) or
UI.accessSynchronously(Command).
handleRequest in interface RequestHandlersession - The session for the requestrequest - The request to handleresponse - The response object to which a response can be written.IOException - If an IO error occurredpublic abstract boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
handleRequest(VaadinSession, VaadinRequest, VaadinResponse)
except the VaadinSession is locked before this is called and
unlocked after this has completed.session - The session for the requestrequest - The request to handleresponse - The response object to which a response can be written.IOException - If an IO error occurredhandleRequest(VaadinSession, VaadinRequest, VaadinResponse)public boolean isReadAndWriteOutsideSessionLock()
VaadinSession locksynchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse, String)
should be called. Returns false if
synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse)
should be called.public Optional<SynchronizedRequestHandler.ResponseWriter> synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response, String requestBody) throws IOException, UnsupportedOperationException
synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse)
except the VaadinSession is locked before this is called and the
response requestBody has been read before locking the session and is
provided as a separate parameter.session - The session for the requestrequest - The request to handleresponse - The response object to which a response can be written.requestBody - Request body pre-read from the request objectIOException - If an IO error occurredUnsupportedOperationExceptionhandleRequest(VaadinSession, VaadinRequest, VaadinResponse)protected boolean canHandleRequest(VaadinRequest request)
true which means that all requests will be handled by
calling
synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse)
with the session locked.request - the request to handletrue if the request handling should continue once
the session has been locked; false if there's no
need to lock the session since the request would still not be
handled.public static String getRequestBody(Reader reader) throws IOException
Prefer getRequestBody(Reader, long) on request-handling code
paths so that the configured maximum request body size is enforced.
reader - the reader to read the request body fromIOException - if reading failspublic static String getRequestBody(Reader reader, long maxBodySize) throws IOException
maxBodySize characters.
The limit is enforced on the number of characters read from the reader. For typical ASCII/UTF-8 JSON payloads this equals the number of bytes; multi-byte content makes the effective byte limit larger.
reader - the reader to read the request body frommaxBodySize - the maximum number of characters to read, or a negative number
to read without any limitIOException - if reading failsRequestBodyTooLargeException - if the body exceeds maxBodySize characterspublic static long getMaxRequestBodySize(VaadinRequest request)
request - the request being handledCopyright © 2000–2026 Vaadin Ltd. All rights reserved.