コード例 #1
0
  public static void process(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      Map<String, BaseAlloyControllerImpl> alloyControllers)
      throws Exception {

    String jsonString = null;

    String controller = ParamUtil.getString(actionRequest, "controller");

    BaseAlloyControllerImpl baseAlloyControllerImpl = alloyControllers.get(controller);

    if (baseAlloyControllerImpl == null) {
      throw new Exception("Unable to find controller " + controller);
    }

    String action = ParamUtil.getString(actionRequest, "action");

    try {
      if (action.equals("custom")) {
        Class<?> clazz = BaseAlloyControllerImpl.class;

        Method method =
            clazz.getDeclaredMethod("processDataRequest", new Class<?>[] {ActionRequest.class});

        jsonString =
            (String)
                ServiceBeanMethodInvocationFactoryUtil.proceed(
                    baseAlloyControllerImpl,
                    clazz,
                    method,
                    new Object[] {actionRequest},
                    new String[] {"transactionAdvice"});
      } else if (action.equals("dynamicQuery")) {
        jsonString = executeDynamicQuery(baseAlloyControllerImpl, actionRequest);
      } else if (action.equals("search")) {
        jsonString = executeSearch(baseAlloyControllerImpl, actionRequest);
      }
    } catch (Exception e) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      String message = e.getMessage();

      if (Validator.isNull(message)) {
        message = baseAlloyControllerImpl.translate("an-unexpected-error-occurred");
      }

      jsonObject.put("message", message);

      jsonObject.put("stacktrace", StackTraceUtil.getStackTrace(e));
      jsonObject.put("success", false);

      jsonString = jsonObject.toString();
    }

    if (jsonString != null) {
      writeJSON(actionRequest, actionResponse, jsonString);
    }
  }
  @Test
  public void testSave() throws Exception {
    EmailAddress emailAddress1 = newEmailAddress("*****@*****.**");
    EmailAddress emailAddress2 = newEmailAddress("*****@*****.**");

    _emailAddresses.add(emailAddress1);
    _emailAddresses.add(emailAddress2);

    ServiceBeanMethodInvocationFactoryUtil.proceed(
        this,
        ServiceBeanMethodInvocationFactoryImplTest.class,
        getSaveMethod(),
        new Object[] {false},
        new String[] {"transactionAdvice"});

    Assert.assertEquals(2, EmailAddressLocalServiceUtil.getEmailAddressesCount());
  }