Search in sources :

Example 41 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project shiro by apache.

the class RestrictedErrorController method error.

@RequestMapping(ERROR_PATH)
String error(HttpServletRequest request, Model model) {
    Map<String, Object> errorMap = errorAttributes.getErrorAttributes(new ServletRequestAttributes(request), false);
    model.addAttribute("errors", errorMap);
    return "error";
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project pivotal-cla by pivotalsoftware.

the class ClaRequest method signUrl.

private String signUrl() throws Exception {
    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = requestAttributes.getRequest();
    return UrlBuilder.signUrl().request(request).claName(claName).repositoryId(repositoryId).pullRequestId(pullRequestId).build();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 43 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project ngtesting-platform by aaronchen2k.

the class StringUtil method getMessage.

/**
 * 获得i18n字符串
 */
public static String getMessage(String code, Object[] args) {
    LocaleResolver localLocaleResolver = SpringContextHolder.getBean(LocaleResolver.class);
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    Locale localLocale = localLocaleResolver.resolveLocale(request);
    return SpringContextHolder.getApplicationContext().getMessage(code, args, localLocale);
}
Also used : LocaleResolver(org.springframework.web.servlet.LocaleResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) Locale(java.util.Locale) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 44 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project spring-boot-quick by vector4wang.

the class WebLogAspect method doBefore.

@Before("logPointCut()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    loggger.info("请求地址 : " + request.getRequestURL().toString());
    loggger.info("HTTP METHOD : " + request.getMethod());
    loggger.info("IP : " + request.getRemoteAddr());
    loggger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    loggger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
// loggger.info("参数 : " + joinPoint.getArgs());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 45 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project spring-boot-quick by vector4wang.

the class WebLogAspect method doBefore.

@Before("logPointCut()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    loggger.info("请求地址 : " + request.getRequestURL().toString());
    loggger.info("HTTP METHOD : " + request.getMethod());
    loggger.info("IP : " + request.getRemoteAddr());
    loggger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    loggger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
// loggger.info("参数 : " + joinPoint.getArgs());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Aggregations

ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)205 HttpServletRequest (javax.servlet.http.HttpServletRequest)92 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)62 RequestAttributes (org.springframework.web.context.request.RequestAttributes)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)32 Test (org.junit.jupiter.api.Test)28 lombok.val (lombok.val)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 Test (org.junit.Test)18 AuthChecker (com.code.server.login.anotation.AuthChecker)17 HttpSession (javax.servlet.http.HttpSession)12 Before (org.junit.Before)12 HashMap (java.util.HashMap)11 Method (java.lang.reflect.Method)8 Date (java.util.Date)7 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)7 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)7 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)6 Map (java.util.Map)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6