class SessionHelpers {

  public void commitRequest(ServletRequest request, ServletRequest oldRequest) throws IOException {
    // we are looking for identity below
    if (request != oldRequest && request instanceof HttpRequestWrapper) { // NOSONAR
      HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper)request;
      try {
        httpRequestWrapper.commit();
        if (httpRequestWrapper.getResponse() != null) {
          httpRequestWrapper.getResponse().flushBuffer();
        }
      } catch (Exception e) { // NOSONAR
        // Recover from any exception and log it
        logger.error("An exception occured while commiting the session.", e);
        throw e;
      } finally {
        request.setAttribute(REQUEST_WRAPPED_ATTRIBUTE, httpRequestWrapper.getEmbeddedRequest());
      }
    }
  }

}