當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。