List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:com.haulmont.restapi.controllers.FileDownloadController.java
protected void downloadFromMiddlewareAndWriteResponse(FileDescriptor fd, HttpServletResponse response) throws IOException { ServletOutputStream os = response.getOutputStream(); try (InputStream is = fileLoader.openStream(fd)) { IOUtils.copy(is, os);//from ww w . j av a2 s . co m os.flush(); } catch (FileStorageException e) { throw new RestAPIException("Unable to download file from FileStorage", "Unable to download file from FileStorage: " + fd.getId(), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:eionet.cr.web.action.ExportTriplesActionBean.java
@DefaultHandler public Resolution defaultHandler() { if (StringUtils.isBlank(uri)) { if (Util.isWebBrowser(getContext().getRequest())) { getContext().getRequest().setAttribute(StripesExceptionHandler.EXCEPTION_ATTR, new CRException("Graph URI not specified in the request!")); return new ForwardResolution(StripesExceptionHandler.ERROR_PAGE); } else {/*from w w w .j av a2s. c o m*/ return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND); } } return (new StreamingResolution("application/rdf+xml") { public void stream(HttpServletResponse response) throws Exception { RDFGenerator.generate(uri, response.getOutputStream()); } }); }
From source file:com.crunchify.jsp.servlet.BarServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); JFreeChart chart = getChart();/* ww w .j av a2 s. c om*/ int width = 500; int height = 350; ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); }
From source file:Hello.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String acceptLanguage = req.getHeader("Accept-Language"); String acceptCharset = req.getHeader("Accept-Charset"); res.getOutputStream().println("acceptLanguage: " + acceptLanguage); res.getOutputStream().println("acceptCharset" + acceptCharset); }
From source file:com.aurel.track.exchange.latex.exporter.LaTeXExportBL.java
/** * Serializes the docx content into the response's output stream * @param response//from w w w . ja va 2 s . c om * @param wordMLPackage * @return */ public static String prepareReportResponse(HttpServletResponse response, TWorkItemBean workItem, ReportBeans reportBeans, TPersonBean user, Locale locale, String templateDir, String templateFile) { ReportBeansToLaTeXConverter rl = new ReportBeansToLaTeXConverter(); File pdf = rl.generatePdf(workItem, reportBeans.getItems(), true, locale, user, "", "", false, new File(templateFile), new File(templateDir)); String fileName = workItem.getSynopsis() + ".pdf"; String contentType = "application/pdf"; if (pdf.length() < 10) { pdf = new File(pdf.getParent() + "/errors.txt"); fileName = workItem.getSynopsis() + ".txt"; contentType = "text"; } OutputStream outputStream = null; try { response.reset(); response.setHeader("Content-Type", contentType); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); DownloadUtil.prepareCacheControlHeader(ServletActionContext.getRequest(), response); outputStream = response.getOutputStream(); InputStream is = new FileInputStream(pdf); IOUtils.copy(is, outputStream); is.close(); } catch (FileNotFoundException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { LOGGER.error("Getting the output stream failed with " + e.getMessage()); LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } // Docx4J.save(wordMLPackage, outputStream, Docx4J.FLAG_NONE); // //wordMLPackage.save(outputStream); // /*SaveToZipFile saver = new SaveToZipFile(wordMLPackage); // saver.save(outputStream);*/ // } catch (Exception e) { // LOGGER.error("Exporting the docx failed with throwable " + e.getMessage()); // LOGGER.debug(ExceptionUtils.getStackTrace(e)); // } return null; }
From source file:com.zilverline.MockHandler.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { invariant();/* w w w . j a v a2s .co m*/ ServletOutputStream outputStream = response.getOutputStream(); IOUtils.copy(responseResource.getInputStream(), outputStream); outputStream.flush(); }
From source file:org.openmrs.module.odkconnector.web.controller.serializer.DownloadCohortController.java
@RequestMapping(method = RequestMethod.POST) public void process(final HttpServletRequest request, final HttpServletResponse response) throws Exception { Processor processor = new HttpProcessor(HttpProcessor.PROCESS_COHORT); processor.process(request.getInputStream(), response.getOutputStream()); }
From source file:eionet.cr.web.action.ExportTriplesActionBean.java
/** * Action event that exports properties of the given uri. * * @return rdf result./*from w ww .j a v a2 s. co m*/ */ public Resolution exportProperties() { if (StringUtils.isBlank(uri)) { if (Util.isWebBrowser(getContext().getRequest())) { getContext().getRequest().setAttribute(StripesExceptionHandler.EXCEPTION_ATTR, new CRException("Graph URI not specified in the request!")); return new ForwardResolution(StripesExceptionHandler.ERROR_PAGE); } else { return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND); } } return (new StreamingResolution("application/rdf+xml") { public void stream(HttpServletResponse response) throws Exception { RDFGenerator.generateProperties(uri, response.getOutputStream()); } }); }
From source file:org.openmrs.module.odkconnector.web.controller.serializer.DownloadPatientsController.java
@RequestMapping(method = RequestMethod.POST) public void process(final HttpServletRequest request, final HttpServletResponse response) throws Exception { Processor processor = new HttpProcessor(HttpProcessor.PROCESS_PATIENTS); processor.process(request.getInputStream(), response.getOutputStream()); }
From source file:Controlador.ChartServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); JFreeChart chart = null;//from w w w. j a v a 2s .c om try { chart = getChart(); } catch (URISyntaxException ex) { Logger.getLogger(ChartServlet.class.getName()).log(Level.SEVERE, null, ex); } int width = 500; int height = 350; ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); }