Example #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();
      }
    }
  }
Example #2
0
  Handler(Route root, Bridge bridge) throws ServletException {
    this.bridge = bridge;

    //
    try {
      bridge.boot();

      //
      HashMap<MethodHandle, Route> routeMap = new HashMap<MethodHandle, Route>();
      HashMap<Route, Map<Phase, MethodHandle>> routeMap2 =
          new HashMap<Route, Map<Phase, MethodHandle>>();

      //
      RouteDescriptor routesDesc =
          (RouteDescriptor) bridge.runtime.getDescriptor().getPluginDescriptor("router");
      if (routesDesc != null) {
        for (RouteDescriptor child : routesDesc.getChildren()) {
          Route route = root.append(child.getPath());
          for (Map.Entry<String, String> entry : child.getTargets().entrySet()) {
            MethodHandle handle = MethodHandle.parse(entry.getValue());
            Phase phase = Phase.valueOf(entry.getKey());
            routeMap.put(handle, route);
            Map<Phase, MethodHandle> map = routeMap2.get(route);
            if (map == null) {
              routeMap2.put(route, map = new HashMap<Phase, MethodHandle>());
            }
            map.put(phase, handle);
          }
        }
      }

      //
      this.root = root;
      this.routeMap = routeMap;
      this.routeMap2 = routeMap2;
    } catch (Exception e) {
      throw ServletBridge.wrap(e);
    }
  }