List of usage examples for javax.servlet.http HttpServletResponse flushBuffer
public void flushBuffer() throws IOException;
From source file:it.govpay.web.console.pagamenti.gde.exporter.EventiExporter.java
private void processRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {/*from w ww .j a v a 2s . c om*/ // ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); // service = (IEventiService)context.getBean("eventiService"); // EventiSearchForm sfInSession = (EventiSearchForm)context.getBean("searchFormEventi"); // EventiSearchForm searchForm = (EventiSearchForm)sfInSession.clone(); // service.setForm(searchForm); // Then we have to get the Response where to write our file HttpServletResponse response = resp; String isAllString = req.getParameter("isAll"); Boolean isAll = Boolean.parseBoolean(isAllString); String idtransazioni = req.getParameter("ids"); String[] ids = StringUtils.split(idtransazioni, ","); String formato = req.getParameter("formato"); String fileName = "Eventi.zip"; response.setContentType("x-download"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.addHeader("Cache-Control", "no-cache"); response.setStatus(200); response.setBufferSize(1024); // committing status and headers response.flushBuffer(); ExporterProperties prop = new ExporterProperties(); prop.setEnableHeaderInfo(EventiExporter.enableHeaderInfo); prop.setFormatoExport(formato); prop.setMimeThrowExceptionIfNotFound(EventiExporter.mimeThrowExceptionIfNotFound); SingleFileExporter sfe = new SingleFileExporter(response.getOutputStream(), prop, service); if (isAll) { //transazioni = service.findAll(start, limit); sfe.export(); } else { List<String> idEvento = new ArrayList<String>(); for (int j = 0; j < ids.length; j++) { idEvento.add(ids[j]); } sfe.export(idEvento); } } catch (IOException se) { this.log.error(se, se); throw se; } catch (Exception e) { this.log.error(e, e); throw new ServletException(e); } }
From source file:it.polimi.diceH2020.launcher.controller.DownloadsController.java
@RequestMapping(value = "/download", method = RequestMethod.GET) @ResponseBody//from w w w. ja v a 2s. co m void downloadPartialExcel(@RequestParam(value = "id") Long id, HttpServletResponse response) { SimulationsManager manager = simulationsManagerRepository.findOne(id); Workbook wb = excelWriter.createWorkbook(manager); try { //response.setContentType("application/ms-excel;charset=utf-8"); response.setContentType("application/vnd.ms-excel;charset=utf-8"); //response.setContentType(new MediaType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet")); response.setHeader("Content-Disposition", "attachment;filename = results.xls"); wb.write(response.getOutputStream()); response.flushBuffer(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.nuxeo.ecm.automation.jsf.operations.DownloadFile.java
@OperationMethod public void run(Blob blob) throws OperationException, IOException { if (blob == null) { throw new OperationException("there is no file content available"); }//from ww w . jav a 2 s .c o m String filename = blob.getFilename(); if (blob.getLength() > Functions.getBigFileSizeLimit()) { ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); HttpServletRequest request = (HttpServletRequest) externalContext.getRequest(); HttpServletResponse response = (HttpServletResponse) externalContext.getResponse(); String sid = UUID.randomUUID().toString(); request.getSession(true).setAttribute(sid, blob); String bigDownloadURL = BaseURL.getBaseURL(request); bigDownloadURL += DownloadService.NXBIGBLOB + "/" + sid; try { // Operation was probably triggered by a POST // so we need to de-activate the ResponseWrapper that would // rewrite the URL request.setAttribute(NXAuthConstants.DISABLE_REDIRECT_REQUEST_KEY, new Boolean(true)); // send the redirect response.sendRedirect(bigDownloadURL); // mark all JSF processing as completed response.flushBuffer(); FacesContext.getCurrentInstance().responseComplete(); // set Outcome to null (just in case) ctx.getVars().put("Outcome", null); } catch (IOException e) { log.error("Error while redirecting for big blob downloader", e); } } else { ComponentUtils.download(null, null, blob, filename, "operation"); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.candidacy.CandidacyProcessDA.java
public ActionForward prepareExecuteExportCandidacies(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment; filename=" + getReportFilename()); final ServletOutputStream writer = response.getOutputStream(); writeCandidaciesReport(request, getProcess(request), writer); writer.flush();/*from w ww . ja v a 2 s . c o m*/ response.flushBuffer(); return null; }
From source file:org.eclipse.vorto.repository.web.ModelGenerationController.java
@ApiOperation(value = "Generate code for a specified platform") @RequestMapping(value = "/{namespace}/{name}/{version:.+}/{serviceKey}", method = RequestMethod.GET) public void generate(@ApiParam(value = "Namespace", required = true) final @PathVariable String namespace, @ApiParam(value = "Name", required = true) final @PathVariable String name, @ApiParam(value = "Version", required = true) final @PathVariable String version, @ApiParam(value = "Service Key - Platform", required = true) @PathVariable String serviceKey, @ApiParam(value = "Response", required = true) final HttpServletResponse response) { Objects.requireNonNull(namespace, "namespace must not be null"); Objects.requireNonNull(name, "name must not be null"); Objects.requireNonNull(version, "version must not be null"); GeneratedOutput generatedOutput = generatorService.generate(new ModelId(name, namespace, version), serviceKey);//w w w . j a va 2 s .c om response.setHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + generatedOutput.getFileName()); response.setContentLengthLong(generatedOutput.getSize()); response.setContentType(APPLICATION_OCTET_STREAM); try { IOUtils.copy(new ByteArrayInputStream(generatedOutput.getContent()), response.getOutputStream()); response.flushBuffer(); } catch (IOException e) { throw new RuntimeException("Error copying file.", e); } }
From source file:com.comcast.video.dawg.show.TraceController.java
/** * Method to generate a trace log file/*from w w w . j a va 2 s . co m*/ * @param trace trace log obtained from trace div * @param device device Id of the settop * @param response http response to get the trace file * @throws IOException Exception occurring while writing log. */ public void generateLogFile(String trace, String device, HttpServletRequest req, HttpServletResponse response) throws IOException { accessValidator.validateUserHasAccessToDevices(req, response, false, device); String timestamp = FILE_NAME_DATE_FORMATTER.format(new Date()); response.setHeader("Content-Disposition", "attachment; filename=Settop_" + device + "_" + timestamp + ".log"); PrintWriter writer = null; String log = StringEscapeUtils.unescapeHtml(trace.trim()); try { writer = response.getWriter(); writer.write(log); } catch (IOException ioe) { LOGGER.error("Exception while generating trace logs ", ioe); throw ioe; } finally { if (writer != null) { writer.flush(); writer.close(); } response.flushBuffer(); } }
From source file:org.kuali.mobility.icons.controllers.WebIconsController.java
/** * Get the icon matching all the criteria of the request and write it the the HttpServletResponse. * * @param iconName Name of the icon to get. * @param theme The theme to get the icon in. * @param size Size to get the icon in. * @param request The HttpServletRequest being handled. * @param response The HttpServletResponse that will reply. * @throws IOException Thrown if there is an exception creating the icon or writing it to the response. */// www.j a v a 2 s .c o m private void writeIconToHttpResponse(String iconName, String theme, int size, HttpServletRequest request, HttpServletResponse response) throws IOException { long dateChanged = request.getDateHeader("If-Modified-Since") / 1000; File imageFile = iconService.getImageFile(iconName, theme, size); long mediaChanged = imageFile.lastModified() / 1000; if (dateChanged == mediaChanged) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } response.setContentType("image/png"); InputStream imageInput = new FileInputStream(imageFile); response.setDateHeader("Last-Modified", imageFile.lastModified()); int bytesWritten = IOUtils.copy(imageInput, response.getOutputStream()); response.setContentLength(bytesWritten); response.flushBuffer(); }
From source file:org.fenixedu.spaces.ui.OccupationRequestsController.java
@RequestMapping(value = "/export", method = RequestMethod.GET) public void exportAnyCampusToExcel(@RequestParam(required = false) Space campus, @RequestParam(required = false) OccupationRequestState state, HttpServletResponse response) { List<OccupationRequest> requests; if (state != null) { requests = occupationService.all(state, campus); } else {//from w ww . ja va 2 s.c om requests = occupationService.getRequestsToProcess(Authenticate.getUser(), campus); } String filename = bundle.message("label.occupation.request.filename"); if (campus != null) { filename += "_" + campus.getPresentationName(); } response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment; filename=" + filename + ".xls"); try { makeExcel(requests, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:nl.strohalm.cyclos.http.RestFilter.java
@Override @SuppressWarnings("unchecked") protected void onError(final HttpServletRequest request, final HttpServletResponse response, final Throwable t) throws IOException { log(request, t);/*w w w . j a v a 2 s . co m*/ LOG.error("Error on REST call", t); final Pair<ServerErrorVO, Integer> error = RestHelper.resolveError(t); final ServerErrorVO vo = error.getFirst(); final JSONObject json = new JSONObject(); if (StringUtils.isNotEmpty(vo.getErrorCode())) { json.put("errorCode", vo.getErrorCode()); } if (StringUtils.isNotEmpty(vo.getErrorDetails())) { json.put("errorDetails", vo.getErrorDetails()); } response.setStatus(error.getSecond()); response.setContentType("application/json"); json.writeJSONString(response.getWriter()); response.flushBuffer(); }