Exemple #1
0
 /**
  * @param request HTTP request
  * @param response HTTP response
  * @return rendered HTML output
  */
 public String renderPage(HttpRequest request, HttpResponse response) {
   RequestLookup requestLookup = createRequestLookup(request, response);
   API api = new API(sessionRegistry, requestLookup);
   // If exists, render Theme.
   Theme renderingTheme = getRenderingTheme(api);
   if (renderingTheme != null) {
     renderingTheme.render(requestLookup);
   }
   try {
     return renderPage(request.getUriWithoutContextPath(), null, requestLookup, api);
   } catch (SessionNotFoundException e) {
     String loginPageUri = configuration.getLoginPageUri();
     if (loginPageUri == null) {
       throw (HttpErrorException) e;
     } else {
       throw new PageRedirectException(loginPageUri);
     }
   }
 }
Exemple #2
0
  public Optional<String> renderErrorPage(
      HttpErrorException ex, HttpRequest request, HttpResponse response) {
    Map<String, String> errorPages = configuration.getErrorPages();
    String errorPageUri =
        errorPages.getOrDefault(String.valueOf(ex.getHttpStatusCode()), errorPages.get("default"));
    if (errorPageUri == null) {
      return Optional.<String>empty();
    }

    RequestLookup requestLookup = createRequestLookup(request, response);
    API api = new API(sessionRegistry, requestLookup);
    // If exists, render Theme.
    Theme renderingTheme = getRenderingTheme(api);
    if (renderingTheme != null) {
      renderingTheme.render(requestLookup);
    }
    // Create Model with HTTP status code and error message.
    Map<String, Object> modelMap = new HashMap<>(2);
    modelMap.put("status", ex.getHttpStatusCode());
    modelMap.put("message", ex.getMessage());
    return Optional.of(renderPage(errorPageUri, new MapModel(modelMap), requestLookup, api));
  }
Exemple #3
0
 private RequestLookup createRequestLookup(HttpRequest request, HttpResponse response) {
   String clientContextPath = configuration.getContextPath();
   return new RequestLookup(
       (clientContextPath == null ? contextPath : clientContextPath), request, response);
 }