Example usage for javax.servlet.http HttpServletResponse setHeader

List of usage examples for javax.servlet.http HttpServletResponse setHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setHeader.

Prototype

public void setHeader(String name, String value);

Source Link

Document

Sets a response header with the given name and value.

Usage

From source file:com.vmware.identity.SharedUtils.java

/**
 * Build mock HttpServletResponse object with a StringWriter
 *  which receives actual response/* w  ww  .  j a  va  2 s  .  co m*/
 * @param sw
 * @param contentType
 * @param expectCookie
 * @return
 * @throws IOException
 */
public static HttpServletResponse buildMockResponseSuccessObject(StringWriter sw, String contentType,
        boolean expectCookie, String contentDispositionValue) throws IOException {
    HttpServletResponse response = createMock(HttpServletResponse.class);
    if (expectCookie) {
        response.addCookie(isA(Cookie.class));
    }
    response.setContentType(contentType);
    if (contentDispositionValue != null && !contentDispositionValue.isEmpty()) {
        response.setHeader("Content-Disposition", contentDispositionValue);
    }
    expect(response.getWriter()).andReturn(new PrintWriter(sw)).anyTimes();
    replay(response);
    return response;
}

From source file:com.lily.dap.web.util.WebUtils.java

/**
 *  If-None-Match Header,Etag./*  www  . ja v a  2 s. c o m*/
 * 
 * Etag,checkIfNoneMatchfalse, 304 not modify status.
 */
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {
    String headerValue = request.getHeader("If-None-Match");
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!headerValue.equals("*")) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader("ETag", etag);
            return false;
        }
    }
    return true;
}

From source file:com.dosport.system.utils.ServletUtils.java

/**
 * ?? If-None-Match Header, Etag?./*from  w  ww.ja  v a2 s .  com*/
 * 
 * Etag, checkIfNoneMatchfalse, 304 not modify status.
 * 
 * @param etag
 *            ETag.
 */
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {
    String headerValue = request.getHeader("If-None-Match");
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!"*".equals(headerValue)) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader("ETag", etag);
            return false;
        }
    }
    return true;
}

From source file:com.handpay.ibenefit.framework.util.WebUtils.java

public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {//from  ww  w  .  ja  v  a2 s .c  o m
    String headerValue = request.getHeader("If-None-Match");
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!"*".equals(headerValue)) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader("ETag", etag);
            return false;
        }
    }
    return true;
}

From source file:com.stormpath.spring.boot.examples.AngularController.java

@RequestMapping(path = { "/login", "/register", "/forgot" }, method = GET, headers = "Accept=text/html")
public String angular(HttpServletResponse res) {
    res.setHeader("Cache-Control", "no-store, no-cache");
    res.setHeader("Pragma", "no-cache");

    return "forward:/";
}

From source file:org.jhk.pulsing.web.controller.AbstractController.java

/**
 * Set cors header since nodejs and server will communicate on different ports
 * /*from w  w  w  .ja v a 2s  . c o  m*/
 * @param response
 */
@ModelAttribute
public void setCorsHeader(HttpServletResponse response) {
    response.setHeader("Access-Control-Allow-Origin", "*");
}

From source file:org.terasoluna.gfw.functionaltest.app.download.ImageFileDownloadView.java

@Override
protected void addResponseHeader(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {
    response.setHeader("Content-Disposition", "attachment; filename=Duke.png");
    response.setContentType("image/png");
}

From source file:org.terasoluna.gfw.functionaltest.app.download.TextFileDownloadView.java

@Override
protected void addResponseHeader(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {
    response.setHeader("Content-Disposition", "attachment; filename=framework.txt");
    response.setContentType("text/plain");
}

From source file:cn.com.qiqi.order.utils.Servlets.java

/**
 * ?? If-None-Match Header, Etag?.//from   w w  w  .ja v a  2  s.  c o m
 * 
 * Etag, checkIfNoneMatchfalse, 304 not modify status.
 * 
 * @param etag ETag.
 */
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {
    String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH);
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!"*".equals(headerValue)) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader(HttpHeaders.ETAG, etag);
            return false;
        }
    }
    return true;
}

From source file:tomekkup.helenos.web.servlet.view.CsvView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    response.setHeader("Content-Disposition",
            "attachment; filename=\"" + (String) model.get("key") + "_" + (String) model.get("key") + ".csv\"");
    BufferedWriter writer = new BufferedWriter(response.getWriter());

    //myDbData = (Whatever) modelMap.get("modelKey");
    //some kind of loop {writer.write(myDbData csv row); writer.newLine(); }
    writer.flush();/*from ww w.  j a  v  a2 s.c  o m*/
    writer.close();
}