use of org.springframework.web.context.request.RequestAttributes in project summer by foxsugar.
the class AgentUtil method findAttributeInHeaders.
public static String findAttributeInHeaders(String key) {
String token = "";
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
Enumeration e = request.getHeaderNames();
boolean find = false;
while (e.hasMoreElements()) {
if (find)
break;
String headerName = (String) e.nextElement();
Enumeration<String> headerValues = request.getHeaders(headerName);
while (headerValues.hasMoreElements()) {
String str = headerValues.nextElement();
// System.out.println(headerName + ":" + str);
if (headerName.equals(key)) {
token = str;
find = true;
}
}
}
return token;
}
use of org.springframework.web.context.request.RequestAttributes in project cuba by cuba-platform.
the class PortalUserSessionSource method getUserSessionFromMiddleware.
protected UserSession getUserSessionFromMiddleware(UUID sessionId) {
UserSession userSession = null;
HttpServletRequest request = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
request = ((ServletRequestAttributes) requestAttributes).getRequest();
}
if (request != null) {
userSession = (UserSession) request.getAttribute(REQUEST_ATTR);
}
if (userSession != null) {
return userSession;
}
userSession = userSessionService.getUserSession(sessionId);
if (request != null) {
request.setAttribute(REQUEST_ATTR, userSession);
}
return userSession;
}
use of org.springframework.web.context.request.RequestAttributes in project commons by terran4j.
the class RestPackAspect method doAfter.
@After("httpResultPackAspect()")
public void doAfter(JoinPoint point) {
if (isRestPack()) {
RequestAttributes servlet = RequestContextHolder.getRequestAttributes();
HttpServletResponse response = ((ServletRequestAttributes) servlet).getResponse();
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "text/json;charset=UTF-8");
}
}
use of org.springframework.web.context.request.RequestAttributes in project commons by terran4j.
the class RestPackDemoAspect method doBefore.
@Before("httpDemoPackAspect()")
public void doBefore(JoinPoint point) throws BusinessException {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes servlet = (ServletRequestAttributes) requestAttributes;
HttpServletRequest httpRequest = servlet.getRequest();
String f = httpRequest.getParameter("f");
if ("e".equals(f)) {
throw new BusinessException(ErrorCodes.ACCESS_DENY).setMessage("不允许执行的操作!");
}
}
use of org.springframework.web.context.request.RequestAttributes in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsControllerTest method setUp.
@Before
public void setUp() {
projectService = mock(ProjectService.class);
userService = mock(UserService.class);
projectUtils = mock(ProjectControllerUtils.class);
messageSource = mock(MessageSource.class);
controller = new ProjectSettingsAssociatedProjectsController(projectService, projectUtils, userService, messageSource);
// fake out the servlet response so that the URI builder will work.
RequestAttributes ra = new ServletRequestAttributes(new MockHttpServletRequest());
RequestContextHolder.setRequestAttributes(ra);
}
Aggregations