Package ch.ralscha.extdirectspring.bean

Examples of ch.ralscha.extdirectspring.bean.SSEvent


    cookies.add(new Cookie("anotherName", "cookieValue1"));

    List<SSEvent> events = ControllerUtil.performSseRequest(mockMvc, "sseProvider",
        "messageCookieValue3", null, null, cookies);
    assertThat(events).hasSize(1);
    SSEvent event = events.get(0);

    assertThat(event.getEvent()).isEqualTo("messageCookieValue3");
    assertThat(event.getComment()).isNull();
    assertThat(event.getData()).isEqualTo("cookieValue1");
    assertThat(event.getId()).isNull();
    assertThat(event.getRetry()).isNull();
  }
View Full Code Here


  public void sseRequiredCookieWithValueAndDefault2() throws Exception {

    List<SSEvent> events = ControllerUtil.performSseRequest(mockMvc, "sseProvider",
        "messageCookieValue3", null, null, null);
    assertThat(events).hasSize(1);
    SSEvent event = events.get(0);

    assertThat(event.getEvent()).isEqualTo("messageCookieValue3");
    assertThat(event.getComment()).isNull();
    assertThat(event.getData()).isEqualTo("default");
    assertThat(event.getId()).isNull();
    assertThat(event.getRetry()).isNull();
  }
View Full Code Here

    cookies.add(new Cookie("anotherName", "cookieValue1"));

    List<SSEvent> events = ControllerUtil.performSseRequest(mockMvc, "sseProvider",
        "messageCookieValue4", null, null, cookies);
    assertThat(events).hasSize(1);
    SSEvent event = events.get(0);

    assertThat(event.getEvent()).isEqualTo("messageCookieValue4");
    assertThat(event.getComment()).isEqualTo("comment of message cookieValue");
    assertThat(event.getData()).isEqualTo("cookieValue");
    assertThat(event.getId()).isNull();
    assertThat(event.getRetry()).isNull();
  }
View Full Code Here

  @Test
  public void sseOptionalCookieWithoutValueAndDefault2() throws Exception {
    List<SSEvent> events = ControllerUtil.performSseRequest(mockMvc, "sseProvider",
        "messageCookieValue4", null, null, null);
    assertThat(events).hasSize(1);
    SSEvent event = events.get(0);

    assertThat(event.getEvent()).isEqualTo("messageCookieValue4");
    assertThat(event.getComment()).isEqualTo("comment of message default");
    assertThat(event.getData()).isEqualTo("default");
    assertThat(event.getId()).isNull();
    assertThat(event.getRetry()).isNull();
  }
View Full Code Here

  }

  @ExtDirectMethod(value = ExtDirectMethodType.SSE, group = "itest_simple",
      streamResponse = true)
  public SSEvent sse(@RequestParam String id) {
    SSEvent event = new SSEvent();
    event.setId(id);
    event.setData("d" + id);
    return event;
  }
View Full Code Here

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

    MethodInfo methodInfo = MethodInfoCache.INSTANCE.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 = null;

        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) {
      sseWriter.write(result);
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

   *            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

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

    MethodInfo methodInfo = MethodInfoCache.INSTANCE.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) {
      sseWriter.write(result);
View Full Code Here

   * 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.