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:org.codehaus.groovy.grails.plugins.springsecurity.GrailsNtlmProcessingFilterEntryPoint.java

/**
 * {@inheritDoc}/*  w  ww .ja  v  a  2  s .  c  om*/
 * @see org.springframework.security.ui.ntlm.NtlmProcessingFilterEntryPoint#commence(
 *    javax.servlet.ServletRequest, javax.servlet.ServletResponse,
 *    org.springframework.security.AuthenticationException)
 */
@Override
public void commence(final ServletRequest req, final ServletResponse res,
        final AuthenticationException authException) throws IOException, ServletException {

    // start authentication, if necessary and forceIdentification in NtlmProcessingFilter is false
    if (!(authException instanceof NtlmBaseException || authException instanceof BadCredentialsException)) {

        HttpServletRequest request = (HttpServletRequest) req;
        request.getSession().setAttribute(STATE_ATTR, BEGIN);

        HttpServletResponse response = (HttpServletResponse) res;

        response.setHeader("WWW-Authenticate", new NtlmBeginHandshakeException().getMessage());
        response.setHeader("Connection", "Keep-Alive");
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.setContentLength(0);
        response.flushBuffer();
    } else {
        super.commence(req, res, authException);
    }
}

From source file:com.sunchenbin.store.feilong.servlet.http.ResponseUtil.java

/**
 * ??./* w w  w . j  av a2s. co m*/
 *
 * @param response
 *            HttpServletResponse
 */
public static void setNoCacheHeader(HttpServletResponse response) {
    // HTTP1.1? CacheControl = no-cache??
    // ? HTTP1.0 ?? Cache-Control 

    // ?? HTTP1.0 ?IEPragma:no-cache  HTTP???
    //  (https://)/??? Pragma:no-cache  Internet Explorer??
    // ?Pragma:no-cache ???? Expires:-1??
    response.setHeader(HttpHeaders.PRAGMA, "No-cache");

    // Cache-controlno-cache???Internet?
    response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache");

    //In other wordsExpires: 0not always leads to immediate resource expiration, 
    //therefore should be avoided andExpires: -1orExpires: [some valid date in the past]should be used instead.
    response.setDateHeader(HttpHeaders.EXPIRES, -1);
}

From source file:com.hypersocket.ui.RedirectHandler.java

@Override
public void handleHttpRequest(HttpServletRequest request, HttpServletResponse response,
        HttpResponseProcessor responseProcessor) throws IOException {

    response.setHeader(HttpHeaders.LOCATION, server.resolvePath(server.getUserInterfacePath()));
    response.sendError(HttpStatus.SC_MOVED_TEMPORARILY);
    responseProcessor.sendResponse(request, response, false);

}

From source file:com.twinsoft.convertigo.engine.enums.HeaderName.java

public void setHeader(HttpServletResponse response, String headerValue) {
    response.setHeader(value, headerValue);
}

From source file:de.knurt.fam.template.controller.json.JSONController.java

/**
 * print out json with the key and values got from
 * {@link JSONController#getKeyAndValues(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}
 * /*from   www. j  a v a  2 s.  co  m*/
 * @param rq
 *            request
 * @param rs
 *            response
 * @return null
 */
@Override
public ModelAndView handleRequest(HttpServletRequest rq, HttpServletResponse rs) {
    PrintWriter pw = null;
    try {
        rs.setHeader("Content-type", "application/json");
        pw = rs.getWriter();
        IOUtils.write(this.getJSONObject(rq, rs).toString(), pw);
    } catch (IOException ex) {
        this.onException(ex);
    } finally {
        IOUtils.closeQuietly(pw);
    }
    return null;
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    res.setHeader("Refresh", "10");
    out.println(new Date().toString());
}

From source file:org.opi.web.view.AbstractXslFoView.java

/**
 * Perform the actual transformation, writing to the HTTP response via the
 * FOP Driver./*from ww w .j a v a2 s.  c  o  m*/
 */
protected void doTransform(Map model, Source source, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    response.setHeader("Content-Disposition", "inline");
    response.setContentType("application/pdf");

    FopFactory fopFactory = FopFactory.newInstance();

    if (log.isInfoEnabled()) {
        log.info("ContextPath = " + request.getSession().getServletContext().getRealPath("/"));
    }

    OutputStream os = response.getOutputStream();

    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, os);

    Result intermediateFile = new SAXResult(fop.getDefaultHandler());

    // Delegate to the superclass for the actual output having constructed the result.
    super.doTransform(source, getParameters(request), intermediateFile, response.getCharacterEncoding());

    log.info("success");
}

From source file:org.vbossica.springbox.metrics.ThreadDumpController.java

@RequestMapping(value = "/metrics/threaddump", method = RequestMethod.GET)
protected void doGet(HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");
    resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
    resp.setStatus(HttpServletResponse.SC_OK);
    OutputStream output = resp.getOutputStream();
    try {// w w  w  . ja  va2s . com
        threadDump.dump(output);
    } finally {
        output.close();
    }
}

From source file:com.dangdang.ddframe.job.console.security.WwwAuthFilter.java

private void authenticateSuccess(final HttpServletResponse response) {
    response.setStatus(200);//  w w  w.jav a2s .co m
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
}

From source file:com.dangdang.ddframe.job.console.security.WwwAuthFilter.java

private void needAuthenticate(final HttpServletRequest request, final HttpServletResponse response) {
    response.setStatus(401);//w w  w .java2  s. com
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    response.setHeader("WWW-authenticate", AUTH_PREFIX + "Realm=\"Elastic Job Console Auth\"");
}