use of elemental.json.JsonException 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;
}
use of elemental.json.JsonException in project flow by vaadin.
the class VaadinService method createCriticalNotificationJSON.
/**
* Creates a JSON message which, when sent to client as-is, will cause a
* critical error to be shown with the given details.
*
* @param caption
* The caption of the error or null to omit
* @param message
* The error message or null to omit
* @param details
* Additional error details or null to omit
* @param url
* A url to redirect to. If no other details are given then the
* user will be immediately redirected to this URL. Otherwise the
* message will be shown and the browser will redirect to the
* given URL only after the user acknowledges the message. If
* null then the browser will refresh the current page.
* @param querySelector
* Query selector to find the element under which the error will
* be added . If element is not found or the selector is
* {@code null}, body will be used
* @return A JSON string to be sent to the client
*/
public static String createCriticalNotificationJSON(String caption, String message, String details, String url, String querySelector) {
try {
JsonObject appError = Json.createObject();
putValueOrJsonNull(appError, "caption", caption);
putValueOrJsonNull(appError, "url", url);
putValueOrJsonNull(appError, "message", message);
putValueOrJsonNull(appError, "details", details);
putValueOrJsonNull(appError, "querySelector", querySelector);
JsonObject meta = Json.createObject();
meta.put("appError", appError);
JsonObject json = Json.createObject();
json.put("changes", Json.createObject());
json.put("resources", Json.createObject());
json.put("locales", Json.createObject());
json.put("meta", meta);
json.put(ApplicationConstants.SERVER_SYNC_ID, -1);
return wrapJsonForClient(json);
} catch (JsonException e) {
getLogger().warn("Error creating critical notification JSON message", e);
return wrapJsonForClient(Json.createObject());
}
}
Aggregations