Beispiel #1
0
  public void render(final RenderBridge requestBridge) throws Throwable {

    //
    Collection<CompilationError> errors = null;
    try {
      boot();
    } catch (CompilationException e) {
      errors = e.getErrors();
    }

    //
    if (errors == null || errors.isEmpty()) {

      //
      if (errors != null) {
        requestBridge.purgeSession();
      }

      //
      try {
        TrimmingException.invoke(
            new TrimmingException.Callback() {
              public void call() throws Throwable {
                try {
                  runtime.getContext().invoke(requestBridge);
                } catch (ApplicationException e) {
                  throw e.getCause();
                }
              }
            });
      } catch (TrimmingException e) {
        if (config.isProd()) {
          throw e.getSource();
        } else {
          StringWriter writer = new StringWriter();
          PrintWriter printer = new PrintWriter(writer);
          renderThrowable(printer, e);
          requestBridge.setResponse(Response.ok(writer.getBuffer()));
        }
      } finally {
        requestBridge.close();
      }
    } else {
      try {
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        renderErrors(printer, errors);
        requestBridge.setResponse(Response.ok(writer.getBuffer()));
      } finally {
        requestBridge.close();
      }
    }
  }
Beispiel #2
0
  public void serveResource(final ResourceBridge requestBridge) throws Throwable {
    try {
      TrimmingException.invoke(
          new TrimmingException.Callback() {
            public void call() throws Throwable {
              try {
                runtime.getContext().invoke(requestBridge);
              } catch (ApplicationException e) {
                throw e.getCause();
              }
            }
          });
    } catch (TrimmingException e) {

      //
      logThrowable(e);

      // Internal server error
      Response response;
      if (!config.isProd()) {
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        printer.print("<html>\n");
        printer.print("<head>\n");
        printer.print("</head>\n");
        printer.print("<body>\n");
        renderThrowable(printer, e);
        printer.print("</body>\n");
        response = Response.content(500, writer.getBuffer());
      } else {
        response = Response.content(500, "todo");
      }

      // Set response
      requestBridge.setResponse(response);
    } finally {
      requestBridge.close();
    }
  }