Package ch.ralscha.extdirectspring.bean

Examples of ch.ralscha.extdirectspring.bean.ExtDirectPollResponse


  @RequestMapping(value = "/poll/{beanName}/{method}/{event}")
  public void poll(@PathVariable("beanName") String beanName, @PathVariable("method") String method,
      @PathVariable("event") String event, HttpServletRequest request, HttpServletResponse response, Locale locale)
      throws Exception {

    ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
    directPollResponse.setName(event);

    MethodInfo methodInfo = MethodInfoCache.INSTANCE.get(beanName, method);
    boolean streamResponse;
    Class<?> jsonView = null;

    if (methodInfo != null) {

      streamResponse = configurationService.getConfiguration().isStreamResponse()
          || methodInfo.isStreamResponse();

      try {

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

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

              if (result instanceof ModelAndJsonView) {
                ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
                directPollResponse.setData(modelAndJsonView.getModel());
                jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
              } else {
                directPollResponse.setData(result);
                jsonView = getJsonView(result, methodInfo.getJsonView());
              }
            }
          } else {
            Object result = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(),
                beanName, methodInfo, parameters);
            if (result instanceof ModelAndJsonView) {
              ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
              directPollResponse.setData(modelAndJsonView.getModel());
              jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
            } else {
              directPollResponse.setData(result);
              jsonView = getJsonView(result, methodInfo.getJsonView());
            }
          }
        } else {
          Object result = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(), beanName,
              methodInfo, parameters);
          if (result instanceof ModelAndJsonView) {
            ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
            directPollResponse.setData(modelAndJsonView.getModel());
            jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
          } else {
            directPollResponse.setData(result);
            jsonView = getJsonView(result, methodInfo.getJsonView());
          }
        }

      } catch (Exception e) {
        log.error("Error polling method '" + beanName + "." + method + "'", e.getCause() != null ? e.getCause()
            : e);
        directPollResponse.setData(handleException(methodInfo, directPollResponse, e, request));
      }
    } else {
      log.error("Error invoking method '" + beanName + "." + method + "'. Method or Bean not found");
      handleMethodNotFoundError(directPollResponse, beanName, method);
      streamResponse = configurationService.getConfiguration().isStreamResponse();
View Full Code Here


  @RequestMapping(value = "/poll/{beanName}/{method}/{event}")
  public void poll(@PathVariable("beanName") String beanName, @PathVariable("method") String method,
      @PathVariable("event") String event, HttpServletRequest request, HttpServletResponse response, Locale locale)
      throws Exception {

    ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
    directPollResponse.setName(event);

    MethodInfo methodInfo = MethodInfoCache.INSTANCE.get(beanName, method);
    boolean streamResponse;
    Class<?> jsonView = null;

    if (methodInfo != null) {

      streamResponse = configurationService.getConfiguration().isStreamResponse()
          || methodInfo.isStreamResponse();

      try {

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

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

              if (result instanceof ModelAndJsonView) {
                ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
                directPollResponse.setData(modelAndJsonView.getModel());
                jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
              } else {
                directPollResponse.setData(result);
                jsonView = getJsonView(result, methodInfo.getJsonView());
              }
            }
          } else {
            Object result = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(),
                beanName, methodInfo, parameters);
            if (result instanceof ModelAndJsonView) {
              ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
              directPollResponse.setData(modelAndJsonView.getModel());
              jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
            } else {
              directPollResponse.setData(result);
              jsonView = getJsonView(result, methodInfo.getJsonView());
            }
          }
        } else {
          Object result = ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(), beanName,
              methodInfo, parameters);
          if (result instanceof ModelAndJsonView) {
            ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
            directPollResponse.setData(modelAndJsonView.getModel());
            jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
          } else {
            directPollResponse.setData(result);
            jsonView = getJsonView(result, methodInfo.getJsonView());
          }
        }

      } catch (Exception e) {
        log.error("Error polling method '" + beanName + "." + method + "'", e.getCause() != null ? e.getCause()
            : e);
        directPollResponse.setData(handleException(methodInfo, directPollResponse, e, request));
      }
    } else {
      log.error("Error invoking method '" + beanName + "." + method + "'. Method or Bean not found");
      handleMethodNotFoundError(directPollResponse, beanName, method);
      streamResponse = configurationService.getConfiguration().isStreamResponse();
View Full Code Here

  @ResponseBody
  public ExtDirectPollResponse poll(@PathVariable String beanName, @PathVariable String method,
      @PathVariable String event, HttpServletRequest request, HttpServletResponse response, Locale locale)
      throws Exception {

    ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
    directPollResponse.setName(event);

    try {
      MethodInfo methodInfo = ExtDirectSpringUtil.findMethodInfo(context, beanName, method);

      Class<?>[] parameterTypes = methodInfo.getParameterTypes();
      Object[] parameters = null;
      if (parameterTypes.length > 0) {
        parameters = new Object[parameterTypes.length];
        int paramIndex = 0;
        for (Class<?> parameterType : parameterTypes) {

          if (SupportedParameterTypes.SERVLET_RESPONSE.getSupportedClass().isAssignableFrom(parameterType)) {
            parameters[paramIndex] = response;
          } else if (SupportedParameterTypes.SERVLET_REQUEST.getSupportedClass().isAssignableFrom(parameterType)) {
            parameters[paramIndex] = request;
          } else if (SupportedParameterTypes.SESSION.getSupportedClass().isAssignableFrom(parameterType)) {
            parameters[paramIndex] = request.getSession();
          } else if (SupportedParameterTypes.LOCALE.getSupportedClass().isAssignableFrom(parameterType)) {
            parameters[paramIndex] = locale;
          } else {
            parameters[paramIndex] = handleRequestParam(request, null,
                methodInfo.getParameterAnnotations()[paramIndex], parameterType);
          }

          paramIndex++;
        }
      }

      directPollResponse.setData(ExtDirectSpringUtil.invoke(context, beanName, methodInfo, parameters));
    } catch (Exception e) {
      log.error("Error on polling method '" + beanName + "." + method + "'", e);

      directPollResponse.setType("exception");

      if (log.isDebugEnabled()) {
        directPollResponse.setMessage(e.getMessage());
        directPollResponse.setWhere(getStackTrace(e));
      } else {
        directPollResponse.setMessage("Server Error");
        directPollResponse.setWhere(null);
      }
    }
    return directPollResponse;

  }
View Full Code Here

  public void poll(@PathVariable("beanName") String beanName,
      @PathVariable("method") String method, @PathVariable("event") String event,
      HttpServletRequest request, HttpServletResponse response, Locale locale)
      throws Exception {

    ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
    directPollResponse.setName(event);

    MethodInfo methodInfo = methodInfoCache.get(beanName, method);
    boolean streamResponse;
    Class<?> jsonView = null;

    if (methodInfo != null) {

      streamResponse = configurationService.getConfiguration().isStreamResponse()
          || methodInfo.isStreamResponse();

      try {

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

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

              if (result instanceof ModelAndJsonView) {
                ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
                directPollResponse.setData(modelAndJsonView.getModel());
                jsonView = getJsonView(modelAndJsonView,
                    methodInfo.getJsonView());
              }
              else {
                directPollResponse.setData(result);
                jsonView = getJsonView(result, methodInfo.getJsonView());
              }
            }
          }
          else {
            Object result = ExtDirectSpringUtil.invoke(
                configurationService.getApplicationContext(), beanName,
                methodInfo, parameters);
            if (result instanceof ModelAndJsonView) {
              ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
              directPollResponse.setData(modelAndJsonView.getModel());
              jsonView = getJsonView(modelAndJsonView,
                  methodInfo.getJsonView());
            }
            else {
              directPollResponse.setData(result);
              jsonView = getJsonView(result, methodInfo.getJsonView());
            }
          }
        }
        else {
          Object result = ExtDirectSpringUtil.invoke(
              configurationService.getApplicationContext(), beanName,
              methodInfo, parameters);
          if (result instanceof ModelAndJsonView) {
            ModelAndJsonView modelAndJsonView = (ModelAndJsonView) result;
            directPollResponse.setData(modelAndJsonView.getModel());
            jsonView = getJsonView(modelAndJsonView, methodInfo.getJsonView());
          }
          else {
            directPollResponse.setData(result);
            jsonView = getJsonView(result, methodInfo.getJsonView());
          }
        }

      }
      catch (Exception e) {
        log.error("Error polling method '" + beanName + "." + method + "'",
            e.getCause() != null ? e.getCause() : e);
        directPollResponse.setData(handleException(methodInfo,
            directPollResponse, e, request));
      }
    }
    else {
      log.error("Error invoking method '" + beanName + "." + method
View Full Code Here

  @ResponseBody
  public ExtDirectPollResponse poll(@PathVariable("beanName") String beanName, @PathVariable("method") String method,
      @PathVariable("event") String event, HttpServletRequest request, HttpServletResponse response, Locale locale)
      throws Exception {

    ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
    directPollResponse.setName(event);

    try {
      MethodInfo methodInfo = ExtDirectSpringUtil.findMethodInfo(context, beanName, method);

      List<ParameterInfo> methodParameters = methodInfo.getParameters();
      Object[] parameters = null;
      if (!methodParameters.isEmpty()) {
        parameters = new Object[methodParameters.size()];

        for (int paramIndex = 0; paramIndex < methodParameters.size(); paramIndex++) {
          ParameterInfo methodParameter = methodParameters.get(paramIndex);

          if (methodParameter.isSupportedParameter()) {
            parameters[paramIndex] = SupportedParameterTypes.resolveParameter(methodParameter.getType(),
                request, response, locale);
          } else {
            parameters[paramIndex] = handleRequestParam(request, null, methodParameter);
          }

        }
      }

      directPollResponse.setData(ExtDirectSpringUtil.invoke(context, beanName, methodInfo, parameters));
    } catch (Exception e) {
      log.error("Error on polling method '" + beanName + "." + method + "'", e);

      directPollResponse.setType("exception");

      if (log.isDebugEnabled()) {
        directPollResponse.setMessage(e.getMessage());
        directPollResponse.setWhere(getStackTrace(e));
      } else {
        directPollResponse.setMessage("Server Error");
        directPollResponse.setWhere(null);
      }
    }
    return directPollResponse;

  }
View Full Code Here

  @ResponseBody
  public ExtDirectPollResponse poll(@PathVariable("beanName") String beanName, @PathVariable("method") String method,
      @PathVariable("event") String event, HttpServletRequest request, HttpServletResponse response, Locale locale)
      throws Exception {

    ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
    directPollResponse.setName(event);

    try {
      MethodInfo methodInfo = ExtDirectSpringUtil.findMethodInfo(context, beanName, method);

      List<ParameterInfo> methodParameters = methodInfo.getParameters();
      Object[] parameters = null;
      if (!methodParameters.isEmpty()) {
        parameters = new Object[methodParameters.size()];

        for (int paramIndex = 0; paramIndex < methodParameters.size(); paramIndex++) {
          ParameterInfo methodParameter = methodParameters.get(paramIndex);

          if (methodParameter.isSupportedParameter()) {
            parameters[paramIndex] = SupportedParameterTypes.resolveParameter(methodParameter.getType(), request,
                response, locale);
          } else {
            parameters[paramIndex] = handleRequestParam(request, null, methodParameter);
          }

        }
      }

      directPollResponse.setData(ExtDirectSpringUtil.invoke(context, beanName, methodInfo, parameters));
    } catch (Exception e) {
      log.error("Error on polling method '" + beanName + "." + method + "'", e);

      directPollResponse.setType("exception");

      if (log.isDebugEnabled()) {
        directPollResponse.setMessage(e.getMessage());
        directPollResponse.setWhere(getStackTrace(e));
      } else {
        directPollResponse.setMessage("Server Error");
        directPollResponse.setWhere(null);
      }
    }
    return directPollResponse;

  }
View Full Code Here

  @ResponseBody
  public ExtDirectPollResponse poll(@PathVariable("beanName") String beanName, @PathVariable("method") String method,
      @PathVariable("event") String event, HttpServletRequest request, HttpServletResponse response, Locale locale)
      throws Exception {

    ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
    directPollResponse.setName(event);

    try {
      MethodInfo methodInfo = ExtDirectSpringUtil.findMethodInfo(context, beanName, method);

      List<ParameterInfo> methodParameters = methodInfo.getParameters();
      Object[] parameters = null;
      if (!methodParameters.isEmpty()) {
        parameters = new Object[methodParameters.size()];

        for (int paramIndex = 0; paramIndex < methodParameters.size(); paramIndex++) {
          ParameterInfo methodParameter = methodParameters.get(paramIndex);

          if (methodParameter.isSupportedParameter()) {
            parameters[paramIndex] = SupportedParameterTypes.resolveParameter(methodParameter.getType(),
                request, response, locale);
          } else {
            parameters[paramIndex] = handleRequestParam(request, null, methodParameter);
          }

        }
      }

      directPollResponse.setData(ExtDirectSpringUtil.invoke(context, beanName, methodInfo, parameters));
    } catch (Exception e) {
      Throwable cause;
      if (e.getCause() != null) {
        cause = e.getCause();
      } else {
        cause = e;
      }

      log.error("Error polling method '" + beanName + "." + method + "'", e);

      directPollResponse.setType("exception");

      if (exceptionToMessage != null) {
        String message = exceptionToMessage.get("extDirectSpringExceptionToMessage").get(cause.getClass());
        if (message != null) {
          directPollResponse.setMessage(message);
        } else {
          directPollResponse.setMessage("Server Error");
        }
      } else {
        directPollResponse.setMessage("Server Error");
      }

      if (log.isDebugEnabled()) {
        directPollResponse.setWhere(getStackTrace(e));
      } else {
        directPollResponse.setWhere(null);
      }

    }
    return directPollResponse;
View Full Code Here

  @RequestMapping(value = "/poll/{beanName}/{method}/{event}")
  public void poll(@PathVariable("beanName") final String beanName, @PathVariable("method") final String method,
      @PathVariable("event") final String event, final HttpServletRequest request,
      final HttpServletResponse response, final Locale locale) throws Exception {

    ExtDirectPollResponse directPollResponse = new ExtDirectPollResponse();
    directPollResponse.setName(event);

    MethodInfo methodInfo = MethodInfoCache.INSTANCE.get(beanName, method);
    boolean streamResponse;

    if (methodInfo != null) {

      streamResponse = configuration.isStreamResponse() || methodInfo.isStreamResponse();

      try {

        List<ParameterInfo> methodParameters = methodInfo.getParameters();
        Object[] parameters = null;
        if (!methodParameters.isEmpty()) {
          parameters = new Object[methodParameters.size()];

          for (int paramIndex = 0; paramIndex < methodParameters.size(); paramIndex++) {
            ParameterInfo methodParameter = methodParameters.get(paramIndex);

            if (methodParameter.isSupportedParameter()) {
              parameters[paramIndex] = SupportedParameters.resolveParameter(methodParameter.getType(),
                  request, response, locale);
            } else if (methodParameter.isHasRequestHeaderAnnotation()) {
              parameters[paramIndex] = parametersResolver.resolveRequestHeader(request, methodParameter);
            } else {
              parameters[paramIndex] = parametersResolver.resolveRequestParam(request, null,
                  methodParameter);
            }

          }
        }

        if (configuration.isSynchronizeOnSession() || methodInfo.isSynchronizeOnSession()) {
          HttpSession session = request.getSession(false);
          if (session != null) {
            Object mutex = WebUtils.getSessionMutex(session);
            synchronized (mutex) {
              directPollResponse.setData(ExtDirectSpringUtil.invoke(context, beanName, methodInfo,
                  parameters));
            }
          } else {
            directPollResponse.setData(ExtDirectSpringUtil
                .invoke(context, beanName, methodInfo, parameters));
          }
        } else {
          directPollResponse.setData(ExtDirectSpringUtil.invoke(context, beanName, methodInfo, parameters));
        }

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

TOP

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

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.