本文整理匯總了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();
}
}
示例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);
}
示例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);
}
示例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;
}
示例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()));
}
示例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;
}
示例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;
}
示例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;
}
示例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()));
}
示例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;
}
示例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;
}
示例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()));
}
示例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;
}
示例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()));
}
示例15: getRequest
import org.springframework.web.context.request.ServletRequestAttributes; //導入方法依賴的package包/類
public static HttpServletRequest getRequest() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attributes.getRequest();
}