• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java WebAsyncManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.web.context.request.async.WebAsyncManager的典型用法代码示例。如果您正苦于以下问题:Java WebAsyncManager类的具体用法?Java WebAsyncManager怎么用?Java WebAsyncManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WebAsyncManager类属于org.springframework.web.context.request.async包,在下文中一共展示了WebAsyncManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doFilterInternal

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        FilterChain filterChain) throws ServletException, IOException {
    setMdc();

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(httpServletRequest);

    UserIdLoggingFilter tenancyProcessingInterceptor = (UserIdLoggingFilter) asyncManager
            .getCallableInterceptor(CALLABLE_INTERCEPTOR_KEY);
    if (tenancyProcessingInterceptor == null) {
        asyncManager.registerCallableInterceptor(CALLABLE_INTERCEPTOR_KEY, new UserIdCallableProcessingInterceptorAdapter());
    }
    try {
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    } finally {
        removeMdc();
    }

}
 
开发者ID:Talend,项目名称:daikon,代码行数:20,代码来源:UserIdLoggingFilter.java


示例2: preHandle

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Override
public void preHandle(WebRequest request) throws DataAccessException {

	String participateAttributeName = getParticipateAttributeName();

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

	if (TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) {
		// do not modify the EntityManager: 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 JPA EntityManager in OpenEntityManagerInViewInterceptor");
		try {
			EntityManager em = createEntityManager();
			EntityManagerHolder emHolder = new EntityManagerHolder(em);
			TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), emHolder);

			AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(getEntityManagerFactory(), emHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, interceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, interceptor);
		}
		catch (PersistenceException ex) {
			throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:OpenEntityManagerInViewInterceptor.java


示例3: applyCallableInterceptor

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
private boolean applyCallableInterceptor(WebAsyncManager asyncManager, String key) {
	if (asyncManager.getCallableInterceptor(key) == null) {
		return false;
	}
	((AsyncRequestInterceptor) asyncManager.getCallableInterceptor(key)).bindSession();
	return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:OpenEntityManagerInViewInterceptor.java


示例4: applyEntityManagerBindingInterceptor

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
private boolean applyEntityManagerBindingInterceptor(WebAsyncManager asyncManager, String key) {
	if (asyncManager.getCallableInterceptor(key) == null) {
		return false;
	}
	((AsyncRequestInterceptor) asyncManager.getCallableInterceptor(key)).bindSession();
	return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:OpenEntityManagerInViewFilter.java


示例5: preHandle

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according and bind it to the thread via the
 * {@link org.springframework.transaction.support.TransactionSynchronizationManager}.
 */
@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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:OpenSessionInViewInterceptor.java


示例6: applySessionBindingInterceptor

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
private boolean applySessionBindingInterceptor(WebAsyncManager asyncManager, String key) {
	if (asyncManager.getCallableInterceptor(key) == null) {
		return false;
	}
	((AsyncRequestInterceptor) asyncManager.getCallableInterceptor(key)).bindSession();
	return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:OpenSessionInViewInterceptor.java


示例7: preHandle

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
@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());
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:OpenSessionInViewInterceptor.java


示例8: preHandle

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

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

	if (TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) {
		// Do not modify the EntityManager: 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 JPA EntityManager in OpenEntityManagerInViewInterceptor");
		try {
			EntityManager em = createEntityManager();
			EntityManagerHolder emHolder = new EntityManagerHolder(em);
			TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), emHolder);

			AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(getEntityManagerFactory(), emHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, interceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, interceptor);
		}
		catch (PersistenceException ex) {
			throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:OpenEntityManagerInViewInterceptor.java


示例9: preHandle

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 */
@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);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:OpenSessionInViewInterceptor.java


示例10: setUpAsyncDispatch

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
private void setUpAsyncDispatch() throws Exception {
	this.request.setAsyncSupported(true);
	this.request.setAsyncStarted(true);
	DeferredResult<String> result = new DeferredResult<String>();
	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
	asyncManager.setAsyncWebRequest(
			new StandardServletAsyncWebRequest(this.request, this.response));
	asyncManager.startDeferredResultProcessing(result);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ErrorPageFilterTests.java


示例11: doFilterInternal

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);

    TenancyContextIntegrationFilter tenancyProcessingInterceptor = (TenancyContextIntegrationFilter) asyncManager
            .getCallableInterceptor(CALLABLE_INTERCEPTOR_KEY);
    if (tenancyProcessingInterceptor == null) {
        asyncManager.registerCallableInterceptor(CALLABLE_INTERCEPTOR_KEY, new TenancyContextCallableProcessingInterceptor());
    }

    TenancyContext contextBeforeChainExecution = determineTenancyContext(request);

    try {
        TenancyContextHolder.setContext(contextBeforeChainExecution);
        setMdc(contextBeforeChainExecution);

        chain.doFilter(request, response);

    } finally {
        // Crucial removal of ContextHolder contents - do this
        // before anything else.
        TenancyContextHolder.clearContext();
        removeMdc();
    }

}
 
开发者ID:Talend,项目名称:daikon,代码行数:29,代码来源:TenancyContextIntegrationFilter.java


示例12: doFilterInternal

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {
    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    asyncManager.registerCallableInterceptor(KEY, this);
    filterChain.doFilter(request, response);
    this.checkContextIsClean();
}
 
开发者ID:Talend,项目名称:daikon,代码行数:9,代码来源:MultiTenantApplication.java


示例13: preHandle

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
public void preHandle(WebRequest request) throws DataAccessException {

		String participateAttributeName = getParticipateAttributeName();

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

		if (TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) {
			// do not modify the EntityManager: 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 JPA EntityManager in OpenEntityManagerInViewInterceptor");
			try {
				EntityManager em = createEntityManager();
				EntityManagerHolder emHolder = new EntityManagerHolder(em);
				TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), emHolder);

				AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(getEntityManagerFactory(), emHolder);
				asyncManager.registerCallableInterceptor(participateAttributeName, interceptor);
				asyncManager.registerDeferredResultInterceptor(participateAttributeName, interceptor);
			}
			catch (PersistenceException ex) {
				throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
			}
		}
	}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:34,代码来源:OpenEntityManagerInViewInterceptor.java


示例14: preHandle

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
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());
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:45,代码来源:OpenSessionInViewInterceptor.java


示例15: preHandle

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according and bind it to the thread via the
 * {@link org.springframework.transaction.support.TransactionSynchronizationManager}.
 */
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);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:33,代码来源:OpenSessionInViewInterceptor.java


示例16: testOpenEntityManagerInViewInterceptorAsyncScenario

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Test
public void testOpenEntityManagerInViewInterceptorAsyncScenario() throws Exception {

	// Initial request thread

	OpenEntityManagerInViewInterceptor interceptor = new OpenEntityManagerInViewInterceptor();
	interceptor.setEntityManagerFactory(factory);

	given(factory.createEntityManager()).willReturn(this.manager);

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

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

	interceptor.afterConcurrentHandlingStarted(this.webRequest);
	assertFalse(TransactionSynchronizationManager.hasResource(factory));

	// Async dispatch thread

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

	asyncManager.clearConcurrentResult();

	// check that further invocations simply participate
	interceptor.preHandle(new ServletWebRequest(request));

	interceptor.preHandle(new ServletWebRequest(request));
	interceptor.postHandle(new ServletWebRequest(request), null);
	interceptor.afterCompletion(new ServletWebRequest(request), null);

	interceptor.postHandle(new ServletWebRequest(request), null);
	interceptor.afterCompletion(new ServletWebRequest(request), null);

	interceptor.preHandle(new ServletWebRequest(request));
	interceptor.postHandle(new ServletWebRequest(request), null);
	interceptor.afterCompletion(new ServletWebRequest(request), null);

	interceptor.postHandle(this.webRequest, null);
	assertTrue(TransactionSynchronizationManager.hasResource(factory));

	given(this.manager.isOpen()).willReturn(true);

	interceptor.afterCompletion(this.webRequest, null);
	assertFalse(TransactionSynchronizationManager.hasResource(factory));

	verify(this.manager).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:59,代码来源:OpenEntityManagerInViewTests.java


示例17: testOpenSessionInViewInterceptorAsyncScenario

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Test
public void testOpenSessionInViewInterceptorAsyncScenario() throws Exception {
	// Initial request thread

	final SessionFactory sf = mock(SessionFactory.class);
	Session session = mock(Session.class);

	OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
	interceptor.setSessionFactory(sf);

	given(sf.openSession()).willReturn(session);
	given(session.getSessionFactory()).willReturn(sf);

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

	interceptor.afterConcurrentHandlingStarted(this.webRequest);
	assertFalse(TransactionSynchronizationManager.hasResource(sf));

	// Async dispatch thread

	interceptor.preHandle(this.webRequest);
	assertTrue("Session not bound to async thread", TransactionSynchronizationManager.hasResource(sf));

	interceptor.postHandle(this.webRequest, null);
	assertTrue(TransactionSynchronizationManager.hasResource(sf));

	verify(session, never()).close();

	interceptor.afterCompletion(this.webRequest, null);
	assertFalse(TransactionSynchronizationManager.hasResource(sf));

	verify(session).setFlushMode(FlushMode.MANUAL);
	verify(session).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:47,代码来源:OpenSessionInViewTests.java


示例18: testOpenSessionInViewFilterAsyncScenario

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Test
public void testOpenSessionInViewFilterAsyncScenario() throws Exception {
	final SessionFactory sf = mock(SessionFactory.class);
	Session session = mock(Session.class);

	// Initial request during which concurrent handling starts..

	given(sf.openSession()).willReturn(session);
	given(session.getSessionFactory()).willReturn(sf);

	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(sc);
	wac.getDefaultListableBeanFactory().registerSingleton("sessionFactory", sf);
	wac.refresh();
	sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);

	MockFilterConfig filterConfig = new MockFilterConfig(wac.getServletContext(), "filter");

	final AtomicInteger count = new AtomicInteger(0);

	final OpenSessionInViewFilter filter = new OpenSessionInViewFilter();
	filter.init(filterConfig);

	final FilterChain filterChain = new FilterChain() {
		@Override
		public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) {
			assertTrue(TransactionSynchronizationManager.hasResource(sf));
			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";
		}
	});

	assertFalse(TransactionSynchronizationManager.hasResource(sf));
	filter.doFilter(this.request, this.response, filterChain);
	assertFalse(TransactionSynchronizationManager.hasResource(sf));
	assertEquals(1, count.get());
	verify(session, never()).close();

	// Async dispatch after concurrent handling produces result ...

	this.request.setAsyncStarted(false);
	assertFalse(TransactionSynchronizationManager.hasResource(sf));
	filter.doFilter(this.request, this.response, filterChain);
	assertFalse(TransactionSynchronizationManager.hasResource(sf));
	assertEquals(2, count.get());

	verify(session).setFlushMode(FlushMode.MANUAL);
	verify(session).close();

	wac.close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:62,代码来源:OpenSessionInViewTests.java


示例19: testOpenEntityManagerInViewInterceptorAsyncScenario

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Test
public void testOpenEntityManagerInViewInterceptorAsyncScenario() throws Exception {

	// Initial request thread

	OpenEntityManagerInViewInterceptor interceptor = new OpenEntityManagerInViewInterceptor();
	interceptor.setEntityManagerFactory(factory);

	MockServletContext sc = new MockServletContext();
	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	ServletWebRequest webRequest = new ServletWebRequest(request);

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

	AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);

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

	verify(asyncWebRequest, times(2)).addCompletionHandler(any(Runnable.class));
	verify(asyncWebRequest).addTimeoutHandler(any(Runnable.class));
	verify(asyncWebRequest, times(2)).addCompletionHandler(any(Runnable.class));
	verify(asyncWebRequest).startAsync();

	interceptor.afterConcurrentHandlingStarted(webRequest);
	assertFalse(TransactionSynchronizationManager.hasResource(factory));

	// Async dispatch thread

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

	asyncManager.clearConcurrentResult();

	// check that further invocations simply participate
	interceptor.preHandle(new ServletWebRequest(request));

	interceptor.preHandle(new ServletWebRequest(request));
	interceptor.postHandle(new ServletWebRequest(request), null);
	interceptor.afterCompletion(new ServletWebRequest(request), null);

	interceptor.postHandle(new ServletWebRequest(request), null);
	interceptor.afterCompletion(new ServletWebRequest(request), null);

	interceptor.preHandle(new ServletWebRequest(request));
	interceptor.postHandle(new ServletWebRequest(request), null);
	interceptor.afterCompletion(new ServletWebRequest(request), null);

	interceptor.postHandle(webRequest, null);
	assertTrue(TransactionSynchronizationManager.hasResource(factory));

	given(manager.isOpen()).willReturn(true);

	interceptor.afterCompletion(webRequest, null);
	assertFalse(TransactionSynchronizationManager.hasResource(factory));

	verify(manager).close();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:67,代码来源:OpenEntityManagerInViewTests.java


示例20: testOpenSessionInViewInterceptorAsyncScenario

import org.springframework.web.context.request.async.WebAsyncManager; //导入依赖的package包/类
@Test
public void testOpenSessionInViewInterceptorAsyncScenario() throws Exception {

	// Initial request thread

	final SessionFactory sf = mock(SessionFactory.class);
	Session session = mock(Session.class);

	OpenSessionInViewInterceptor interceptor = new OpenSessionInViewInterceptor();
	interceptor.setSessionFactory(sf);

	given(sf.openSession()).willReturn(session);
	given(session.getSessionFactory()).willReturn(sf);

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

	AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);

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

	interceptor.afterConcurrentHandlingStarted(this.webRequest);
	assertFalse(TransactionSynchronizationManager.hasResource(sf));

	// Async dispatch thread

	interceptor.preHandle(this.webRequest);
	assertTrue("Session not bound to async thread", TransactionSynchronizationManager.hasResource(sf));

	interceptor.postHandle(this.webRequest, null);
	assertTrue(TransactionSynchronizationManager.hasResource(sf));

	interceptor.afterCompletion(this.webRequest, null);
	assertFalse(TransactionSynchronizationManager.hasResource(sf));

	verify(session).setFlushMode(FlushMode.MANUAL);
	verify(asyncWebRequest, times(2)).addCompletionHandler(any(Runnable.class));
	verify(asyncWebRequest).addTimeoutHandler(any(Runnable.class));
	verify(asyncWebRequest).startAsync();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:50,代码来源:OpenSessionInViewTests.java



注:本文中的org.springframework.web.context.request.async.WebAsyncManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StreamRequest类代码示例发布时间:2022-05-23
下一篇:
Java TomlWriter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap