예제 #1
0
 /* (non-Javadoc)
  * @see net.cbtltd.client.RazorService#send(net.cbtltd.shared.api.HasService)
  */
 public HasResponse send(HasService action) throws SerializationException {
   try {
     Date timestamp = new Date();
     HasResponse response = execute(action);
     MonitorService.monitor(action.getClass().getSimpleName(), timestamp);
     return response;
   } catch (PatternSyntaxException x) {
     LOG.error("PatternSyntaxException " + x.toString());
     throw new SerializationException("PatternSyntaxException");
   }
 }
예제 #2
0
  /**
   * Executes the specified action on the action.service() service.
   *
   * @param action the action to be executed.
   * @return the response.
   * @throws SerializationException the serialization exception
   */
  public HasResponse execute(HasService action) throws SerializationException {

    HasResponse response = null;
    LOG.debug("\n\nRazorServer execute " + action.getClass().getName() + "\naction " + action);
    String classname = action.service().classname();

    try {
      Class<?> c = Class.forName(classname); // say AccountService
      Method[] allMethods = c.getDeclaredMethods(); // can be static
      for (Method m : allMethods) {
        String mname = m.getName();
        if (mname.equals("execute")) {
          Type[] pType = m.getGenericParameterTypes();
          if (pType[1].toString().equals("class " + action.getClass().getName())) {
            SqlSession sqlSession = openSession();
            try {
              m.setAccessible(true);
              Object t = getService(action.service());
              response = (HasResponse) m.invoke(t, sqlSession, action);
              sqlSession.commit();
            } catch (IllegalAccessException x) {
              LOG.error(
                  "IllegalAccessException " + action.getClass().getName() + "\n" + x.getMessage());
            } catch (InvocationTargetException x) {
              LOG.error(
                  "InvocationTargetException exception "
                      + action.getClass().getName()
                      + "\n"
                      + x.getMessage());
            } catch (Throwable x) {
              sqlSession.rollback();
              MonitorService.log(x);
            } finally {
              sqlSession.close();
            }
          }
        }
      }
    } catch (ClassNotFoundException x) {
      MonitorService.log(x);
      LOG.error("ClassNotFoundException " + action.getClass().getName() + "\n" + x.getMessage());
    }
    return response;
  }