List of usage examples for org.springframework.web.context.request RequestContextHolder currentRequestAttributes
public static RequestAttributes currentRequestAttributes() throws IllegalStateException
From source file:net.shopxx.service.impl.MerchantServiceImpl.java
@Transactional(readOnly = true) public boolean isAuthenticated() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) request.getSession().getAttribute(Merchant.PRINCIPAL_ATTRIBUTE_NAME); if (principal != null) { return true; }/*from w w w .j a v a2 s.c o m*/ } return false; }
From source file:com.cws.us.pws.controllers.CommonController.java
@RequestMapping(value = "/default", method = RequestMethod.GET) public final ModelAndView showDefaultPage() { final String methodName = CommonController.CNAME + "#showDefaultPage()"; if (DEBUG) {/*w w w. j av a 2 s .c o m*/ DEBUGGER.debug(methodName); } ModelAndView mView = new ModelAndView(); final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); final HttpServletRequest hRequest = requestAttributes.getRequest(); final HttpSession hSession = hRequest.getSession(); final String lang = hRequest.getParameter(Constants.PARAMETER_LANG); if (DEBUG) { DEBUGGER.debug("ServletRequestAttributes: {}", requestAttributes); DEBUGGER.debug("HttpServletRequest: {}", hRequest); DEBUGGER.debug("HttpSession: {}", hSession); DEBUGGER.debug("lang: {}", lang); DEBUGGER.debug("Dumping session content:"); @SuppressWarnings("unchecked") Enumeration<String> sessionEnumeration = hSession.getAttributeNames(); while (sessionEnumeration.hasMoreElements()) { String sessionElement = sessionEnumeration.nextElement(); Object sessionValue = hSession.getAttribute(sessionElement); DEBUGGER.debug("Attribute: " + sessionElement + "; Value: " + sessionValue); } DEBUGGER.debug("Dumping request content:"); @SuppressWarnings("unchecked") Enumeration<String> requestEnumeration = hRequest.getAttributeNames(); while (requestEnumeration.hasMoreElements()) { String requestElement = requestEnumeration.nextElement(); Object requestValue = hRequest.getAttribute(requestElement); DEBUGGER.debug("Attribute: " + requestElement + "; Value: " + requestValue); } DEBUGGER.debug("Dumping request parameters:"); @SuppressWarnings("unchecked") Enumeration<String> paramsEnumeration = hRequest.getParameterNames(); while (paramsEnumeration.hasMoreElements()) { String requestElement = paramsEnumeration.nextElement(); Object requestValue = hRequest.getParameter(requestElement); DEBUGGER.debug("Parameter: " + requestElement + "; Value: " + requestValue); } } try { ProductRequest productRequest = new ProductRequest(); productRequest.setIsFeatured(true); productRequest.setLang((StringUtils.isBlank(lang)) ? "en" : lang); if (DEBUG) { DEBUGGER.debug("ProductRequest: {}", productRequest); } ProductResponse productResponse = this.productRefSvc.getFeaturedProducts(productRequest); if (DEBUG) { DEBUGGER.debug("ProductResponse: {}", productResponse); } if (productResponse.getRequestStatus() == CoreServicesStatus.SUCCESS) { List<Product> featuredProducts = productResponse.getProductList(); if (DEBUG) { DEBUGGER.debug("List<Product>: {}", featuredProducts); } mView.addObject("featuredProducts", featuredProducts); } } catch (ProductRequestException prx) { ERROR_RECORDER.error(prx.getMessage(), prx); mView = new ModelAndView(new RedirectView()); mView.setViewName(this.appConfig.getErrorResponsePage()); } mView.setViewName(this.appConfig.getHomePage()); if (DEBUG) { DEBUGGER.debug("ModelAndView: {}", mView); } return mView; }
From source file:net.groupbuy.service.impl.MemberServiceImpl.java
@Transactional(readOnly = true) public Member getCurrent() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) request.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); if (principal != null) { return memberDao.find(principal.getId()); }/*from w w w.j a va 2 s .c o m*/ } return null; }
From source file:org.jtalks.poulpe.security.AclAwareDecisionVoter.java
/** * @return current request attributes*/ @VisibleForTesting RequestAttributes getRequestAttributes() { return RequestContextHolder.currentRequestAttributes(); }
From source file:com.dp2345.service.impl.ShopServiceImpl.java
/** * ??/*w w w.j a va 2 s . c o m*/ */ @Transactional(readOnly = true) public Member getCurrent() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) request.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); if (principal != null) { return memberDao.find(principal.getId()); } } return null; }
From source file:net.shopxx.service.impl.MerchantServiceImpl.java
@Transactional(readOnly = true) public Merchant getCurrent() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) request.getSession().getAttribute(Merchant.PRINCIPAL_ATTRIBUTE_NAME); if (principal != null) { return merchantDao.find(principal.getId()); }//from www . j a v a2 s . c om } return null; }
From source file:com.jaspersoft.jasperserver.war.model.impl.AwsDataSourceTreeDataProvider.java
private String retrieveEndpointFromRequest() { ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); HttpServletRequest request = attr.getRequest(); return request.getParameter("region"); }
From source file:com.archsystemsinc.ipms.sec.webapp.controller.IssueController.java
public static HttpSession getSession() { final ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); return attr.getRequest().getSession(true); }
From source file:net.osxx.service.impl.MemberServiceImpl.java
@Transactional(readOnly = true) public Member getCurrent() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) request.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); String username = (String) request.getSession().getAttribute(Member.USERNAME_COOKIE_NAME); if (principal != null) { return memberDao.find(principal.getId()); }/* w w w.j a va 2 s . co m*/ } return null; }
From source file:net.groupbuy.service.impl.MemberServiceImpl.java
@Transactional(readOnly = true) public String getCurrentUsername() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) request.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); if (principal != null) { return principal.getUsername(); }/*from w w w .ja va2 s . c o m*/ } return null; }