Example usage for javax.servlet.http HttpServletResponseWrapper addHeader

List of usage examples for javax.servlet.http HttpServletResponseWrapper addHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponseWrapper addHeader.

Prototype

@Override
public void addHeader(String name, String value) 

Source Link

Document

The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.

Usage

From source file:com.marklogic.samplestack.web.SessionController.java

/**
 * Exposes endpoint that returns CSRF token information and a session for use in login.
 * @param request The Http Request./*from  www . j  av a 2s .c  o m*/
 * @param response The Http response.
 * @return A JsonNode with bare-bones acknowledgement.
 */
@RequestMapping(value = "session", method = RequestMethod.GET)
public @ResponseBody JsonNode hello(HttpServletRequest request, HttpServletResponse response) {

    CsrfToken csrfToken = (CsrfToken) request.getAttribute("_csrf");

    String headerName = csrfToken.getHeaderName();
    String token = csrfToken.getToken();
    HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response);

    responseWrapper.addHeader(headerName, token);
    return errors.makeJsonResponse(200, "New Session");
}

From source file:org.craftercms.commons.web.CORSFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws ServletException, IOException {
    final HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response);
    responseWrapper.addHeader(ALLOW_ORIGIN, allowOrigins);
    responseWrapper.addHeader(ALLOW_METHODS, allowMethods);
    responseWrapper.addHeader(MAX_AGE, maxAge);
    responseWrapper.addHeader(ALLOW_HEADERS, allowHeaders);
    responseWrapper.addHeader(ALLOW_CREDENTIALS, allowCredentials);
    filterChain.doFilter(request, responseWrapper);
}

From source file:com.scooterframework.web.controller.ScooterRequestFilter.java

/**
 * Time the processing that is performed by all subsequent filters in the
 * current filter stack, including the ultimately invoked servlet.
 *
 * @param request The servlet request we are processing
 * @param chain The filter chain we are processing
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */// w  w  w  .  j  a v a 2s . c  o m
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    boolean staticContent = isStaticContentRequest((HttpServletRequest) request);

    if (encoding != null) {
        request.setCharacterEncoding(encoding);
        if (!staticContent) {
            response.setCharacterEncoding(encoding);
        }
    }

    // boolean skip = skippedRequestPath((HttpServletRequest)request);
    boolean skip = staticContent;

    long before = System.currentTimeMillis();

    if (!skip) {
        initializeActionContext((HttpServletRequest) request, (HttpServletResponse) response);
    } else {
        request.setAttribute(Constants.SKIP_PATH, "Y");
    }

    if (isAjaxRequest((HttpServletRequest) request)) {
        request.setAttribute(Constants.SITEMESH_FILTERAPPLIED, Boolean.TRUE);
    }

    String requestPathKeyWithQueryString = requestInfo(skip, (HttpServletRequest) request);
    log.debug("============>>\"" + requestPathKeyWithQueryString + "\"");

    try {
        chain.doFilter(request, response);
    } catch (Throwable ex) {
        log.error("Error from chain.doFilter: " + ex.getMessage(), ex);
    }

    long after = System.currentTimeMillis();

    if (EnvConfig.getInstance().allowRecordBenchmark()) {
        log.info("\"" + requestPathKeyWithQueryString + "\" takes: " + (after - before) + " ms");
        if (EnvConfig.getInstance().allowRecordBenchmarkInHeader()) {
            HttpServletResponseWrapper resw = new HttpServletResponseWrapper((HttpServletResponse) response);
            resw.addHeader("Exec-Time", (after - before) + " ms");
        }
    }

    clearCachedRequestData();
}

From source file:com.jsmartframework.web.manager.FilterControl.java

private void addAjaxHeaders(HttpServletRequest httpRequest, HttpServletResponseWrapper response) {
    // Case redirect via ajax, place tag with path to be handled by java script
    String ajaxPath = (String) httpRequest.getAttribute(REQUEST_REDIRECT_PATH_AJAX_ATTR);
    if (ajaxPath != null) {
        Boolean newWindow = (Boolean) httpRequest.getAttribute(REQUEST_REDIRECT_WINDOW_PATH_AJAX_ATTR);

        if (Boolean.TRUE.equals(newWindow)) {
            response.addHeader("New-Window-Ajax", ajaxPath);
        } else {//  www . ja va  2s.  c om
            response.addHeader("Redirect-Ajax", ajaxPath);
        }
    }

    // Case session reset, place tag to force java script reset the page
    HttpSession session = httpRequest.getSession();
    synchronized (session) {
        if (session.getAttribute(SESSION_RESET_ATTR) != null) {
            if (ajaxPath == null && WebContext.isAjaxRequest()) {
                response.addHeader("Reset-Ajax", "Session");
            }
            session.removeAttribute(SESSION_RESET_ATTR);
        }
    }
}