Exemple #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();
      }
    }
  }
Exemple #2
0
 public void processAction(final ActionBridge requestBridge) throws Throwable {
   try {
     TrimmingException.invoke(
         new TrimmingException.Callback() {
           public void call() throws Throwable {
             try {
               runtime.getContext().invoke(requestBridge);
             } catch (ApplicationException e) {
               // For now we do that until we find something better specially for the dev mode
               throw e.getCause();
             }
           }
         });
   } catch (TrimmingException e) {
     throw e.getSource();
   } finally {
     requestBridge.close();
   }
 }
Exemple #3
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();
    }
  }