Example usage for org.springframework.web.util WebUtils getNativeResponse

List of usage examples for org.springframework.web.util WebUtils getNativeResponse

Introduction

In this page you can find the example usage for org.springframework.web.util WebUtils getNativeResponse.

Prototype

@SuppressWarnings("unchecked")
@Nullable
public static <T> T getNativeResponse(ServletResponse response, @Nullable Class<T> requiredType) 

Source Link

Document

Return an appropriate response object of the specified type, if available, unwrapping the given response as far as necessary.

Usage

From source file:org.springframework.security.web.context.HttpSessionSecurityContextRepository.java

public void saveContext(SecurityContext context, HttpServletRequest request, HttpServletResponse response) {
    SaveContextOnUpdateOrErrorResponseWrapper responseWrapper = WebUtils.getNativeResponse(response,
            SaveContextOnUpdateOrErrorResponseWrapper.class);
    if (responseWrapper == null) {
        throw new IllegalStateException("Cannot invoke saveContext on response " + response
                + ". You must use the HttpRequestResponseHolder.response after invoking loadContext");
    }/*from  w ww . ja v a2 s  . c  o  m*/
    // saveContext() might already be called by the response wrapper
    // if something in the chain called sendError() or sendRedirect(). This ensures we
    // only call it
    // once per request.
    if (!responseWrapper.isContextSaved()) {
        responseWrapper.saveContext(context);
    }
}