Package ch.ralscha.extdirectspring.bean

Examples of ch.ralscha.extdirectspring.bean.ExtDirectPollResponse


    HttpHeaders headers = new HttpHeaders();
    headers.add("intHeader", "2");
    headers.add("booleanHeader", "true");

    ExtDirectPollResponse resp = ControllerUtil.performPollRequest(mockMvc,
        "pollProvider", "messageRequestHeader6", "messageRequestHeader6", null,
        headers);

    assertThat(resp).isNotNull();
    assertThat(resp.getType()).isEqualTo("event");
    assertThat(resp.getName()).isEqualTo("messageRequestHeader6");
    assertThat(resp.getData()).isEqualTo("2;true");
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isNull();
  }
View Full Code Here


  @Test
  public void pollRequiredCookieWithoutValue() throws Exception {
    List<Cookie> cookies = new ArrayList<Cookie>();
    cookies.add(new Cookie("cookie", "cookieValue"));

    ExtDirectPollResponse resp = ControllerUtil.performPollRequest(mockMvc,
        "pollProvider", "messageCookieValue1", "messageCookieValue1", null, null,
        cookies);

    assertThat(resp).isNotNull();
    assertThat(resp.getType()).isEqualTo("event");
    assertThat(resp.getName()).isEqualTo("messageCookieValue1");
    assertThat(resp.getData()).isEqualTo("null;null;cookieValue");
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isNull();
  }
View Full Code Here

    List<Cookie> cookies = new ArrayList<Cookie>();
    cookies.add(new Cookie("cookie", "cookieValue"));
    cookies.add(new Cookie("anotherName", "cookieValue1"));
    cookies.add(new Cookie("anotherName", "cookieValue2"));

    ExtDirectPollResponse resp = ControllerUtil.performPollRequest(mockMvc,
        "pollProvider", "messageCookieValue2", "messageCookieValue2", params,
        null, cookies);

    assertThat(resp).isNotNull();
    assertThat(resp.getType()).isEqualTo("event");
    assertThat(resp.getName()).isEqualTo("messageCookieValue2");
    assertThat(resp.getData()).isEqualTo("1;cookieValue1");
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isNull();

    params.clear();
    params.put("id", "2");

    resp = ControllerUtil.performPollRequest(mockMvc, "pollProvider",
        "messageCookieValue2", "messageCookieValue2", params, null, null, true);

    assertThat(resp).isNotNull();
    assertThat(resp.getType()).isEqualTo("exception");
    assertThat(resp.getName()).isEqualTo("messageCookieValue2");
    assertThat(resp.getData()).isNull();
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isEqualTo("Server Error");

    params.clear();
    params.put("id", "3");
    cookies = new ArrayList<Cookie>();
    cookies.add(new Cookie("cookie", "cookieValue"));
    resp = ControllerUtil
        .performPollRequest(mockMvc, "pollProvider", "messageCookieValue2",
            "messageCookieValue2", params, null, cookies, true);

    assertThat(resp).isNotNull();
    assertThat(resp.getType()).isEqualTo("exception");
    assertThat(resp.getName()).isEqualTo("messageCookieValue2");
    assertThat(resp.getData()).isNull();
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isEqualTo("Server Error");
  }
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);
          }

        }
      }

      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);
      handleException(directPollResponse, e);
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

  @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);
          }

        }
      }

      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);
      handleException(directPollResponse, e);
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;

    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) {
              directPollResponse.setData(ExtDirectSpringUtil.invoke(
                  configurationService.getApplicationContext(), beanName, methodInfo, parameters));
            }
          } else {
            directPollResponse.setData(ExtDirectSpringUtil.invoke(
                configurationService.getApplicationContext(), beanName, methodInfo, parameters));
          }
        } else {
          directPollResponse.setData(ExtDirectSpringUtil.invoke(configurationService.getApplicationContext(),
              beanName, methodInfo, parameters));
        }

      } catch (Exception e) {
        log.error("Error polling method '" + beanName + "." + method + "'", e.getCause() != null ? e.getCause()
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

  @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("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);
          }

        }
      }

      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);
      handleException(directPollResponse, 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.