Java Code Examples for org.springframework.web.context.request.ServletRequestAttributes#getResponse()

The following examples show how to use org.springframework.web.context.request.ServletRequestAttributes#getResponse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseController.java    From feiqu-opensource with Apache License 2.0 5 votes vote down vote up
protected FqUserCache getCurrentUser(){
    ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes());
    HttpServletRequest request = servletRequestAttributes
            .getRequest();
    HttpServletResponse response = servletRequestAttributes
            .getResponse();
    WebUtil webUtil = SpringUtils.getBean(WebUtil.class);
    return webUtil.currentUser(request,response);
}
 
Example 2
Source File: MonitoringEndpoint.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Display a report page.
 * @throws ServletException e
 * @throws IOException e
 */
@ReadOperation
public void report() throws ServletException, IOException {
	final ServletRequestAttributes currentRequestAttributes = (ServletRequestAttributes) RequestContextHolder
			.currentRequestAttributes();
	final HttpServletRequest httpServletRequest = currentRequestAttributes.getRequest();
	final HttpServletResponse httpResponse = currentRequestAttributes.getResponse();

	reportServlet.service(httpServletRequest, httpResponse);
}
 
Example 3
Source File: PageProcessAspect.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 写cookie 信息
 *
 * @param pd         页面封装信息
 * @param attributes
 * @throws IOException
 */
private void writeCookieInfo(IPageData pd, ServletRequestAttributes attributes) throws IOException {
    // 这里目前只写到组件级别,如果需要 写成方法级别
    if (!StringUtil.isNullOrNone(pd.getToken()) && "login".equals(pd.getComponentCode())) {
        HttpServletResponse response = attributes.getResponse();
        Cookie cookie = new Cookie(CommonConstant.COOKIE_AUTH_TOKEN, pd.getToken());
        cookie.setHttpOnly(true);
        cookie.setPath("/");
        response.addCookie(cookie);
        response.flushBuffer();
    }

}
 
Example 4
Source File: RequestHolder.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取Response
 *
 * @return HttpServletRequest
 */
public static HttpServletResponse getResponse() {
    log.debug("getResponse -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName());
    ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
    if (null == servletRequestAttributes) {
        return null;
    }
    return servletRequestAttributes.getResponse();
}
 
Example 5
Source File: RequestHolder.java    From springboot-shiro with MIT License 5 votes vote down vote up
/**
 * 获取Response
 *
 * @return HttpServletRequest
 */
public static HttpServletResponse getResponse() {
    log.debug("getResponse -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName());
    ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
    if (null == servletRequestAttributes) {
        return null;
    }
    return servletRequestAttributes.getResponse();
}
 
Example 6
Source File: CookieContext.java    From springboot-link-admin with Apache License 2.0 5 votes vote down vote up
public static void set(String key, String value, int expiry) {
	Cookie userCookie = new Cookie(key, value);

	userCookie.setMaxAge(30 * 24 * 60 * 60); // 存活期为一个月 30*24*60*60
	userCookie.setPath("/");
	ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
			.getRequestAttributes();
	HttpServletResponse response = requestAttributes.getResponse();
	response.addCookie(userCookie);
}
 
Example 7
Source File: CookieContext.java    From springboot-link-admin with Apache License 2.0 5 votes vote down vote up
public static void set(String key, String value) {
	Cookie userCookie = new Cookie(key, value);
	userCookie.setPath("/");
	ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
			.getRequestAttributes();
	HttpServletResponse response = requestAttributes.getResponse();
	response.addCookie(userCookie);
}
 
Example 8
Source File: RequestHolder.java    From mogu_blog_v2 with Apache License 2.0 5 votes vote down vote up
/**
 * 获取Response
 *
 * @return HttpServletRequest
 */
public static HttpServletResponse getResponse() {
    log.debug("getResponse -- Thread id :{}, name : {}", Thread.currentThread().getId(), Thread.currentThread().getName());
    ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
    if (null == servletRequestAttributes) {
        return null;
    }
    return servletRequestAttributes.getResponse();
}
 
Example 9
Source File: CookieUtils.java    From mogu_blog_v2 with Apache License 2.0 5 votes vote down vote up
/**
 * 设置Cookie的值,并使其在指定时间内生效
 *
 * @param cookieMaxage cookie生效的最大秒数
 */
private static final void doSetCookie(String cookieName, String cookieValue, int cookieMaxage, boolean isEncode) {
    ServletRequestAttributes attribute = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attribute.getRequest();
    HttpServletResponse response = attribute.getResponse();
    try {
        if (cookieValue == null) {
            cookieValue = "";
        } else if (isEncode) {
            cookieValue = URLEncoder.encode(cookieValue, "utf-8");
        }
        Cookie cookie = new Cookie(cookieName, cookieValue);
        if (cookieMaxage > 0) {
            cookie.setMaxAge(cookieMaxage);
        }
        if (null != request) {// 设置域名的cookie
            String domainName = getDomainName(request);
            System.out.println(domainName);
            if (!"localhost".equals(domainName)) {
                cookie.setDomain(domainName);
            }
        }
        cookie.setPath("/");
        response.addCookie(cookie);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: HttpUtils.java    From springboot-link-admin with Apache License 2.0 4 votes vote down vote up
public static HttpServletResponse getResponse() {
	ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
			.getRequestAttributes();
	return requestAttributes.getResponse();
}
 
Example 11
Source File: WebApplicationContextUtils.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public WebRequest getObject() {
	ServletRequestAttributes requestAttr = currentRequestAttributes();
	return new ServletWebRequest(requestAttr.getRequest(), requestAttr.getResponse());
}
 
Example 12
Source File: CookieUtil.java    From uccn with Apache License 2.0 4 votes vote down vote up
public static void saveCookie(Cookie cookie) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletResponse response = attributes.getResponse();
    response.addCookie(cookie);
}
 
Example 13
Source File: CookieUtils.java    From NetworkDisk_Storage with GNU General Public License v2.0 4 votes vote down vote up
public static void saveCookie(Cookie cookie) {
	ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
	HttpServletResponse response = attributes.getResponse();
	response.addCookie(cookie);
}
 
Example 14
Source File: HttpUtil.java    From demo-project with MIT License 4 votes vote down vote up
public static HttpServletResponse getResponse() {
    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    return requestAttributes.getResponse();
}
 
Example 15
Source File: WebApplicationContextUtils.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public WebRequest getObject() {
	ServletRequestAttributes requestAttr = currentRequestAttributes();
	return new ServletWebRequest(requestAttr.getRequest(), requestAttr.getResponse());
}
 
Example 16
Source File: WebApplicationContextUtils.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public WebRequest getObject() {
	ServletRequestAttributes requestAttr = currentRequestAttributes();
	return new ServletWebRequest(requestAttr.getRequest(), requestAttr.getResponse());
}
 
Example 17
Source File: RequestHolder.java    From spring-boot-cookbook with Apache License 2.0 4 votes vote down vote up
public static HttpServletResponse getResponseFacade() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
    return servletRequestAttributes.getResponse();
}
 
Example 18
Source File: WebApplicationContextUtils.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public WebRequest getObject() {
	ServletRequestAttributes requestAttr = currentRequestAttributes();
	return new ServletWebRequest(requestAttr.getRequest(), requestAttr.getResponse());
}