Package ch.ralscha.extdirectspring.bean

Examples of ch.ralscha.extdirectspring.bean.SSEvent


  public void handle(String beanName, String method, HttpServletRequest request,
      HttpServletResponse response, Locale locale) throws Exception {

    MethodInfo methodInfo = methodInfoCache.get(beanName, method);

    SSEvent result = null;
    SSEWriter sseWriter = new SSEWriter(response);

    if (methodInfo != null) {
      try {

        Object[] parameters = configurationService.getParametersResolver()
            .prepareParameters(request, response, locale, methodInfo,
                sseWriter);
        Object methodReturnValue;

        if (configurationService.getConfiguration().isSynchronizeOnSession()
            || methodInfo.isSynchronizeOnSession()) {
          HttpSession session = request.getSession(false);
          if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
              methodReturnValue = ExtDirectSpringUtil.invoke(
                  configurationService.getApplicationContext(),
                  beanName, methodInfo, parameters);
            }
          }
          else {
            methodReturnValue = ExtDirectSpringUtil.invoke(
                configurationService.getApplicationContext(), beanName,
                methodInfo, parameters);
          }
        }
        else {
          methodReturnValue = ExtDirectSpringUtil.invoke(
              configurationService.getApplicationContext(), beanName,
              methodInfo, parameters);
        }

        if (methodReturnValue instanceof SSEvent) {
          result = (SSEvent) methodReturnValue;
        }
        else if (methodReturnValue != null) {
          result = new SSEvent();
          result.setData(methodReturnValue.toString());
        }

      }
      catch (Exception e) {
        log.error("Error polling method '" + beanName + "." + method + "'",
            e.getCause() != null ? e.getCause() : e);

        Throwable cause;
        if (e.getCause() != null) {
          cause = e.getCause();
        }
        else {
          cause = e;
        }

        result = new SSEvent();
        result.setEvent("error");
        result.setData(configurationService.getConfiguration().getMessage(cause));

        if (configurationService.getConfiguration().isSendStacktrace()) {
          result.setComment(ExtDirectSpringUtil.getStackTrace(cause));
        }
      }
    }
    else {
      log.error("Error invoking method '" + beanName + "." + method
          + "'. Method or Bean not found");

      result = new SSEvent();
      result.setEvent("error");
      result.setData(configurationService.getConfiguration()
          .getDefaultExceptionMessage());

      if (configurationService.getConfiguration().isSendStacktrace()) {
        result.setComment("Bean or Method '" + beanName + "." + method
            + "' not found");
      }
    }

    if (result != null) {
View Full Code Here


   *            If null nothing is written.
   * @throws IOException
   */
  public void write(Object data) throws IOException {
    if (data != null) {
      SSEvent sseEvent = new SSEvent();
      sseEvent.setData(data.toString());
      write(sseEvent);
    }
  }
View Full Code Here

TOP

Related Classes of ch.ralscha.extdirectspring.bean.SSEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.