當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletRequestAttributes.getRequest方法代碼示例

本文整理匯總了Java中org.springframework.web.context.request.ServletRequestAttributes.getRequest方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletRequestAttributes.getRequest方法的具體用法?Java ServletRequestAttributes.getRequest怎麽用?Java ServletRequestAttributes.getRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.context.request.ServletRequestAttributes的用法示例。


在下文中一共展示了ServletRequestAttributes.getRequest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doVerify

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的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

示例2: before

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
@Before("log()")
public void before(JoinPoint joinPoint) {
    timeTreadLocal.set(System.currentTimeMillis());
    // 接收到請求,記錄請求內容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    //獲取請求的request
    HttpServletRequest request = attributes.getRequest();
    //獲取所有請求的參數,封裝為map對象
    // Map<String,Object> parameterMap = getParameterMap(request);
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    //獲取被攔截的方法
    Method method = methodSignature.getMethod();
    //獲取被攔截的方法名
    String methodName = method.getName();
    logger.info("AOP begin ,請求開始方法  :{}", method.getDeclaringClass() + "." + methodName + "()");
    //獲取所有請求參數key和value
    String keyValue = getReqParameter(request);
    logger.info("請求url = {}", request.getRequestURL().toString());
    logger.info("請求方法requestMethod = {}", request.getMethod());
    logger.info("請求資源uri = {}", request.getRequestURI());
    logger.info("所有的請求參數 key:value = {}", keyValue);
}
 
開發者ID:fier-liu,項目名稱:FCat,代碼行數:23,代碼來源:LogAspect.java

示例3: doBefore

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
@Before(value = "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());
//        log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//        log.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
//        BasicDBObject logInfo = ;
        l.set(getBasicDBObject(request, joinPoint));
//        log.info(logInfo);
    }
 
開發者ID:nellochen,項目名稱:springboot-start,代碼行數:17,代碼來源:WebLogAspect.java

示例4: getRequest

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
/**
 * Gets the http request based on the
 * {@link org.springframework.web.context.request.RequestContextHolder}.
 * @return the request or null
 */
protected final HttpServletRequest getRequest() {
    try {
        final ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        if (attrs != null) {
            return attrs.getRequest();
        }
    }  catch (final Exception e) {
        LOGGER.trace("Unable to obtain the http request", e);
    }
    return null;
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:17,代碼來源:AbstractCasExpirationPolicy.java

示例5: doBefore

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的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("**************Start API Request**************");
    LOGGER.info("URL : " + request.getRequestURI().toString());
    LOGGER.info("HTTP_METHOD : " + request.getMethod());
    LOGGER.info("IP : " + request.getRemoteAddr());
    LOGGER.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    LOGGER.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
}
 
開發者ID:JesseHu1520,項目名稱:mall,代碼行數:17,代碼來源:WebLogAspect.java

示例6: process

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的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

示例7: doAround

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
/**
 * 環繞通知 用於攔截Controller層記錄用戶的操作
 */
@Around("controllerAspect()")
public Object doAround(ProceedingJoinPoint pjp) throws Throwable {

    logger.info("===> 執行controller - 環繞通知.");
    if(logger.isInfoEnabled()){
        logger.info("===> around: {}", pjp);
    }

    RequestAttributes ra = RequestContextHolder.getRequestAttributes();
    ServletRequestAttributes sra = (ServletRequestAttributes) ra;
    HttpServletRequest request = sra.getRequest();

    String url = request.getRequestURL().toString();
    String method = request.getMethod();
    String uri = request.getRequestURI();
    String queryString = request.getQueryString();
    logger.info("===> 請求開始:");
    logger.info("===> 請求參數: url: {}, method: {}, uri: {}, params: {}", url, method, uri, queryString);

    // result的值就是被攔截方法的返回值
    Object result = pjp.proceed();
    ObjectMapper mapper = new ObjectMapper();
    String resutlStr = mapper.writeValueAsString(result);
    logger.info("===> 請求結束:");
    logger.info("===> 請求結束: Controller返回值是:{}", resutlStr);

    return result;
}
 
開發者ID:jeikerxiao,項目名稱:SpringBootStudy,代碼行數:32,代碼來源:LogAspect.java

示例8: getRequest

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
/**
 * Gets the http request based on the
 * {@link org.springframework.web.context.request.RequestContextHolder}.
 * @return the request or null
 */
protected final HttpServletRequest getRequest() {
    try {
        final ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        if (attrs != null) {
            return attrs.getRequest();
        }
    }  catch (final Exception e) {
        logger.trace("Unable to obtain the http request", e);
    }
    return null;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:17,代碼來源:AbstractCasExpirationPolicy.java

示例9: doBefore

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的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

示例10: getCurrentRequest

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的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

示例11: filterAroundHandling

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
@Around("init()")
public Object filterAroundHandling(ProceedingJoinPoint joinPoint) throws Throwable {
  log.debug("around handing");
  //action
  MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
  Method action = methodSignature.getMethod();
  //接收到請求,記錄請求內容
  ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  HttpServletRequest request = attributes.getRequest();
  //流控
  String clientIp = request.getRemoteAddr();
  String sessionId = request.getSession().getId();
  String requestUri = request.getRequestURI();
  String requestMethod = request.getMethod();
  long requestTimestamp = System.currentTimeMillis();
  flowControlService.flowController(clientIp, sessionId, requestUri, requestMethod, requestTimestamp, action.getDeclaredAnnotation(FlowControl.class));
  //過濾參數
  Map<String, String[]> filterParam = filterParamService.filterParam(request.getParameterMap(), action.getDeclaredAnnotation(FilterParam.class));
  //觸發action, 完成參數校驗部分
  Object object = joinPoint.proceed();
  log.debug("local response: {}", object);
  //透傳
  PipeConfig pipeConfig = action.getAnnotation(PipeConfig.class);
  if (pipeConfig != null) {
    object = penetrationService.penetrate(request, action, methodSignature.getDeclaringType(), filterParam);
  }
  log.debug("penetration response: {}", object);
  return object;
}
 
開發者ID:chuangxian,項目名稱:lib-edge,代碼行數:30,代碼來源:BeforeControllerAdvice.java

示例12: doBefore

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
@Before("weblog()")
public void doBefore(JoinPoint joinpoint) throws Throwable {
    // 接收到請求,記錄請求內容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 記錄下請求內容
    logger.info("Started " + request.getMethod() + " "
            + request.getRequestURL().toString() + " for "
            + request.getRemoteAddr() + " at " + LocalDateTime.now());
    logger.info("Processing by " + joinpoint.getSignature().getDeclaringTypeName() + "." + joinpoint.getSignature().getName()
            + " " + request.getContentType());
    logger.info("Parameters: " + mapper.writeValueAsString(request.getParameterMap()));
}
 
開發者ID:myliang,項目名稱:fish-admin,代碼行數:14,代碼來源:WebLogAspectConfig.java

示例13: loadUserByUsername

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的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

示例14: doBefore

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) {
    startTime.set(System.currentTimeMillis());

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    logger.info("HTTP_METHOD: {}, URL: {}, IP: {}, CLASS_METHOD: {}, ARGS: {}", request.getMethod(),
            request.getRequestURL().toString(), request.getRemoteAddr(),
            joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName(),
            Arrays.toString(joinPoint.getArgs()));
}
 
開發者ID:YupaiTS,項目名稱:docs-manage,代碼行數:13,代碼來源:WebLogAspect.java

示例15: getRequest

import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
public static HttpServletRequest getRequest() {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    return attributes.getRequest();
}
 
開發者ID:DomKing,項目名稱:springbootWeb,代碼行數:5,代碼來源:SecurityUtil.java


注:本文中的org.springframework.web.context.request.ServletRequestAttributes.getRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。