List of usage examples for javax.servlet.http HttpServletResponse addHeader
public void addHeader(String name, String value);
From source file:net.sf.ginp.GinpPictureServlet.java
/** * Handle missing picture handles the case where the image being linked * to does not exist. It returns the image "/img/nofile.jpg" and sets * the image to not cache so that if the image does appear later the * image will reload. If the image exists it returns the origional * image passed.//from ww w.j av a 2s . c o m * @param req servlet request * @param res servlet response * @param fl file * @return the file to use as the image source file */ private File handleMissingPicture(final HttpServletRequest req, final HttpServletResponse res, File fl) { if (!(fl.exists())) { log.info("File not found: " + fl.getAbsolutePath()); fl = new File(req.getSession().getServletContext().getRealPath("/img/nofile.jpg")); // DO NOT cache this picture. res.setHeader("Expires", "-1"); res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); res.addHeader("Cache-Control", "post-check=0, pre-check=0"); res.setHeader("Pragma", "no-cac`he"); } return fl; }
From source file:net.sf.jasperreports.web.servlets.ViewerServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html; charset=UTF-8"); // Set to expire far in the past. response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT"); // Set standard HTTP/1.1 no-cache headers. response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); // Set IE extended HTTP/1.1 no-cache headers (use addHeader). response.addHeader("Cache-Control", "post-check=0, pre-check=0"); // Set standard HTTP/1.0 no-cache header. response.setHeader("Pragma", "no-cache"); PrintWriter out = response.getWriter(); WebReportContext webReportContext = WebReportContext.getInstance(request); try {/*from w ww .j ava 2 s. c o m*/ render(request, webReportContext, out); } catch (Exception e) { log.error("Error on report execution", e); out.println("<html>");//FIXMEJIVE do we need to render this? or should this be done by the viewer? out.println("<head>"); out.println("<title>JasperReports - Web Application Sample</title>"); out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">"); out.println("</head>"); out.println("<body bgcolor=\"white\">"); out.println("<span class=\"bnew\">JasperReports encountered this error :</span>"); out.println("<pre>"); e.printStackTrace(out); out.println("</pre>"); out.println("</body>"); out.println("</html>"); } }
From source file:eu.comvantage.dataintegration.QueryDistributionServiceImpl.java
private void print(HttpResponse in, HttpServletResponse out) throws IOException { //writing binary response stream for (Header h : in.getAllHeaders()) { out.addHeader(h.getName(), h.getValue()); }//from www .j a va 2 s. co m out.setStatus(in.getStatusLine().getStatusCode()); out.setLocale(in.getLocale()); out.setContentType("text/html"); ServletOutputStream outstream = out.getOutputStream(); int c; while ((c = in.getEntity().getContent().read()) != -1) { outstream.write(c); } outstream.flush(); }
From source file:at.gv.egovernment.moa.id.auth.servlet.VerifyIdentityLinkServlet.java
/** * GET requested by security layer implementation to verify * that data URL resource is available.// ww w .j a v a 2s . c o m * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest, HttpServletResponse) */ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Logger.debug("GET VerifyIdentityLink"); resp.setHeader(MOAIDAuthConstants.HEADER_EXPIRES, MOAIDAuthConstants.HEADER_VALUE_EXPIRES); resp.setHeader(MOAIDAuthConstants.HEADER_PRAGMA, MOAIDAuthConstants.HEADER_VALUE_PRAGMA); resp.setHeader(MOAIDAuthConstants.HEADER_CACHE_CONTROL, MOAIDAuthConstants.HEADER_VALUE_CACHE_CONTROL); resp.addHeader(MOAIDAuthConstants.HEADER_CACHE_CONTROL, MOAIDAuthConstants.HEADER_VALUE_CACHE_CONTROL_IE); }
From source file:io.fabric8.maven.impl.MavenProxyServletSupportTest.java
@Test @Ignore("[https://jira.codehaus.org/browse/WAGON-416][FABRIC-171] Wait for wagon-http-lightweight fixes") public void testDownloadUsingAuthenticatedProxy() throws Exception { testDownload(new AbstractHandler() { @Override//www. jav a 2 s .c o m public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String proxyAuth = request.getHeader("Proxy-Authorization"); if (proxyAuth == null || proxyAuth.trim().equals("")) { response.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED); response.addHeader("Proxy-Authenticate", "Basic realm=\"Proxy Server\""); baseRequest.setHandled(true); } else { response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); response.getOutputStream().write(new byte[] { 0x42 }); response.getOutputStream().close(); } } }); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.base.FenixDispatchAction.java
protected void writeFile(final HttpServletResponse response, final String filename, final String contentType, final byte[] content) throws IOException { response.setContentLength(content.length); response.setContentType(contentType); response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); try (ServletOutputStream outputStream = response.getOutputStream()) { outputStream.write(content);/* ww w. j av a 2 s. c o m*/ outputStream.flush(); response.flushBuffer(); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.epfl.ExportPhdIndividualProgramProcessInformation.java
private void downloadCandidateDocuments(HttpServletRequest request, HttpServletResponse response) throws IOException { final String candidateOid = request.getParameter("candidateOid"); final PhdProgramPublicCandidacyHashCode code = FenixFramework.getDomainObject(candidateOid); final byte[] documents = ExportPhdIndividualProgramProcessesInHtml.createZip(code); final String email = code.getEmail().substring(0, code.getEmail().indexOf("@")); final String documentName = email + "-documents.zip"; response.addHeader("Content-Disposition", "attachment; filename=" + documentName); writeResponse(response, documents, "application/zip"); }
From source file:mx.edu.um.mateo.rh.web.JefeSeccionController.java
private void generaReporte(String tipo, List<JefeSeccion> jefeSeccions, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(jefeSeccions); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.pdf"); break;/*from w w w .j a v a 2s . c o m*/ case "CSV": archivo = generaCsv(jefeSeccions); response.setContentType("text/csv"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.csv"); break; case "XLS": archivo = generaXls(jefeSeccions); response.setContentType("application/vnd.ms-excel"); response.addHeader("Content-Disposition", "attachment; filename=clavesEmpleado.xls"); } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:com.jaspersoft.jasperserver.rest.utils.Utils.java
public void sendFile(DataSource ds, HttpServletResponse response) { response.setContentType(ds.getContentType()); if (ds.getName() != null && ds.getName().length() > 0) { response.addHeader("Content-Disposition", "attachment; filename=" + ds.getName()); }// w ww . j ava2 s .co m OutputStream outputStream = null; BufferedInputStream bufferedInputStream = null; try { outputStream = response.getOutputStream(); bufferedInputStream = new BufferedInputStream(ds.getInputStream()); int readBytes = 0; while ((readBytes = bufferedInputStream.read()) != -1) { outputStream.write(readBytes); } if (log.isDebugEnabled()) { log.debug("finished sending bytes"); } } catch (IOException ex) { log.error("Error serving a file: " + ex.getMessage(), ex); } finally { if (outputStream != null) try { outputStream.close(); } catch (Exception ex) { } if (bufferedInputStream != null) try { bufferedInputStream.close(); } catch (Exception ex) { } } }
From source file:mx.edu.um.mateo.rh.web.CategoriaController.java
private void generaReporte(String tipo, List<Categoria> categorias, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(categorias); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=Categorias.pdf"); break;//from w w w. j a va 2 s . co m case "CSV": archivo = generaCsv(categorias); response.setContentType("text/csv"); response.addHeader("Content-Disposition", "attachment; filename=Categorias.csv"); break; case "XLS": archivo = generaXls(categorias); response.setContentType("application/vnd.ms-excel"); response.addHeader("Content-Disposition", "attachment; filename=Categorias.xls"); } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }