Search in sources :

Example 61 with RequestAttributes

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Enumeration(java.util.Enumeration) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 62 with RequestAttributes

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserSession(com.haulmont.cuba.security.global.UserSession) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 63 with RequestAttributes

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");
    }
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 64 with RequestAttributes

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("不允许执行的操作!");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BusinessException(com.terran4j.commons.util.error.BusinessException) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 65 with RequestAttributes

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);
}
Also used : UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) ProjectControllerUtils(ca.corefacility.bioinformatics.irida.ria.web.projects.ProjectControllerUtils) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) MessageSource(org.springframework.context.MessageSource) ProjectSettingsAssociatedProjectsController(ca.corefacility.bioinformatics.irida.ria.web.projects.ProjectSettingsAssociatedProjectsController) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) Before(org.junit.Before)

Aggregations

RequestAttributes (org.springframework.web.context.request.RequestAttributes)81 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)51 HttpServletRequest (javax.servlet.http.HttpServletRequest)20 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 Test (org.junit.Test)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)3 DBUnitTest (org.orcid.test.DBUnitTest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 ProjectService (ca.corefacility.bioinformatics.irida.service.ProjectService)2 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)2 UserSession (com.haulmont.cuba.security.global.UserSession)2 ActionContext (com.opensymphony.xwork2.ActionContext)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2