List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:nl.edia.sakai.tool.skinmanager.download.SkinDownloadView.java
@SuppressWarnings("unchecked") public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { String myName = (String) model.get("id"); Number myVersion = (Number) model.get("version"); setHeaders(response, myName);//from ww w . j a v a 2s .co m ServletOutputStream myOutputStream = response.getOutputStream(); if (myVersion != null) { skinArchiveService.fetchSkinArchiveData(myName, myVersion.intValue(), myOutputStream); } else { skinArchiveService.fetchSkinArchiveData(myName, myOutputStream); } }
From source file:com.aurel.track.exchange.docx.exporter.DocxTemplateBL.java
/** * Download the template file// w ww .j a v a 2 s. c o m * @param iconBytes * @param request * @param response * @param fileName * @param inline */ public static void download(String fileName, HttpServletRequest request, HttpServletResponse response, boolean inline) { String dir = ""; File file = null; if (fileName.endsWith(".docx")) { dir = getWordTemplatesDir(); file = new File(dir + File.separator + fileName); DownloadUtil.prepareResponse(request, response, fileName, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", Long.toString(file.length()), inline); } if (fileName.endsWith(".tlx") || fileName.endsWith(".zip")) { dir = getLatexTemplatesDir(); DownloadUtil.prepareResponse(request, response, fileName, "application/zip"); file = new File(dir + File.separator + fileName); } InputStream inputStream = null; OutputStream outputStream = null; try { // retrieve the file data inputStream = new FileInputStream(file); outputStream = response.getOutputStream(); byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead = 0; while ((bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE)) != -1) { outputStream.write(buffer, 0, bytesRead); } } catch (FileNotFoundException fnfe) { LOGGER.error("FileNotFoundException thrown " + fnfe.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.error(ExceptionUtils.getStackTrace(fnfe)); } return; } catch (Exception ioe) { LOGGER.error("Creating the input stream failed with " + ioe.getMessage(), ioe); LOGGER.debug(ExceptionUtils.getStackTrace(ioe)); return; } finally { // flush and close the streams if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } if (outputStream != null) { try { outputStream.flush(); outputStream.close(); } catch (IOException e) { } } } }
From source file:eu.earthobservatory.org.StrabonEndpoint.DescribeBean.java
/** * Processes the request made by a client of the endpoint that uses it as a service. * /* ww w . ja va2 s . co m*/ * @param request * @param response * @throws IOException */ private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { ServletOutputStream out = response.getOutputStream(); // get the RDF format (we check only the Accept header) RDFFormat format = RDFFormat.forMIMEType(request.getHeader("accept")); // get the query String query = request.getParameter("query"); // check for required parameters if (format == null || query == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.print(ResponseMessages.getXMLHeader()); out.print(ResponseMessages.getXMLException(PARAM_ERROR)); out.print(ResponseMessages.getXMLFooter()); } else { // decode the query query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); response.setContentType(format.getDefaultMIMEType()); response.setHeader("Content-Disposition", "attachment; filename=describe." + format.getDefaultFileExtension() + "; " + format.getCharset()); try { strabonWrapper.describe(query, format.getName(), out); response.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.print(ResponseMessages.getXMLHeader()); out.print(ResponseMessages.getXMLException(e.getMessage())); out.print(ResponseMessages.getXMLFooter()); } } out.flush(); }
From source file:UpdateMySqlClobServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Connection conn = null;// w w w . j a v a 2 s . c o m String id = "001"; String fileAsURL = "http://yourwebsite/fileName.dat"; ServletOutputStream out = response.getOutputStream(); response.setContentType("text/html"); out.println("<html><head><title>UpdateMySqlClobServlet</title></head>"); try { conn = getConnection(); String fileContent = getClobsContentAsString(fileAsURL); updateCLOB(conn, id, fileContent); out.println("<body><h4>OK: updated an existing record with id=" + id + "</h4></body></html>"); } catch (Exception e) { e.printStackTrace(); out.println("<body><h4>Error: " + e.getMessage() + "</h4></body></html>"); } }
From source file:ar.com.zauber.commons.facebook.utils.filters.FacebookOnlyFilter.java
/** @see OncePerRequestFilter#doFilterInternal(HttpServletRequest, * HttpServletResponse, FilterChain) */ @Override/*from w ww.j a va2 s . co m*/ protected final void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws ServletException, IOException { if (validator.validate(request)) { if (needsLogin && request.getParameter("fb_sig_user") == null) { response.getOutputStream().print("<fb:redirect url='" + "http://www.facebook.com/apps/application.php?api_key=" + apiKey + "' />"); } else { chain.doFilter(request, response); } } else { response.sendError(403, "requests doesn't seem to come from a facebook server"); } }
From source file:com.qcadoo.mes.workPlans.controller.WorkPlansController.java
private void printPdfFile(final Entity attachment, HttpServletResponse response) { InputStream is = fileService/*from w w w .j a va 2 s .c om*/ .getInputStream(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT)); try { IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (IOException e) { LOG.error("Problem with printing document - " + e.getMessage()); e.printStackTrace(); } }
From source file:org.openxdata.server.servlet.FormDownloadServlet.java
private void downloadStudies(HttpServletRequest request, HttpServletResponse response) throws IOException { formDownloadService.downloadStudies(response.getOutputStream(), request.getParameter(OpenXDataConstants.REQUEST_PARAM_STUDY_SERIALIZER), request.getParameter(OpenXDataConstants.REQUEST_PARAM_LOCALE)); }
From source file:org.psystems.dicom.browser.server.stat.UseagStoreChartServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); JFreeChart chart = getChart();//ww w .ja v a 2 s .c o m int width = 800; int height = 400; ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); }
From source file:com.zuoxiaolong.niubi.job.test.http.DownloadFileController.java
@RequestMapping("/download/test.jar") public void downloadJar(HttpServletResponse response) throws IOException { String fileName = "test.jar"; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); OutputStream outputStream = response.getOutputStream(); outputStream.write("hello".getBytes()); outputStream.flush();// ww w .j a va 2s. c o m outputStream.close(); }
From source file:com.fishcart.delivery.service.OrderInformer.java
@RequestMapping(value = "/orderhistory", method = { RequestMethod.POST, RequestMethod.GET }, produces = { "application/text" }) public void getOrderHistory(@RequestParam(value = "date") String date, HttpServletResponse response) throws IOException { String data = generator.getOrderHistory(date); response.setHeader("Content-Disposition", "attachment; filename=report.csv"); IOUtils.copy(IOUtils.toInputStream(data, "UTF-8"), response.getOutputStream()); response.flushBuffer();/*from w w w . j a v a 2s .com*/ }