List of usage examples for javax.servlet.http HttpServletResponse setDateHeader
public void setDateHeader(String name, long date);
From source file:com.impala.paga.all.QueryBanks.java
/** * //from w w w . j ava 2s . c o m * @param request * @param response * @throws ServletException * , IOException */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream out = response.getOutputStream(); response.setContentType("text/plain;charset=UTF-8"); response.setDateHeader("Expires", new Date().getTime()); // Expiration // date response.setDateHeader("Date", new Date().getTime()); // Date and time try { // that the // message was // sent out.write(moneytransfer(request).getBytes()); } catch (JSONException ex) { Logger.getLogger(QueryBanks.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(QueryBanks.class.getName()).log(Level.SEVERE, null, ex); } out.flush(); out.close(); }
From source file:com.impala.paga.all.QueryMobileOperators.java
/** * // ww w.j a v a2 s .c om * @param request * @param response * @throws ServletException * , IOException */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream out = response.getOutputStream(); response.setContentType("text/plain;charset=UTF-8"); response.setDateHeader("Expires", new Date().getTime()); // Expiration // date response.setDateHeader("Date", new Date().getTime()); // Date and time try { // that the // message was // sent out.write(moneytransfer(request).getBytes()); } catch (JSONException ex) { Logger.getLogger(QueryMobileOperators.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(QueryMobileOperators.class.getName()).log(Level.SEVERE, null, ex); } out.flush(); out.close(); }
From source file:org.openmrs.module.uiframework.ResourceServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("In service method for module servlet: " + request.getPathInfo()); File f = getFile(request);//from w ww .j a va 2s .com if (f == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } response.setDateHeader("Last-Modified", f.lastModified()); response.setContentLength(new Long(f.length()).intValue()); String mimeType = getServletContext().getMimeType(f.getName()); response.setContentType(mimeType); FileInputStream is = new FileInputStream(f); try { OpenmrsUtil.copyFile(is, response.getOutputStream()); } finally { OpenmrsUtil.closeStream(is); } }
From source file:org.openmrs.module.web.ModuleResourcesServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("In service method for module servlet: " + request.getPathInfo()); File f = getFile(request);/*from w w w .j av a 2s .com*/ if (f == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } response.setDateHeader("Last-Modified", f.lastModified()); response.setContentLength(Long.valueOf(f.length()).intValue()); String mimeType = getServletContext().getMimeType(f.getName()); response.setContentType(mimeType); FileInputStream is = new FileInputStream(f); try { OpenmrsUtil.copyFile(is, response.getOutputStream()); } finally { OpenmrsUtil.closeStream(is); } }
From source file:be.fedict.eid.applet.service.PhotoServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug("doGet"); response.setContentType("image/jpg"); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1 response.setHeader("Pragma", "no-cache, no-store"); // http 1.0 response.setDateHeader("Expires", -1); ServletOutputStream out = response.getOutputStream(); HttpSession session = request.getSession(); byte[] photoData = (byte[]) session.getAttribute(IdentityDataMessageHandler.PHOTO_SESSION_ATTRIBUTE); if (null != photoData) { BufferedImage photo = ImageIO.read(new ByteArrayInputStream(photoData)); if (null == photo) { /*/*from www. j a va 2 s .c om*/ * In this case we render a photo containing some error message. */ photo = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) photo.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setColor(Color.RED); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.drawString("Photo Error", 0, 200 / 2); graphics.dispose(); ImageIO.write(photo, "jpg", out); } else { out.write(photoData); } } out.close(); }
From source file:org.sigmah.server.servlet.filter.CacheFilter.java
/** * {@inheritDoc}//from ww w .java2 s. c o m */ @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain filterChain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) { // Just in case. filterChain.doFilter(request, response); return; } final HttpServletRequest httpRequest = (HttpServletRequest) request; final HttpServletResponse httpResponse = (HttpServletResponse) response; final String requestURI = httpRequest.getRequestURI(); if (containsAny(requestURI, CACHE_FILTERS)) { // Cached resource. httpResponse.setDateHeader("Expires", new Date().getTime() + YEAR); // Control flag. httpResponse.setHeader(CUSTOM_HEADER_NAME, "Resource cached by Sigmah filter."); } else if (containsAny(requestURI, NO_CACHE_FILTERS)) { // Never cached resource. httpResponse.setDateHeader("Expires", 0); httpResponse.setHeader("Cache-Control", "no-cache, public, max-age=0, must-revalidate"); // Set IE extended HTTP/1.1 no-cache headers (use addHeader). httpResponse.addHeader("Cache-Control", "post-check=0, pre-check=0"); // Set standard HTTP/1.0 no-cache header. httpResponse.setHeader("Pragma", "no-cache"); // Control flag. httpResponse.setHeader(CUSTOM_HEADER_NAME, "Resource NOT cached by Sigmah filter."); } // Define content-type for JSON files. if (requestURI.contains(".json")) { httpResponse.setContentType("application/json"); } filterChain.doFilter(request, response); }
From source file:com.google.reducisaurus.servlets.BaseServlet.java
private void maybeSetHttpCacheHeaders(HttpServletRequest req, HttpServletResponse resp) { long cachePolicy = getCachingPolicy(req, MAX_AGE_PARAM, DISABLE_MAX_AGE, DEFAULT_MAX_AGE_PARAM); if (cachePolicy != DISABLE_MAX_AGE) { resp.setDateHeader("Expires", new Date().getTime() + cachePolicy * 1000); resp.setHeader("Cache-Control", "max-age=" + cachePolicy); }//from www .j av a 2 s.c om }
From source file:com.gitblit.servlet.PtServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {// w w w . ja v a 2 s. c o m response.setContentType("application/octet-stream"); response.setDateHeader("Last-Modified", lastModified); response.setHeader("Cache-Control", "none"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); boolean windows = false; try { String useragent = request.getHeader("user-agent").toString(); windows = useragent.toLowerCase().contains("windows"); } catch (Exception e) { } byte[] pyBytes; File file = runtimeManager.getFileOrFolder("tickets.pt", "${baseFolder}/pt.py"); if (file.exists()) { // custom script pyBytes = readAll(new FileInputStream(file)); } else { // default script pyBytes = readAll(getClass().getResourceAsStream("/pt.py")); } if (windows) { // windows: download zip file with pt.py and pt.cmd response.setHeader("Content-Disposition", "attachment; filename=\"pt.zip\""); OutputStream os = response.getOutputStream(); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os); // add the Python script ZipArchiveEntry pyEntry = new ZipArchiveEntry("pt.py"); pyEntry.setSize(pyBytes.length); pyEntry.setUnixMode(FileMode.EXECUTABLE_FILE.getBits()); pyEntry.setTime(lastModified); zos.putArchiveEntry(pyEntry); zos.write(pyBytes); zos.closeArchiveEntry(); // add a Python launch cmd file byte[] cmdBytes = readAll(getClass().getResourceAsStream("/pt.cmd")); ZipArchiveEntry cmdEntry = new ZipArchiveEntry("pt.cmd"); cmdEntry.setSize(cmdBytes.length); cmdEntry.setUnixMode(FileMode.REGULAR_FILE.getBits()); cmdEntry.setTime(lastModified); zos.putArchiveEntry(cmdEntry); zos.write(cmdBytes); zos.closeArchiveEntry(); // add a brief readme byte[] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt")); ZipArchiveEntry txtEntry = new ZipArchiveEntry("readme.txt"); txtEntry.setSize(txtBytes.length); txtEntry.setUnixMode(FileMode.REGULAR_FILE.getBits()); txtEntry.setTime(lastModified); zos.putArchiveEntry(txtEntry); zos.write(txtBytes); zos.closeArchiveEntry(); // cleanup zos.finish(); zos.close(); os.flush(); } else { // unix: download a tar.gz file with pt.py set with execute permissions response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\""); OutputStream os = response.getOutputStream(); CompressorOutputStream cos = new CompressorStreamFactory() .createCompressorOutputStream(CompressorStreamFactory.GZIP, os); TarArchiveOutputStream tos = new TarArchiveOutputStream(cos); tos.setAddPaxHeadersForNonAsciiNames(true); tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); // add the Python script TarArchiveEntry pyEntry = new TarArchiveEntry("pt"); pyEntry.setMode(FileMode.EXECUTABLE_FILE.getBits()); pyEntry.setModTime(lastModified); pyEntry.setSize(pyBytes.length); tos.putArchiveEntry(pyEntry); tos.write(pyBytes); tos.closeArchiveEntry(); // add a brief readme byte[] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt")); TarArchiveEntry txtEntry = new TarArchiveEntry("README"); txtEntry.setMode(FileMode.REGULAR_FILE.getBits()); txtEntry.setModTime(lastModified); txtEntry.setSize(txtBytes.length); tos.putArchiveEntry(txtEntry); tos.write(txtBytes); tos.closeArchiveEntry(); // cleanup tos.finish(); tos.close(); cos.close(); os.flush(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.rhq.enterprise.gui.client.RemoteClientServlet.java
private void getVersion(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {/*from www. jav a 2 s. co m*/ File versionFile = getVersionFile(); resp.setContentType("text/plain"); resp.setDateHeader("Last-Modified", versionFile.lastModified()); FileInputStream stream = new FileInputStream(versionFile); byte[] versionData = StreamUtil.slurp(stream); resp.getOutputStream().write(versionData); } catch (Throwable t) { log.error("Failed to stream version info.", t); disableBrowserCache(resp); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to stream version info"); } return; }
From source file:fr.littlereddot.pocket.site.controller.account.ConnectAccountController.java
private void setNoCache(NativeWebRequest request) { HttpServletResponse response = request.getNativeResponse(HttpServletResponse.class); if (response != null) { response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 1L); response.setHeader("Cache-Control", "no-cache"); response.addHeader("Cache-Control", "no-store"); }// ww w . j av a2s .co m }