Package org.springframework.web.context.request.async

Examples of org.springframework.web.context.request.async.WebAsyncManager


    interceptor.preHandle(this.webRequest);
    assertTrue(TransactionSynchronizationManager.hasResource(this.factory));

    AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
    asyncManager.setTaskExecutor(new SyncTaskExecutor());
    asyncManager.setAsyncWebRequest(asyncWebRequest);
    asyncManager.startCallableProcessing(new Callable<String>() {
      @Override
      public String call() throws Exception {
        return "anything";
      }
    });
View Full Code Here


    FilterChain filterChain3 = new PassThroughFilterChain(filter2, filterChain2);

    AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);
    given(asyncWebRequest.isAsyncStarted()).willReturn(true);

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
    asyncManager.setTaskExecutor(new SyncTaskExecutor());
    asyncManager.setAsyncWebRequest(asyncWebRequest);
    asyncManager.startCallableProcessing(new Callable<String>() {
      @Override
      public String call() throws Exception {
        return "anything";
      }
    });
View Full Code Here

      throws ServletException, IOException {

    SessionFactory sessionFactory = lookupSessionFactory(request);
    boolean participate = false;

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    String key = getAlreadyFilteredAttributeName();

    if (isSingleSession()) {
      // single session mode
      if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
        // Do not modify the Session: just set the participate flag.
        participate = true;
      }
      else {
        boolean isFirstRequest = !isAsyncDispatch(request);
        if (isFirstRequest || !applySessionBindingInterceptor(asyncManager, key)) {
          logger.debug("Opening single Hibernate Session in OpenSessionInViewFilter");
          Session session = getSession(sessionFactory);
          SessionHolder sessionHolder = new SessionHolder(session);
          TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);

          AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(sessionFactory, sessionHolder);
          asyncManager.registerCallableInterceptor(key, interceptor);
          asyncManager.registerDeferredResultInterceptor(key, interceptor);
        }
      }
    }
    else {
      // deferred close mode
View Full Code Here

   */
  @Override
  public void preHandle(WebRequest request) throws DataAccessException {
    String participateAttributeName = getParticipateAttributeName();

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    if (asyncManager.hasConcurrentResult()) {
      if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
        return;
      }
    }

    if (TransactionSynchronizationManager.hasResource(getSessionFactory())) {
      // Do not modify the Session: just mark the request accordingly.
      Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
      int newCount = (count != null ? count + 1 : 1);
      request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
    }
    else {
      logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor");
      Session session = openSession();
      SessionHolder sessionHolder = new SessionHolder(session);
      TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

      AsyncRequestInterceptor asyncRequestInterceptor =
          new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
      asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
      asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
    }
  }
View Full Code Here

      throws ServletException, IOException {

    SessionFactory sessionFactory = lookupSessionFactory(request);
    boolean participate = false;

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    String key = getAlreadyFilteredAttributeName();

    if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
      // Do not modify the Session: just set the participate flag.
      participate = true;
    }
    else {
      boolean isFirstRequest = !isAsyncDispatch(request);
      if (isFirstRequest || !applySessionBindingInterceptor(asyncManager, key)) {
        logger.debug("Opening Hibernate Session in OpenSessionInViewFilter");
        Session session = openSession(sessionFactory);
        SessionHolder sessionHolder = new SessionHolder(session);
        TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);

        AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(sessionFactory, sessionHolder);
        asyncManager.registerCallableInterceptor(key, interceptor);
        asyncManager.registerDeferredResultInterceptor(key, interceptor);
      }
    }

    try {
      filterChain.doFilter(request, response);
View Full Code Here

   */
  @Override
  public void preHandle(WebRequest request) throws DataAccessException {
    String participateAttributeName = getParticipateAttributeName();

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    if (asyncManager.hasConcurrentResult()) {
      if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
        return;
      }
    }

    if ((isSingleSession() && TransactionSynchronizationManager.hasResource(getSessionFactory())) ||
      SessionFactoryUtils.isDeferredCloseActive(getSessionFactory())) {
      // Do not modify the Session: just mark the request accordingly.
      Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
      int newCount = (count != null ? count + 1 : 1);
      request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
    }
    else {
      if (isSingleSession()) {
        // single session mode
        logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
        Session session = SessionFactoryUtils.getSession(
            getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
        applyFlushMode(session, false);
        SessionHolder sessionHolder = new SessionHolder(session);
        TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

        AsyncRequestInterceptor asyncRequestInterceptor =
            new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
        asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
        asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
      }
      else {
        // deferred close mode
        SessionFactoryUtils.initDeferredClose(getSessionFactory());
      }
View Full Code Here

    registerAsyncResultInterceptors(request);
    super.service(request, response);
  }

  private void registerAsyncResultInterceptors(final HttpServletRequest request) {
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    asyncManager.registerCallableInterceptor(KEY, new CallableProcessingInterceptorAdapter() {
      @Override
      public <T> void postProcess(NativeWebRequest r, Callable<T> task, Object value) throws Exception {
        getMvcResult(request).setAsyncResult(value);
      }
    });
    asyncManager.registerDeferredResultInterceptor(KEY, new DeferredResultProcessingInterceptorAdapter() {
      @Override
      public <T> void postProcess(NativeWebRequest r, DeferredResult<T> result, Object value) throws Exception {
        getMvcResult(request).setAsyncResult(value);
      }
    });
View Full Code Here

    interceptor.preHandle(this.webRequest);
    assertTrue(TransactionSynchronizationManager.hasResource(sf));

    AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
    asyncManager.setTaskExecutor(new SyncTaskExecutor());
    asyncManager.setAsyncWebRequest(asyncWebRequest);
    asyncManager.startCallableProcessing(new Callable<String>() {
      @Override
      public String call() throws Exception {
        return "anything";
      }
    });
View Full Code Here

    interceptor.preHandle(this.webRequest);
    assertTrue(TransactionSynchronizationManager.hasResource(sf));

    AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
    asyncManager.setTaskExecutor(new SyncTaskExecutor());
    asyncManager.setAsyncWebRequest(asyncWebRequest);
    asyncManager.startCallableProcessing(new Callable<String>() {
      @Override
      public String call() throws Exception {
        return "anything";
      }
    });
View Full Code Here

        count.incrementAndGet();
      }
    };

    AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
    asyncManager.setTaskExecutor(new SyncTaskExecutor());
    asyncManager.setAsyncWebRequest(asyncWebRequest);
    asyncManager.startCallableProcessing(new Callable<String>() {
      @Override
      public String call() throws Exception {
        return "anything";
      }
    });
View Full Code Here

TOP

Related Classes of org.springframework.web.context.request.async.WebAsyncManager

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.