Example usage for javax.servlet.http HttpServletResponse setDateHeader

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

Introduction

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

Prototype

public void setDateHeader(String name, long date);

Source Link

Document

Sets a response header with the given name and date-value.

Usage

From source file:it.jugpadova.controllers.ServiceController.java

@RequestMapping
public ModelAndView kml(HttpServletRequest req, HttpServletResponse res) throws Exception {
    logger.info("Requested kml from " + req.getRemoteAddr());
    Document doc = jugBo.buildKml();
    res.setHeader("Cache-Control", "no-store");
    res.setHeader("Pragma", "no-cache");
    res.setDateHeader("Expires", 0);
    res.setContentType("text/xml");
    ServletOutputStream resOutputStream = res.getOutputStream();
    Serializer serializer = new Serializer(resOutputStream);
    serializer.setIndent(4);/*ww w.  j a  v  a  2s .  co  m*/
    serializer.setMaxLength(64);
    serializer.setLineSeparator("\n");
    serializer.write(doc);
    resOutputStream.flush();
    resOutputStream.close();
    return null;
}

From source file:org.openmrs.module.pmtct.web.view.chart.AbstractChartView.java

/**
 * @see org.springframework.web.servlet.view.AbstractView
 *///ww  w  .ja  v a  2 s.  c o m
@Override
@SuppressWarnings("unchecked")
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Respond as a PNG image
    response.setContentType("image/png");

    // Disable caching
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache");

    int width = 400;
    int height = 300;

    JFreeChart chart = createChart(model, request);
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setOutlineStroke(new BasicStroke(0));
    chart.getPlot().setOutlinePaint(getBackgroundColor());
    chart.getPlot().setBackgroundPaint(getBackgroundColor());
    chart.getPlot().setNoDataMessage("No data available");

    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}

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

private void authenticateSuccess(final HttpServletResponse response, final boolean isGuest) {
    response.setStatus(200);//from   w w  w  . j  av a  2 s.c  o  m
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    response.setHeader("identify", isGuest ? GUEST_IDENTIFY : ROOT_IDENTIFY);
}

From source file:nl.strohalm.cyclos.controls.customization.documents.ViewDocumentAction.java

@Override
protected ActionForward executeAction(final ActionContext context) throws Exception {
    final PreviewDocumentForm form = context.getForm();
    final long documentId = form.getDocumentId();
    if (documentId < 1) {
        throw new ValidationException();
    }/*from ww  w.  j  a  v  a  2 s.  c  o m*/
    final StaticDocument document = (StaticDocument) documentService.load(documentId,
            StaticDocument.Relationships.BINARY_FILE);
    final BinaryFile binaryFile = document.getBinaryFile();
    final HttpServletResponse response = context.getResponse();
    responseHelper.setDownload(response, binaryFile.getName());
    response.setContentType(binaryFile.getContentType());
    response.setContentLength(binaryFile.getSize());
    response.setDateHeader("Last-Modified", binaryFile.getLastModified().getTimeInMillis());
    IOUtils.copy(binaryFile.getContents().getBinaryStream(), response.getOutputStream());
    response.flushBuffer();
    return null;
}

From source file:org.openmrs.module.tracpatienttransfer.web.view.chart.AbstractChartView.java

/**
 * @see org.springframework.web.servlet.view.AbstractView
 *//*from   w w  w.j a v  a  2  s  .  c o m*/
@Override
@SuppressWarnings("unchecked")
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Respond as a PNG image
    response.setContentType("image/png");

    // Disable caching
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache");

    int width = Integer.valueOf(request.getParameter("width"));
    int height = Integer.valueOf(request.getParameter("height"));
    ;

    JFreeChart chart = createChart(model, request);
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setOutlineStroke(new BasicStroke(0));
    chart.getPlot().setOutlinePaint(getBackgroundColor());
    chart.getPlot().setBackgroundPaint(getBackgroundColor());
    chart.getPlot().setNoDataMessage(
            TransferOutInPatientUtil.getMessage("tracpatienttransfer.error.noDataAvailable", null));

    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}

From source file:com.aistor.common.servlet.ValidateCodeServlet.java

private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    /*//from ww w  .ja v  a  2s.  c o m
     * ??
     */
    String width = request.getParameter("width");
    String height = request.getParameter("height");
    if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
        w = NumberUtils.toInt(width);
        h = NumberUtils.toInt(height);
    }

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();

    /*
     * ?
     */
    createBackground(g);

    /*
     * ?
     */
    String s = createCharacter(g);
    request.getSession().setAttribute("validateCode", s);

    g.dispose();
    OutputStream out = response.getOutputStream();
    ImageIO.write(image, "JPEG", out);
    out.close();

}

From source file:org.openmrs.module.vcttrac.web.view.chart.AbstractChartView.java

/**
 * @see org.springframework.web.servlet.view.AbstractView
 *///from   w  w w .  ja  v a 2s.c om
@Override
@SuppressWarnings("unchecked")
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Respond as a PNG image
    response.setContentType("image/png");

    // Disable caching
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache");

    int width = (request.getParameter("width") != null && request.getParameter("width").compareTo("") != 0)
            ? (Integer.valueOf(request.getParameter("width")))
            : 450;
    int height = (request.getParameter("height") != null && request.getParameter("height").compareTo("") != 0)
            ? (Integer.valueOf(request.getParameter("height")))
            : 350;

    JFreeChart chart = createChart(model, request);
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setOutlineStroke(new BasicStroke(0));
    chart.getPlot().setOutlinePaint(getBackgroundColor());
    chart.getPlot().setBackgroundPaint(getBackgroundColor());

    chart.getPlot().setNoDataMessage(VCTTracUtil.getMessage("vcttrac.error.noDataAvailable", null));

    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height);
}

From source file:com.eryansky.common.web.servlet.ValidateCodeServlet.java

private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    /*// ww  w. j a  v a2  s . co m
     * ??
     */
    String width = request.getParameter("width");
    String height = request.getParameter("height");
    if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
        w = NumberUtils.toInt(width);
        h = NumberUtils.toInt(height);
    }

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();

    /*
     * ?
     */
    createBackground(g);

    /*
     * ?
     */
    String s = createCharacter(g);
    request.getSession().setAttribute(SysConstants.SESSION_VALIDATE_CODE, s);

    g.dispose();
    OutputStream out = response.getOutputStream();
    ImageIO.write(image, "JPEG", out);
    out.close();

}

From source file:apm.common.servlet.ValidateCodeServlet.java

private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    /*//from  w  ww  .  ja v  a  2  s  . c  om
     * ??
     */
    String width = request.getParameter("width");
    String height = request.getParameter("height");
    if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
        w = NumberUtils.toInt(width);
        h = NumberUtils.toInt(height);
    }

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();

    /*
     * ?
     */
    createBackground(g);

    /*
     * ?
     */
    String s = createCharacter(g);
    request.getSession().setAttribute(VALIDATE_CODE, s);

    g.dispose();
    OutputStream out = response.getOutputStream();
    ImageIO.write(image, "JPEG", out);
    out.close();

}

From source file:org.openmrs.module.logmanager.web.view.AutocompleteView.java

@SuppressWarnings("rawtypes")
@Override// ww w.j a  va 2  s .com
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    PrintWriter writer = response.getWriter();
    Object source = model.get(sourceKey);

    // Disable caching
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache");
    response.setContentType("application/json");

    writer.write("[");

    if (source != null) {
        if (source instanceof Collection) {
            Collection<?> collection = (Collection<?>) source;
            Object[] items = collection.toArray();
            for (int i = 0; i < items.length; i++) {
                Object item = items[i];
                String label = (item instanceof LoggerProxy) ? ((LoggerProxy) item).getName() : item.toString();

                if (i > 0)
                    writer.write(',');

                writer.write("{\"label\":\"" + label + "\", \"value\":\"" + label + "\"}");
            }
        }
    } else
        writer.write("\"ERROR: Source object is null\"");

    writer.write("]");
}