List of usage examples for javax.servlet.http HttpServletResponse flushBuffer
public void flushBuffer() throws IOException;
From source file:cn.com.cennavi.visualizer.service.ExecuteController.java
private void returnAjax(String json, HttpServletRequest request, HttpServletResponse response) throws IOException { try {//w w w . j a v a2 s .co m String callback = request.getParameter("callback"); String revalue = callback + "(" + json + ")"; request.setCharacterEncoding("utf-8"); //??? response.setContentType("text/html;charset=utf-8"); response.setHeader("Cache-Control", "no-cache"); response.getOutputStream().write(revalue.getBytes()); response.flushBuffer(); } catch (Exception e) { // TODO: handle exception } }
From source file:com.ugam.collage.plus.controller.people_count.TeamStructureController.java
@RequestMapping(value = "/downLoadFile", method = RequestMethod.GET) public void downLoadFile(HttpServletRequest request, HttpServletResponse response) { try {//w w w . ja va2 s. c o m String docDir = System.getProperty("docDir"); String fileName = request.getParameter("fileName"); File file = new File(docDir + "/" + fileName); InputStream in = new BufferedInputStream(new FileInputStream(file)); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); ServletOutputStream out = response.getOutputStream(); IOUtils.copy(in, out); response.flushBuffer(); } catch (Exception e) { logger.error("", e); } }
From source file:org.mitre.mpf.mvc.controller.ServerMediaController.java
/*** * * @param response/*from w ww .ja va2 s. c om*/ * @param nodeFullPath * @throws IOException * @throws URISyntaxException */ @RequestMapping(value = "/server/node-image", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE) @ResponseBody public void serve(HttpServletResponse response, @RequestParam(value = "nodeFullPath", required = true) String nodeFullPath) throws IOException, URISyntaxException { //TODO: this set of lines is also used in the MarkupController - create a single method File f = new File(nodeFullPath); if (f.canRead()) { FileUtils.copyFile(f, response.getOutputStream()); response.flushBuffer(); } else { response.setStatus(404); } //TODO: add an image to return that is file not available and error retrieving file //to resources to use when there are issues //TODO: adjust the content type based on the image type //response.setContentLength(MediaType.); }
From source file:edu.ucla.loni.pipeline.server.Upload.Uploaders.FileUploadServlet.java
/** * Handles HTTP POST Request/Response/*from w w w .ja v a2 s . co m*/ * * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */ @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // set response status resp.setStatus(HttpServletResponse.SC_OK); // reset response message ResponseBuilder respBuilder = new ResponseBuilder(); // handle file upload handleFileUpload(req, respBuilder); // get response message String message = respBuilder.getRespMessage(); resp.getWriter().print(message); // flush response buffer resp.flushBuffer(); }
From source file:com.rcn.controller.ResourceController.java
@RequestMapping(value = "/pkcs12/{file_name}", method = RequestMethod.POST) public void pkcs12Post(@PathVariable("file_name") String fileName, @RequestParam("rid") Long rid, @RequestParam("password") String password, Authentication principal, Model model, HttpServletResponse response) throws IOException { RcnUserDetail user = (RcnUserDetail) principal.getPrincipal(); Long targetUserId = user.getTargetUser().getId(); String cert = resourceRepository.certById(targetUserId, targetUserId, rid); try {//from w ww . j a va 2s .c o m byte[] content = certificateService.toPkcs12(cert, password); response.setContentType("application/octet-stream"); response.getOutputStream().write(content); response.flushBuffer(); } catch (Exception e) { model.addAttribute("error", e.getMessage()); } }
From source file:fr.putnami.pwt.plugin.spring.file.server.controller.FileTransfertController.java
@RequestMapping(value = "/file/download/{fileId}", method = RequestMethod.GET) public void downloadFile(@PathVariable String fileId, HttpServletRequest request, HttpServletResponse response) { try {/*from w w w. j av a 2 s . c o m*/ FileDto fileBean = this.store.getFileBean(fileId); if (fileBean == null) { throw new RuntimeException("Aucun fichier trouver " + fileId); } InputStream is = this.store.read(fileId); response.setContentType(fileBean.getMime()); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileBean.getName() + "\""); response.setContentLength((int) fileBean.getContentLength()); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { throw new RuntimeException("IOError writing file to output stream", ex); } }
From source file:cn.org.once.cstack.controller.MonitoringController.java
/** * * Is a wrapper to cAdvisor API//from w w w. jav a2s .co m * * @param containerName * @throws ServiceException * @throws CheckException */ @RequestMapping(value = "/api/containers/docker/{containerName}", method = RequestMethod.GET) public void infoContainer(HttpServletRequest request, HttpServletResponse response, @PathVariable String containerName) throws ServiceException, CheckException { try { String containerId = dockerService.getContainerId(containerName); String responseFromCAdvisor = monitoringService.getJsonFromCAdvisor(containerId); if (logger.isDebugEnabled()) { logger.debug("containerId=" + containerId); logger.debug("responseFromCAdvisor=" + responseFromCAdvisor); } response.getWriter().write(responseFromCAdvisor); response.flushBuffer(); } catch (Exception e) { logger.error("error during write and flush response", containerName); } }
From source file:org.mitre.mpf.mvc.controller.MarkupController.java
@RequestMapping(value = "/markup/download", method = RequestMethod.GET) public void getFile(@RequestParam(value = "id", required = true) long id, HttpServletResponse response) throws IOException, URISyntaxException { MarkupResult mediaMarkupResult = mpfService.getMarkupResult(id); if (mediaMarkupResult != null) { String nonUrlPath = mediaMarkupResult.getMarkupUri().replace("file:", ""); File f = new File(nonUrlPath); if (f.canRead()) { //copy it to response's OutputStream FileUtils.copyFile(f, response.getOutputStream()); response.flushBuffer(); }/*w w w . j a va2 s . com*/ } //TODO: what to do if file does not exist }
From source file:gerenciador.incubadora.controller.ArquivoController.java
@RequestMapping(value = "/imagem/{id}") public ModelAndView download(HttpServletResponse response, @PathVariable Long id) throws FileNotFoundException, Exception { InputStream is = new ByteArrayInputStream( FileUtils.readFileToByteArray(new File(Empreendimento.EMPREENDIMENTO_PATH_LOGO_DEFAULT))); ModelAndView mv = new ModelAndView("redirect:/empreendedor"); Empreendimento empreendimento = ServiceLocator.getEmpreendimentoService().readById(id); mv.addObject("empreendimento", empreendimento); //is.close(); response.setContentType("image/jpeg"); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); if (response.isCommitted()) { System.out.println("Resposta Comitada!"); }/* ww w . ja va2 s .c o m*/ return new ModelAndView("empreendimento/new"); }