List of usage examples for javax.servlet.http HttpServletResponse flushBuffer
public void flushBuffer() throws IOException;
From source file:de.unirostock.sems.cbarchive.web.servlet.IconServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { // set charset response.setCharacterEncoding(Fields.CHARSET); request.setCharacterEncoding(Fields.CHARSET); // splitting request URL String requestUrl = request.getRequestURI(); LOGGER.debug("IconServlet request: ", requestUrl); if (requestUrl != null && !requestUrl.isEmpty()) { String formatString = null; try {//from w w w . java2 s . co m response.setContentType("image/png"); formatString = requestUrl.substring(requestUrl.indexOf("res/icon/") + 9); LOGGER.debug("format: ", formatString); URI format = new URI(formatString); LOGGER.debug("format url: ", format); OutputStream output = response.getOutputStream(); InputStream input = Iconizer.formatToIconStream(format); int size = IOUtils.copy(input, output); response.setContentLength(size); output.flush(); output.close(); input.close(); response.flushBuffer(); } catch (IOException e) { LOGGER.error(e, "IOException while loading icon"); } catch (URISyntaxException e) { LOGGER.warn(e, "Not able to generate URL for Iconizer: ", formatString); } } }
From source file:org.asqatasun.webapp.controller.AuditScenarioController.java
@RequestMapping(value = TgolKeyStore.DOWNLOAD_SCENARIO_URL_CONTRACT_URL, method = RequestMethod.GET) @Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY }) public void getScenarioFile(@RequestParam(TgolKeyStore.CONTRACT_ID_KEY) String contractId, @RequestParam(TgolKeyStore.SCENARIO_ID_KEY) String scenarioId, HttpServletResponse response) { Contract contract = getContractDataService().read(Long.valueOf(contractId)); if (contract.getUser().getId().equals(getCurrentUser().getId())) { try {// w w w . j a v a 2 s . co m for (Scenario scenario : contract.getScenarioSet()) { if (scenario.getId().equals(Long.valueOf(scenarioId))) { InputStream is = IOUtils.toInputStream(scenario.getContent()); IOUtils.copy(is, response.getOutputStream()); response.setContentType(TgolKeyStore.CONTENT_TYPE); StringBuilder strb = new StringBuilder(TgolKeyStore.ATTACHMENT); strb.append(scenario.getLabel()); strb.append(TgolKeyStore.JSON_EXTENSION); response.setHeader(TgolKeyStore.CONTENT_DISPOSITION, strb.toString()); response.flushBuffer(); break; } } throw new ForbiddenPageException(getCurrentUser()); } catch (IOException ex) { throw new RuntimeException("IOError writing file to output stream"); } } else { throw new ForbiddenPageException(getCurrentUser()); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.gep.ects.ManageEctsComparabilityTablesDispatchAction.java
public ActionForward exportTemplate(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { EctsTableFilter filter = readFilter(request); try {/*from w ww. ja va 2 s. co m*/ try { SheetData<?> builder = exportTemplate(request, filter); response.setContentType("text/csv"); response.setHeader("Content-disposition", "attachment; filename=template.tsv"); new SpreadsheetBuilder().addSheet("template", builder).build(WorkbookExportFormat.TSV, response.getOutputStream()); return null; } finally { response.flushBuffer(); } } catch (IOException e) { addActionMessage(request, "error.ects.comparabilityTables.ioException"); processStatus(request, filter); request.setAttribute("filter", filter); return mapping.findForward("index"); } }
From source file:org.ejbca.extra.ra.ScepRAServlet.java
/** * Sends back a number of bytes//from w ww . j a va 2s. c om * * @param bytes DER encoded certificate to be returned * @param out output stream to send to * @param contentType mime type to send back bytes as * @param fileName to call the file in a Content-disposition, can be null to leave out this header * * @throws Exception on error */ private void sendBinaryBytes(byte[] bytes, HttpServletResponse out, String contentType, String filename) throws Exception { if ((bytes == null) || (bytes.length == 0)) { log.error("0 length can not be sent to client!"); return; } if (filename != null) { // We must remove cache headers for IE removeCacheHeaders(out); out.setHeader("Content-disposition", "filename=\"" + filename + "\""); } // Set content-type to general file out.setContentType(contentType); out.setContentLength(bytes.length); // Write the certificate ServletOutputStream os = out.getOutputStream(); os.write(bytes); out.flushBuffer(); log.debug("Sent " + bytes.length + " bytes to client"); }
From source file:ru.codemine.ccms.router.TaskRouter.java
@Secured("ROLE_USER") @RequestMapping(value = "/tasks/getfile/{urlfilename}", method = RequestMethod.GET) public void getFileFromTask(@RequestParam("taskid") Integer taskid, @RequestParam("fileid") Long fileid, @PathVariable("urlfilename") String urlFileName, HttpServletResponse response) { Task task = taskService.getById(taskid); DataFile targetDataFile = dataFileService.getById(fileid); Employee currentUser = employeeService.getCurrentUser(); if (targetDataFile == null || task == null || !task.isInTask(currentUser)) return;// w w w .j a v a 2 s . c om File targetFile = new File(targetDataFile.getFilename()); try { String encFilename = URLEncoder.encode(targetDataFile.getViewName().replace(" ", "_"), "UTF-8"); String decFilename = URLDecoder.decode(encFilename, "ISO8859_1"); response.setHeader("Content-Disposition", "attachment;filename=" + decFilename); BufferedInputStream bs = new BufferedInputStream(new FileInputStream(targetFile)); IOUtils.copy(bs, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { log.error(" " + targetDataFile.getViewName() + ", : " + ex.getLocalizedMessage()); } }
From source file:eionet.transfer.controller.FileOpsController.java
/** * AJAX Upload file for transfer./*from www .ja v a 2 s . c om*/ */ @RequestMapping(value = "/fileupload", method = RequestMethod.POST, params = "ajaxupload=1") public void importFileWithAJAX(@RequestParam("file") MultipartFile myFile, @RequestParam("fileTTL") int fileTTL, HttpServletRequest request, HttpServletResponse response) throws IOException { if (myFile == null || myFile.getOriginalFilename() == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Select a file to upload"); return; } if (fileTTL > 90) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid expiration date"); return; } String uuidName = storeFile(myFile, fileTTL); response.setContentType("text/xml"); PrintWriter printer = response.getWriter(); StringBuffer requestUrl = request.getRequestURL(); String url = requestUrl.substring(0, requestUrl.length() - "/fileupload".length()); printer.println("<?xml version='1.0'?>"); printer.println("<package>"); printer.println("<downloadLink>" + url + "/download/" + uuidName + "</downloadLink>"); printer.println("<deleteLink>" + url + "/delete/" + uuidName + "</deleteLink>"); printer.println("</package>"); printer.flush(); response.flushBuffer(); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.scientificCouncil.credits.MasterDegreeCreditsManagementDispatchAction.java
public ActionForward exportToExcel(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws FenixServiceException { ExecutionDegree executionDegree = getExecutionDegreeFromParameter(request); List<MasterDegreeCreditsDTO> listing = getListing(executionDegree); if (!listing.isEmpty()) { Collections.sort(listing, new BeanComparator("curricularCourse.name")); }//from w w w.j a va 2s. c om try { String filename = getFileName(executionDegree); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment; filename=" + filename + ".xls"); ServletOutputStream writer = response.getOutputStream(); exportToXls(executionDegree, listing, writer); writer.flush(); response.flushBuffer(); } catch (IOException e) { throw new FenixServiceException(); } return null; }
From source file:org.nuxeo.ecm.automation.jsf.operations.ExtDownloadFile.java
@OperationMethod public void run(Blob blob) throws Exception { if (blob == null) { throw new OperationException("there is no file content available"); }//from w w w .j a va 2 s. co m FacesContext faces = FacesContext.getCurrentInstance(); String filename = blob.getFilename(); if (blob.getLength() > Functions.getBigFileSizeLimit()) { HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); if (!blob.isPersistent()) { blob.persist(); } String sid = "Blob-" + ctx.getCoreSession().getSessionId() + "-" + System.currentTimeMillis(); sid = sid.replace("#", ""); request.getSession(true).setAttribute(sid, blob); String bigDownloadURL = BaseURL.getBaseURL(request); bigDownloadURL += "nxbigblob" + "/" + sid; try { // Operation was probably triggered by a POST // so we need to desactivate 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(faces, blob, filename); } }
From source file:de.knurt.fam.template.controller.DelegateResourceController.java
@RequestMapping(value = "/jobsurvey__{filename}__html__delegate.fam", method = RequestMethod.GET) public final ModelAndView handleGetJobsurvey(HttpServletResponse response, HttpServletRequest request) { this.generalInit(response, "text/html; charset=UTF-8"); User user = SessionAuth.user(request); if (user == null) { return RedirectResolver.redirect(RedirectTarget.PUBLIC_HOME); } else {/*from ww w .j a v a 2 s . c o m*/ OutputStream os = null; try { os = response.getOutputStream(); JobSurveyView jsv = JobSurveyViewFactory.getJobSurveyView(user, request, response); if (jsv.isValidRequest()) { IOUtils.write(jsv.getView(), os); response.flushBuffer(); } else { FamLog.error("no jobsurvey found!;" + request.getQueryString() + ";" + user.getUsername(), 201203281229l); IOUtils.write("please report error 201203281229-" + FamDateFormat.getDateAndTimeShort(), os); } } catch (IOException e) { FamLog.exception(e, 201202160927l); } finally { IOUtils.closeQuietly(os); } return null; } }
From source file:org.apache.sentry.api.service.thrift.LogLevelServlet.java
/** * Parse the class name and log level in the http servlet request. * If the request contains only class name, return the log level in the response message. * If the request contains both class name and level, set the log level to the requested level * and return the setting result in the response message. *//*from w w w . ja va 2 s .co m*/ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String logName = getParameter(request, "log"); String level = getParameter(request, "level"); response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter out = response.getWriter(); if (logName != null) { Logger logInstance = LogManager.getLogger(logName); if (level == null) { out.write( String.format(FORMS_GET, escapeHtml(logName), logInstance.getEffectiveLevel().toString())); } else if (isLogLevelValid(level)) { logInstance.setLevel(Level.toLevel(level)); out.write(String.format(FORMS_SET, escapeHtml(logName), escapeHtml(level), escapeHtml(level), logInstance.getEffectiveLevel().toString())); } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid log level: " + escapeHtml(level)); return; } } out.write(FORMS_END); out.close(); response.flushBuffer(); }