Search in sources :

Example 1 with ResynchronizationRequiredException

use of com.vaadin.flow.server.communication.ServerRpcHandler.ResynchronizationRequiredException in project flow by vaadin.

the class UidlRequestHandler method synchronizedHandleRequest.

@Override
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    UI uI = session.getService().findUI(request);
    if (uI == null) {
        // This should not happen but it will if the UI has been closed. We
        // really don't want to see it in the server logs though
        commitJsonResponse(response, VaadinService.createUINotFoundJSON(false));
        return true;
    }
    StringWriter stringWriter = new StringWriter();
    try {
        getRpcHandler(session).handleRpc(uI, request.getReader(), request);
        writeUidl(uI, stringWriter, false);
    } catch (JsonException e) {
        getLogger().error("Error writing JSON to response", e);
        // Refresh on client side
        writeRefresh(response);
        return true;
    } catch (InvalidUIDLSecurityKeyException e) {
        getLogger().warn("Invalid security key received from {}", request.getRemoteHost());
        // Refresh on client side
        writeRefresh(response);
        return true;
    } catch (ResynchronizationRequiredException e) {
        // NOSONAR
        // Resync on the client side
        writeUidl(uI, stringWriter, true);
    } finally {
        stringWriter.close();
    }
    commitJsonResponse(response, stringWriter.toString());
    return true;
}
Also used : JsonException(elemental.json.JsonException) InvalidUIDLSecurityKeyException(com.vaadin.flow.server.communication.ServerRpcHandler.InvalidUIDLSecurityKeyException) UI(com.vaadin.flow.component.UI) JavaScriptBootstrapUI(com.vaadin.flow.component.internal.JavaScriptBootstrapUI) StringWriter(java.io.StringWriter) ResynchronizationRequiredException(com.vaadin.flow.server.communication.ServerRpcHandler.ResynchronizationRequiredException)

Aggregations

UI (com.vaadin.flow.component.UI)1 JavaScriptBootstrapUI (com.vaadin.flow.component.internal.JavaScriptBootstrapUI)1 InvalidUIDLSecurityKeyException (com.vaadin.flow.server.communication.ServerRpcHandler.InvalidUIDLSecurityKeyException)1 ResynchronizationRequiredException (com.vaadin.flow.server.communication.ServerRpcHandler.ResynchronizationRequiredException)1 JsonException (elemental.json.JsonException)1 StringWriter (java.io.StringWriter)1