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


Java RequestContextHolder.getRequestAttributes方法代码示例

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


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

示例1: doBefore

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Before("webLog()")
public void doBefore(JoinPoint joinPoint){
    log.info("------------日志开始:"+LocalDateTime.now()+"------------");
    startTime.set(System.currentTimeMillis());
    // 接收到请求,记录请求内容
    log.info("WebLogAspect.doBefore()");
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    log.info("URL : " + request.getRequestURL().toString());
    log.info("HTTP_METHOD : " + request.getMethod());
    log.info("IP : " + request.getRemoteAddr());
    log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    log.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
    //获取所有参数方法一:
    Enumeration enu=request.getParameterNames();
    while(enu.hasMoreElements()){
        String paraName=(String)enu.nextElement();
        log.info("PARAM :"+"("+paraName+" : "+request.getParameter(paraName)+")");
    }
}
 
开发者ID:TheWinding,项目名称:Burst,代码行数:22,代码来源:WebLogAspect.java

示例2: doBefore

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    startTime.set(System.currentTimeMillis());

    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    // 记录下请求内容
    logger.info("请求地址 : " + request.getRequestURL().toString());
    logger.info("请求方法类型 : " + request.getMethod());
    logger.info("IP : " + request.getRemoteAddr());
    logger.info("请求方法 : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    logger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));

}
 
开发者ID:handexing,项目名称:pinkyLam-Blog-Server,代码行数:17,代码来源:WebLogAspect.java

示例3: filterBeforeHandling

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Before("init()")
public void filterBeforeHandling(JoinPoint joinPoint) throws Exception {
  log.debug("before handing");
  ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  HttpServletRequest request = attributes.getRequest();
  Map<String, String> requestInfoMap = new LinkedHashMap<>();
  String clientIpAddr = RequestHelper.getRealIp(request);
  String requestUri = request.getRequestURI();
  String requestMethod = request.getMethod();
  int size = 0;
  requestInfoMap.put(TemplateEnum.MESSAGE_SOURCE, environment.getProperty(ENV_LOG_KAFKA_MESSAGE_SOURCE));
  requestInfoMap.put(TemplateEnum.REMOTE_HOST, clientIpAddr);
  requestInfoMap.put(TemplateEnum.REQUEST_METHOD, requestMethod);
  requestInfoMap.put(TemplateEnum.RESPONSE_BODY_SIZE, String.valueOf(size));
  requestInfoMap.put(TemplateEnum.REQUEST_URI, requestUri);
  requestInfoMap.put(TemplateEnum.SERVICE_NAME, environment.getProperty(ENV_APPLICATION_NAME));
  requestInfo.set(requestInfoMap);
  startTime.set(System.currentTimeMillis());
}
 
开发者ID:chuangxian,项目名称:lib-edge,代码行数:20,代码来源:BeforeControllerAdvice.java

示例4: process

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
/**
 * 查询物品最低价时统计物品查询
 * @param point 切点
 * @return 切面方法返回值
 * @throws Throwable 异常
 */
@Around("execution(public * com.bnade.wow.controller.CheapestAuctionController.findAll(..))")
public Object process(ProceedingJoinPoint point) throws Throwable {
    // 获取方法参数
    CheapestAuction cheapestAuction = null;
    Object[] args = point.getArgs();
    if (args != null && args.length == 1) {
        cheapestAuction = (CheapestAuction)args[0];
    }
    // 实际方法运行
    Object returnValue = point.proceed();
    if (cheapestAuction != null && returnValue != null && returnValue instanceof List) {
        // 当有返回数据时才统计
        if (((List) returnValue).size() > 0) {
            // 获取httprequest
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = attributes.getRequest();
            String ip = IPUtils.getIp(request);
            // 统计物品搜索
            logger.debug("记录ip: {}, item: {}", ip, cheapestAuction.getItemId());
            statisticService.recordItemSearchedByIp(ip, "" + cheapestAuction.getItemId());
        }
    }
    return returnValue;
}
 
开发者ID:liufeng0103,项目名称:bnade-web-ssh,代码行数:31,代码来源:StatisticAspect.java

示例5: getCurrentRequest

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
/**
 * Obtain the request through {@link RequestContextHolder}.
 * @return the active servlet request
 */
protected static HttpServletRequest getCurrentRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}
 
开发者ID:jaschenk,项目名称:Your-Microservice,代码行数:13,代码来源:YourServletUriComponentsBuilder.java

示例6: doVerify

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Before("verify()")
public void doVerify() {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    //查询cookie
    Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN);
    if (cookie == null) {
        log.warn("【登录校验】Cookie中查不到token");
        throw new SellerAuthorizeException();
    }

    //去redis里查询
    String tokenValue = redisTemplate.opsForValue().get(String.format(RedisConstant.TOKEN_PREFIX, cookie.getValue()));
    if (StringUtils.isEmpty(tokenValue)) {
        log.warn("【登录校验】Redis中查不到token");
        throw new SellerAuthorizeException();
    }
}
 
开发者ID:ldlood,项目名称:SpringBoot_Wechat_Sell,代码行数:20,代码来源:SellerAuthorizeAspect.java

示例7: list

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@RequiresPermissions("admin:index")
@ResponseBody
@RequestMapping(value = "/admins", method = RequestMethod.GET)
public ResponseDTO list() {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    Integer pageSize = Integer.valueOf(Objects.nonNull(request.getParameter("pageSize")) ? request.getParameter("pageSize") : "20");
    Integer pageNumber = Integer.valueOf(Objects.nonNull(request.getParameter("pageIndex")) ? request.getParameter("pageIndex") : "1");
    String userName = request.getParameter("userName");
    String email = request.getParameter("email");
    String reservation = request.getParameter("reservation");
    logger.info("查询条件为,userName:{},email:{},reservation:{}", userName, email, reservation);
    Map<String, Object> params = new HashMap();
    if (!StringUtils.isEmpty(userName)) {
        params.put("userName", userName);
    }
    if (!StringUtils.isEmpty(email)) {
        params.put("userEmail", email);
    }
    Pagination<AdminDO> pagination = adminService.pageAdminsByConditions(pageNumber, pageSize, params);
    return new ResponseDTO(0, "success", pagination);
}
 
开发者ID:wu05281,项目名称:admin-shiro,代码行数:23,代码来源:AdminCtl.java

示例8: doBefore

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    LOGGER.info("URL : " + request.getRequestURL().toString() + ",IP : " + request.getRemoteAddr() + ",CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() + ",ARGS : " + Arrays.toString(joinPoint.getArgs()));
}
 
开发者ID:ZHENFENG13,项目名称:My-Blog,代码行数:9,代码来源:LogAspect.java

示例9: getCurrentRequest

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
public static HttpServletRequest getCurrentRequest() {
	ServletRequestAttributes reqAttrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
	if (reqAttrs == null) {
		return null;
	}
	HttpServletRequest request = reqAttrs.getRequest();
	return request;
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:9,代码来源:WebUtils.java

示例10: doBefore

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Before("weblog()")
public void doBefore(JoinPoint joinpoint) throws Throwable {
    ServletRequestAttributes attributes =
            (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    log.info("URL : " + request.getRequestURL().toString());
    log.info("TYPE : " + request.getMethod());
    log.info("REMOTE IP : " + request.getRemoteAddr());
    log.info("METHOD : " + joinpoint.getSignature().getDeclaringTypeName() + "." + joinpoint.getSignature().getName());
    log.info("PARAMETERS : " + Arrays.toString(joinpoint.getArgs()));
}
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:13,代码来源:LogAspect.java

示例11: loadUserByUsername

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Override
public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    Byte accountType = Byte.valueOf(request.getParameter(SecurityUtil.ACCOUNT_TYPE));
    CustomerUserDetail customerUserDetail = securityService.getUserDetailByName(name, accountType);
    if (customerUserDetail == null) {
        throw new UsernameNotFoundException("用户不存在或密码错误");
    }
    return customerUserDetail;
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:12,代码来源:CustomerUserDetailService.java

示例12: doBefore

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    logger.debug("***************请求开始***************");
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    CommLogger commLogger = new CommLogger();
    commLogger.setActionUrlAll(request.getRequestURL().toString());
    commLogger.setActionUrlTail(request.getServletPath());
    commLogger.setRequestParams(JSON.toJSONString(request.getParameterMap()));
    commLogger.setIp(IPUtil.getRealIP(request));
    commLogger.setReqStartTime(new Date());
    commLoggerThreadLocal.set(commLogger);

    // 记录下请求内容
    logger.debug("URL : " + request.getRequestURL().toString());
    logger.debug("HTTP_METHOD : " + request.getMethod());
    logger.debug("IP : " + IPUtil.getRealIP(request));
    logger.debug("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    logger.debug("ARGS : " + Arrays.toString(joinPoint.getArgs()));
    logger.debug("params : " + JSON.toJSONString(request.getParameterMap()));

}
 
开发者ID:DomKing,项目名称:webDemo,代码行数:25,代码来源:WebLogAspect.java

示例13: getCurrentRequest

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
public static HttpServletRequest getCurrentRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}
 
开发者ID:tspannhw,项目名称:phoenix,代码行数:9,代码来源:DataController.java

示例14: doBefore

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    startTime.set(System.currentTimeMillis());
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    log.info("URL : " + request.getRequestURL().toString());
    log.info("HTTP_METHOD : " + request.getMethod());
    log.info("IP : " + (request.getRemoteAddr().equals("0:0:0:0:0:0:0:1") ? "127.0.0.1":request.getRemoteAddr()));
    log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    log.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
}
 
开发者ID:MIYAOW,项目名称:MI-S,代码行数:14,代码来源:WebRequestLogAspect.java

示例15: getWxWebUserFromSession

import org.springframework.web.context.request.RequestContextHolder; //导入方法依赖的package包/类
public static WxWebUser getWxWebUserFromSession() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        return (WxWebUser) requestAttributes.getAttribute(WX_SESSION_USER, RequestAttributes.SCOPE_SESSION);
    }
    return null;
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:8,代码来源:WxWebUtils.java


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