List of usage examples for javax.servlet.http HttpServletResponse flushBuffer
public void flushBuffer() throws IOException;
From source file:com.qcadoo.mes.technologies.controller.TechnologyMultiUploadController.java
@RequestMapping(value = "/getAttachment.html", method = RequestMethod.GET) public final void getAttachment(@RequestParam("id") final Long[] ids, HttpServletResponse response) { DataDefinition attachmentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_ATTACHMENT); Entity attachment = attachmentDD.get(ids[0]); InputStream is = fileService/*w ww . j a va 2 s .c om*/ .getInputStream(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT)); try { if (is == null) { response.sendRedirect("/error.html?code=404"); } response.setHeader("Content-disposition", "inline; filename=" + attachment.getStringField(TechnologyAttachmentFields.NAME)); response.setContentType( fileService.getContentType(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT))); int bytes = IOUtils.copy(is, response.getOutputStream()); response.setContentLength(bytes); response.flushBuffer(); } catch (IOException e) { logger.error("Unable to copy attachment file to response stream.", e); } }
From source file:it.cilea.osd.jdyna.web.flow.GestioneAlberoDTO.java
public Event export(RequestContext context) throws Exception { DTOGestioneAlberoClassificatore alberoDTO = (DTOGestioneAlberoClassificatore) getFormObject(context); ServletExternalContext externalContext = (ServletExternalContext) context.getExternalContext(); HttpServletResponse response = externalContext.getResponse(); Integer alberoID = alberoDTO.getId(); AlberoClassificatorio albero = null; if (alberoID != null) { albero = applicationService.get(AlberoClassificatorio.class, alberoID); }/*from w ww . j a v a 2s. c om*/ String filename; filename = "configurazione-albero_classificatorio_" + albero.getNome().replaceAll(" ", "_") + ".xml"; response.setContentType("application/xml"); response.addHeader("Content-Disposition", "attachment; filename=" + filename); PrintWriter writer = response.getWriter(); exportUtils.writeDocTypeANDCustomEditorAlberoClassificatore(writer); if (albero != null) { exportUtils.alberoClassificatorioToXML(writer, albero); } response.getWriter().print("</beans>"); response.flushBuffer(); return success(); }
From source file:com.crucialticketing.controllers.FileController.java
@RequestMapping(value = "/{filename}/", method = RequestMethod.GET) @ResponseBody//from ww w .jav a2 s.co m public void fileDispatcher(@PathVariable(value = "filename") String fileUploadId, HttpServletRequest request, HttpServletResponse response, ModelMap map) throws Exception { String fileName = request.getServletContext().getRealPath("/WEB-INF/upload/"); Attachment attachment = attachmentService.getAttachmentById(Integer.valueOf(fileUploadId)); if (attachment.getFileUploadId() == 0) { throw new Exception(); } fileName += "\\" + attachment.getTicket().getTicketId() + "\\" + attachment.getFileName(); try { InputStream in = new BufferedInputStream(new FileInputStream(new File(fileName))); String extension = "unknown"; int i = fileName.lastIndexOf('.'); if (i > 0) { extension = fileName.substring(i + 1); } response.setContentType("application/" + extension); response.setHeader("Content-Disposition", "attachment; filename=" + attachment.getFileName()); ServletOutputStream out = response.getOutputStream(); IOUtils.copy(in, out); response.flushBuffer(); } catch (Exception e) { } }
From source file:cn.imethan.common.security.session.ConcurrentSessionFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; HttpSession session = request.getSession(false); if (session != null) { SessionInformation info = sessionRegistry.getSessionInformation(session.getId()); if (info != null) { if (info.isExpired()) { // Expired - abort processing doLogout(request, response); String targetUrl = determineExpiredUrl(request, info); if (targetUrl != null) { redirectStrategy.sendRedirect(request, response, targetUrl); return; } else { response.getWriter() .print("This session has been expired (possibly due to multiple concurrent " + "logins being attempted as the same user)."); response.flushBuffer(); }/* w ww . java 2s . com*/ return; } else { // Non-expired - update last request date/time sessionRegistry.refreshLastRequest(info.getSessionId()); } } } chain.doFilter(request, response); }
From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserController.java
@RequestMapping(value = "download", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK)/*from w w w . j a v a 2 s. c o m*/ public Response download(HttpServletResponse res, @RequestParam String bucketName, @RequestParam String key) throws IOException { S3Object object = s3BrowserService.getObject(bucketName, key); InputStream objectData = object.getObjectContent(); res.setHeader("Content-Length", "" + object.getObjectMetadata().getContentLength()); res.setHeader("Content-Transfer-Encoding", "binary"); res.setHeader("Content-Type", "application/force-download"); res.setHeader("Content-Disposition", MessageFormatter.format("attachment; filename={};", getName(key)).getMessage()); res.setStatus(200); FileCopyUtils.copy(objectData, res.getOutputStream()); res.flushBuffer(); objectData.close(); Response response = new Response(); response.setSuccess(true); return response; }
From source file:com.qcadoo.mes.cmmsMachineParts.controller.PlannedEventMultiUploadController.java
@RequestMapping(value = "/getAttachmentForPlannedEvent.html", method = RequestMethod.GET) public final void getAttachment(@RequestParam("id") final Long[] ids, HttpServletResponse response) { DataDefinition attachmentDD = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT_ATTACHMENT); Entity attachment = attachmentDD.get(ids[0]); InputStream is = fileService// w w w . j a v a 2 s .c o m .getInputStream(attachment.getStringField(PlannedEventAttachmentFields.ATTACHMENT)); try { if (is == null) { response.sendRedirect("/error.html?code=404"); } response.setHeader("Content-disposition", "inline; filename=" + attachment.getStringField(PlannedEventAttachmentFields.NAME)); response.setContentType( fileService.getContentType(attachment.getStringField(PlannedEventAttachmentFields.ATTACHMENT))); int bytes = IOUtils.copy(is, response.getOutputStream()); response.setContentLength(bytes); response.flushBuffer(); } catch (IOException e) { logger.error("Unable to copy attachment file to response stream.", e); } }
From source file:org.alfresco.repo.webdav.auth.BaseKerberosAuthenticationFilter.java
/** * The logon to start again/*from ww w .j av a2s . co m*/ * * @param context ServletContext * @param req HttpServletRequest * @param resp HttpServletResponse * @param ignoreFallback ignore fallback * @throws IOException */ private void logonStartAgain(ServletContext context, HttpServletRequest req, HttpServletResponse resp, boolean ignoreFallback) throws IOException { if (getLogger().isDebugEnabled()) getLogger().debug("Issuing login challenge to browser."); // Force the logon to start again resp.setHeader("WWW-Authenticate", "Negotiate"); if (!ignoreFallback && isFallbackEnabled()) { includeFallbackAuth(context, req, resp); } resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); writeLoginPageLink(context, req, resp); resp.flushBuffer(); }
From source file:org.kchine.r.server.http.frontend.RebindServlet.java
protected void doAny(final HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); try {//www . ja v a2 s. c o m String[] names = ServerDefaults.getRmiRegistry().list(); Properties props = new Properties(); Map<String, String> map = request.getParameterMap(); for (String s : map.keySet()) props.put(s, map.get(s)); for (int i = 0; i < names.length; ++i) { try { RServices r = (RServices) ServerDefaults.getRmiRegistry().lookup(names[i]); String newName = r.export(props, request.getParameter("prefix"), true); response.getOutputStream().println("<" + names[i] + "> rebinded to <" + newName + ">"); } catch (Exception e) { response.getOutputStream().println("Couldn't Rebind <" + names[i] + ">"); } } response.getOutputStream().println("Rebind succeeded"); response.flushBuffer(); } catch (Throwable e) { response.getOutputStream().println(Utils.getStackTraceAsString(e)); response.flushBuffer(); } }
From source file:de.whs.poodle.repositories.FileRepository.java
public void writeFileToHttpResponse(int fileId, HttpServletResponse response) { jdbc.query("SELECT filename,mimetype,data FROM uploaded_file WHERE id = ?", new Object[] { fileId }, // use ResultSetExtractor, so we can check whether the row even exists (NotFoundException) new ResultSetExtractor<Void>() { @Override/* ww w . jav a 2s . c o m*/ public Void extractData(ResultSet rs) throws SQLException { if (!rs.next()) throw new NotFoundException(); String filename = rs.getString("filename"); String mimeType = rs.getString("mimetype"); response.setHeader("Content-Disposition", "filename=\"" + filename + "\""); response.setContentType(mimeType); try (InputStream in = rs.getBinaryStream("data"); OutputStream out = response.getOutputStream();) { StreamUtils.copy(in, out); response.flushBuffer(); } catch (IOException e) { throw new RuntimeException(e); } return null; } }); }
From source file:io.getlime.security.powerauth.app.server.service.controller.RESTResponseExceptionResolver.java
@Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) { try {/*w w w .j av a2 s .c o m*/ // Build the error list RESTErrorModel error = new RESTErrorModel(); error.setCode("ERR_SPRING_JAVA"); error.setMessage(exception.getMessage()); error.setLocalizedMessage(exception.getLocalizedMessage()); List<RESTErrorModel> errorList = new LinkedList<>(); errorList.add(error); // Prepare the response RESTResponseWrapper<List<RESTErrorModel>> errorResponse = new RESTResponseWrapper<>("ERROR", errorList); // Write the response in JSON and send it ObjectMapper mapper = new ObjectMapper(); String responseString = mapper.writeValueAsString(errorResponse); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.getOutputStream().print(responseString); response.flushBuffer(); } catch (IOException e) { // Response object does have an output stream here } return new ModelAndView(); }