Ejemplo n.º 1
0
  private void executeMethod(Item item, Request request, Response response, String actionMethod)
      throws NoSuchMethodException, InvocationTargetException, IllegalAccessException,
          NoSuchJsonElementException {
    logger.debug("METHOD: " + item + ", " + actionMethod);

    Method method = getRequestMethod(item, actionMethod, request.isRequestPost());
    logger.debug("FOUND METHOD: " + method);

    if (request.isRequestPost()) {
      JsonObject json = null;
      try {
        json = JsonUtils.getJsonFromRequest(request);
      } catch (Exception e) {
        logger.debug(e.getMessage());
      }
      method.invoke(item, request, response, json);
    } else {
      method.invoke(item, request, response);
    }
  }
Ejemplo n.º 2
0
  private void executeThing(Request request, Response response, Item item, String urlName)
      throws ActionHandlerException {
    logger.debug("EXECUTE: " + item + ", " + urlName);

    /* First try to find a view, if not a POST */
    try {
      logger.debug("Item: " + item + " -> " + urlName);
      executeMethod(item, request, response, urlName);
      return;
    } catch (Exception e) {
      e.printStackTrace();
      logger.debug(item + " does not not have " + urlName + ", " + e.getMessage());
    }

    logger.debug("TRYING VIEW FILE");

    if (!request.isRequestPost()) {
      try {
        request
            .getContext()
            .put(
                "content",
                SeventyEight.getInstance()
                    .getTemplateManager()
                    .getRenderer(request)
                    .renderObject(item, urlName + ".vm"));
        response
            .getWriter()
            .print(
                SeventyEight.getInstance()
                    .getTemplateManager()
                    .getRenderer(request)
                    .render(request.getTemplate()));
        return;
      } catch (Exception e) {
        logger.debug("Unable to view " + urlName + " for " + item + ": " + e.getMessage());
        throw new ActionHandlerException(e);
      }
    }
  }