List of usage examples for org.springframework.web.context.request RequestContextHolder getRequestAttributes
@Nullable public static RequestAttributes getRequestAttributes()
From source file:org.dbflute.utflute.spring.web.bean.BarActionTest.java
@Override public void setUp() throws Exception { assertNull(barLogic);//from www. j a va 2s .c o m assertNull(cachedInjectingBarAction); assertNull(cachedNestedBarLogic); assertNull(RequestContextHolder.getRequestAttributes()); super.setUp(); assertNotNull(barLogic); }
From source file:de.metas.ui.web.session.UserSession.java
/** * Gets current {@link UserSession} if any * //from w w w .j ava 2s.c o m * @return {@link UserSession} or null */ public static UserSession getCurrentOrNull() { // // Quickly check if the session scoped UserSession bean will be really available // NOTE: it's not about that the object will be null but if it's method calls will be really working if (RequestContextHolder.getRequestAttributes() == null) { return null; } // UserSession userSession = _userSession; if (userSession == null) { synchronized (UserSession.class) { if (_userSession == null) { userSession = _userSession = Adempiere.getSpringApplicationContext().getBean(UserSession.class); } } } return userSession; }
From source file:com.krawler.esp.database.MBasicDataSource.java
@Override public Connection getConnection() throws SQLException { ServletRequestAttributes ss = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); String domain_key = ""; try {//from www . j a v a 2 s. com domain_key = URLUtil.getDomainName(ss.getRequest()); } catch (Exception ex) { System.out.print(ex); } if (!dataSourceMap.containsKey(domain_key)) { dataSourceMap.put(domain_key, createDataSource(domain_key)); } super.dataSource = (DataSource) dataSourceMap.get(domain_key); return super.dataSource.getConnection(); }
From source file:uk.ac.ebi.intact.editor.util.HybridSessionThreadScope.java
public String getConversationId() { if (RequestContextHolder.getRequestAttributes() != null) { return RequestContextHolder.currentRequestAttributes().getSessionId(); }//from www. j av a2s . co m return super.getConversationId(); }
From source file:com.roncoo.controller.BaseController.java
/** * ?request * * @return */ protected HttpServletRequest getRequest() { return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); }
From source file:com.iwancool.dsm.service.impl.AbstractBaseService.java
/** * ?/* ww w .ja va 2 s .c o m*/ * * @author long * @param path * @return * @throws Exception * @return String * @exception * @author long * @since 1.0.0 * @date 2015715 ?6:57:37 */ public String getProjectRealPath(String path) throws Exception { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); return request.getSession().getServletContext().getRealPath(path); }
From source file:com.hongqiang.shop.common.utils.StringUtils.java
/** * i18n//from ww w.j a v a2 s. c om */ public static String getMessage(String code, Object[] args) { LocaleResolver localLocaleResolver = (LocaleResolver) SpringContextHolder.getBean(LocaleResolver.class); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); Locale localLocale = localLocaleResolver.resolveLocale(request); return SpringContextHolder.getApplicationContext().getMessage(code, args, localLocale); }
From source file:com.baidu.stqa.signet.web.action.BaseAction.java
public String getUser() { HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest() .getSession();// ww w . j a v a2s .com Object obj = session.getAttribute(USER_NAME); String user = null; if (obj != null) { user = (String) obj; } return user; }
From source file:io.jmnarloch.spring.request.correlation.support.RequestCorrelationUtilsTest.java
@Test public void shouldRetrieveRequestId() { // given// w ww. j ava2s . com final String requestId = UUID.randomUUID().toString(); RequestContextHolder.getRequestAttributes().setAttribute(RequestCorrelationConsts.ATTRIBUTE_NAME, new DefaultRequestCorrelation(requestId), RequestAttributes.SCOPE_REQUEST); // when final String correlationId = RequestCorrelationUtils.getCurrentCorrelationId(); // then assertEquals(requestId, correlationId); }
From source file:at.ac.univie.isc.asio.spring.ContextPropagatorTest.java
@Test public void should_clear_attributes_from_current_thread() throws Exception { RequestContextHolder.setRequestAttributes(attributes); subject.close();// ww w .j a v a2s . c om assertThat(RequestContextHolder.getRequestAttributes(), nullValue()); }