UidlRequestHandler extends SynchronizedRequestHandler implements SessionExpiredHandler { @Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { UI uI = session.getService().findUI(request); if (uI == null) { 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); writeRefresh(response); return true; } catch (InvalidUIDLSecurityKeyException e) { getLogger().warn("Invalid security key received from {}", request.getRemoteHost()); writeRefresh(response); return true; } catch (ResynchronizationRequiredException e) { writeUidl(uI, stringWriter, true); } finally { stringWriter.close(); } commitJsonResponse(response, stringWriter.toString()); return true; }  @Override boolean synchronizedHandleRequest(VaadinSession session,
            VaadinRequest request, VaadinResponse response); @Override boolean handleSessionExpired(VaadinRequest request,
            VaadinResponse response); static void commitJsonResponse(VaadinResponse response, String json); static final Pattern HASH_PATTERN; static final Pattern URL_PATTERN; static final String PUSH_STATE_HASH; static final String PUSH_STATE_LOCATION; }
@Test public void writeSessionExpired_whenUINotFound() throws IOException { VaadinService service = mock(VaadinService.class); VaadinSession session = mock(VaadinSession.class); when(session.getService()).thenReturn(service); when(service.findUI(request)).thenReturn(null); boolean result = handler.synchronizedHandleRequest(session, request, response); Assert.assertTrue("Result should be true", result); String responseContent = CommunicationUtil .getStringWhenWriteString(outputStream); Assert.assertEquals("Invalid response", "for(;;);[{\"meta\":{\"sessionExpired\":true}}]", responseContent); }