当前位置: 首页>>代码示例>>Java>>正文


Java WebRequest.getAttribute方法代码示例

本文整理汇总了Java中org.springframework.web.context.request.WebRequest.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java WebRequest.getAttribute方法的具体用法?Java WebRequest.getAttribute怎么用?Java WebRequest.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.context.request.WebRequest的用法示例。


在下文中一共展示了WebRequest.getAttribute方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: afterCompletion

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count != null) {
		// Do not modify the PersistenceManager: just clear the marker.
		if (count > 1) {
			request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
		}
		else {
			request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		}
	}
	else {
		PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
				TransactionSynchronizationManager.unbindResource(getPersistenceManagerFactory());
		logger.debug("Closing JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
		PersistenceManagerFactoryUtils.releasePersistenceManager(
				pmHolder.getPersistenceManager(), getPersistenceManagerFactory());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:OpenPersistenceManagerInViewInterceptor.java

示例2: preHandle

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	if (TransactionSynchronizationManager.hasResource(getPersistenceManagerFactory())) {
		// Do not modify the PersistenceManager: just mark the request accordingly.
		String participateAttributeName = getParticipateAttributeName();
		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 JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
		PersistenceManager pm =
				PersistenceManagerFactoryUtils.getPersistenceManager(getPersistenceManagerFactory(), true);
		TransactionSynchronizationManager.bindResource(
				getPersistenceManagerFactory(), new PersistenceManagerHolder(pm));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:OpenPersistenceManagerInViewInterceptor.java

示例3: preHandle

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void preHandle(WebRequest request) throws Exception {
	if (request.getUserPrincipal() == null)
		return;
	Map<String, String> o = (Map<String, String>)
			request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, WebRequest.SCOPE_REQUEST);
	if (o == null)
		return;
	if (o.get(USERNAME_ATTRIBUTE) != null && o.get(USERNAME_ATTRIBUTE).equals(LOGGED_IN_USER_PARAMETER)) {
		o.put(USERNAME_ATTRIBUTE, request.getUserPrincipal().getName());
	}
}
 
开发者ID:codenergic,项目名称:theskeleton,代码行数:14,代码来源:LoggedInUserInterceptor.java

示例4: getAsyncManager

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
/**
 * Obtain the {@link WebAsyncManager} for the current request, or if not
 * found, create and associate it with the request.
 */
public static WebAsyncManager getAsyncManager(WebRequest webRequest) {
	int scope = RequestAttributes.SCOPE_REQUEST;
	WebAsyncManager asyncManager = (WebAsyncManager) webRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, scope);
	if (asyncManager == null) {
		asyncManager = new WebAsyncManager();
		webRequest.setAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, asyncManager, scope);
	}
	return asyncManager;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:WebAsyncUtils.java

示例5: retrieveAttribute

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
@Override
public Object retrieveAttribute(WebRequest request, String attributeName) {
	Assert.notNull(request, "WebRequest must not be null");
	Assert.notNull(attributeName, "Attribute name must not be null");
	String storeAttributeName = getAttributeNameInSession(request, attributeName);
	return request.getAttribute(storeAttributeName, WebRequest.SCOPE_SESSION);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:DefaultSessionAttributeStore.java

示例6: preHandle

import org.springframework.web.context.request.WebRequest; //导入方法依赖的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

示例7: decrementParticipateCount

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:OpenEntityManagerInViewInterceptor.java

示例8: preHandle

import org.springframework.web.context.request.WebRequest; //导入方法依赖的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

示例9: preHandle

import org.springframework.web.context.request.WebRequest; //导入方法依赖的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

示例10: getLoginForm

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
@GetMapping
public String getLoginForm(WebRequest request, Model model) {
	String continueUri = (String) request.getAttribute(AuthorizationEndpoint.AUTH_REQUEST_URI_ATTRIBUTE,
			RequestAttributes.SCOPE_SESSION);

	if (continueUri != null) {
		model.addAttribute(AuthorizationEndpoint.AUTH_REQUEST_URI_ATTRIBUTE, continueUri);
	}

	return LOGIN_FORM_VIEW_NAME;
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:12,代码来源:LoginFormController.java

示例11: getLoginErrorForm

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
@GetMapping(params = ERROR_PARAMETER_NAME)
public String getLoginErrorForm(WebRequest request, Model model) {
	AuthenticationException error = (AuthenticationException) request
			.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, RequestAttributes.SCOPE_SESSION);
	model.addAttribute(ERROR_PARAMETER_NAME, error != null ? error.getMessage() : DEFAULT_ERROR_MESSAGE);

	return getLoginForm(request, model);
}
 
开发者ID:vpavic,项目名称:simple-openid-provider,代码行数:9,代码来源:LoginFormController.java

示例12: getUserConnection

import org.springframework.web.context.request.WebRequest; //导入方法依赖的package包/类
@ModelAttribute("currentUserConnection")
public ConnectionData getUserConnection(WebRequest request) {
    return (ConnectionData) request.getAttribute(SESSION_USER_CONNECTION,
            RequestAttributes.SCOPE_SESSION);
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:6,代码来源:GlobalController.java


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