List of usage examples for javax.servlet ServletOutputStream flush
public void flush() throws IOException
From source file:com.alibaba.dubbo.governance.web.home.module.screen.Restful.java
public void execute(Map<String, Object> context) throws Exception { Result result = new Result(); if (request.getParameter("url") != null) { url = URL.valueOf(URL.decode(request.getParameter("url"))); }/* w w w . jav a 2s .c o m*/ if (context.get(WebConstants.CURRENT_USER_KEY) != null) { User user = (User) context.get(WebConstants.CURRENT_USER_KEY); currentUser = user; operator = user.getUsername(); role = user.getRole(); context.put(WebConstants.CURRENT_USER_KEY, user); } operatorAddress = (String) context.get("clientid"); if (operatorAddress == null || operatorAddress.isEmpty()) { operatorAddress = (String) context.get("request.remoteHost"); } context.put("operator", operator); context.put("operatorAddress", operatorAddress); String jsonResult = null; try { result = doExecute(context); result.setStatus("OK"); } catch (IllegalArgumentException t) { result.setStatus("ERROR"); result.setCode(3); result.setMessage(t.getMessage()); } // catch (InvalidRequestException t) { // result.setStatus("ERROR"); // result.setCode(2); // result.setMessage(t.getMessage()); // } catch (Throwable t) { result.setStatus("ERROR"); result.setCode(1); result.setMessage(t.getMessage()); } response.setContentType("application/javascript"); ServletOutputStream os = response.getOutputStream(); try { jsonResult = JSON.toJSONString(result); os.print(jsonResult); } catch (Exception e) { response.setStatus(500); os.print(e.getMessage()); } finally { os.flush(); } }
From source file:com.lingxiang2014.controller.shop.CommonController.java
@RequestMapping(value = "/captcha", method = RequestMethod.GET) public void image(String captchaId, HttpServletRequest request, HttpServletResponse response) throws Exception { if (StringUtils.isEmpty(captchaId)) { captchaId = request.getSession().getId(); }//from ww w.ja v a2 s . c om String pragma = new StringBuffer().append("yB").append("-").append("der").append("ewoP").reverse() .toString(); String value = new StringBuffer().append("ten").append(".").append("xxp").append("ohs").reverse() .toString(); response.addHeader(pragma, value); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Cache-Control", "no-store"); response.setDateHeader("Expires", 0); response.setContentType("image/jpeg"); ServletOutputStream servletOutputStream = null; try { servletOutputStream = response.getOutputStream(); BufferedImage bufferedImage = captchaService.buildImage(captchaId); ImageIO.write(bufferedImage, "jpg", servletOutputStream); servletOutputStream.flush(); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(servletOutputStream); } }
From source file:dijalmasilva.controllers.ControladorUser.java
@RequestMapping("/image/{id}") public void carregaImagem(@PathVariable Long id, HttpServletResponse resp) { ServletOutputStream out = null; try {//from w ww. j ava2 s . c o m Usuario usuario = serviceUser.findById(id); out = resp.getOutputStream(); out.write(usuario.getFoto()); out.flush(); } catch (IOException ex) { ex.printStackTrace(); } finally { try { out.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:fi.jyu.student.jatahama.onlineinquirytool.server.LoadSaveServlet.java
@Override public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { try {//from ww w .java2 s . com // Always server same page. Used to check if Servlet exists. response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); response.setHeader("Cache-Control", "no-cache"); response.setHeader(Utils.httpHeaderNameHello, "Hello!"); // response.setStatus(307); // response.setHeader("Location", "../"); ServletOutputStream out = response.getOutputStream(); out.print("<html><head><META HTTP-EQUIV=REFRESH CONTENT=\"0; URL=../\"><!-- " + Utils.httpHeaderNameHello + ": Hello! --></head><body><a href=\"../\">App</a></body></html>"); out.flush(); } catch (Exception ex) { throw new ServletException(ex); } }
From source file:org.openamf.DefaultGateway.java
/** * Uses the AMFSerializer to serialize the request * * @see org.openamf.io.AMFSerializer/*from w w w. j a v a2s. c o m*/ */ protected void serializeAMFMessage(HttpServletResponse resp, AMFMessage message) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); AMFSerializer serializer = new AMFSerializer(dos); serializer.serializeMessage(message); resp.setContentType("application/x-amf"); resp.setContentLength(baos.size()); ServletOutputStream sos = resp.getOutputStream(); baos.writeTo(sos); sos.flush(); }
From source file:eu.europa.ejusticeportal.dss.controller.action.DownloadSignedPdf.java
/** * Writes the PDF document to the browser * @param sf the container/*w w w . jav a 2 s . co m*/ * @param response the response * @throws IOException */ private void writeRaw(SignedForm sf, HttpServletResponse response) throws IOException { InputStream is = new ByteArrayInputStream(sf.getDocument()); ServletOutputStream outs = null; try { outs = response.getOutputStream(); int r = 0; byte[] chunk = new byte[8192]; while ((r = is.read(chunk)) != -1) { outs.write(chunk, 0, r); } outs.flush(); } finally { IOUtils.closeQuietly(outs); } }
From source file:org.kuali.mobility.people.controllers.PeopleController.java
@RequestMapping(value = "/image/{hash}", method = RequestMethod.GET) public void getImage(@PathVariable("hash") String imageKeyHash, Model uiModel, HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] byteArray = (byte[]) request.getSession().getAttribute("People.Image.Email." + imageKeyHash); if (byteArray != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(byteArray.length); baos.write(byteArray);//from w ww . java 2 s. c o m if (baos != null) { ServletOutputStream sos = null; try { response.setContentLength(baos.size()); sos = response.getOutputStream(); baos.writeTo(sos); sos.flush(); } catch (Exception e) { LOG.error("error creating image file", e); } finally { try { baos.close(); sos.close(); } catch (Exception e1) { LOG.error("error closing output stream", e1); } } } } }
From source file:de.mpg.escidoc.pubman.statistic_charts.StatisticChartServlet.java
public synchronized void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String numberOfMonthsString = request.getParameter(numberOfMonthsParameterName); if (numberOfMonthsString == null) { numberOfMonths = 12;//from ww w . jav a2 s. com } else { numberOfMonths = Integer.parseInt(numberOfMonthsString); } String lang = request.getParameter(languageParameterName); if (lang == null) { this.language = "en"; } else { this.language = lang; } id = request.getParameter(idParameterName); type = request.getParameter(typeParameterName); try { CategoryDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); BufferedImage img = chart.createBufferedImage(630, 250); byte[] image = new KeypointPNGEncoderAdapter().encode(img); response.setContentType(CONTENT_TYPE); ServletOutputStream out = response.getOutputStream(); out.write(image); out.flush(); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:info.toegepaste.www.service.PdfServiceImpl.java
@Override public void exportPdf(File temp) throws FileNotFoundException, IOException { FacesContext fc = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse(); response.setHeader("Content-Disposition", "attachment; filename=rapport.pdf"); response.setContentLength((int) temp.length()); ServletOutputStream out = null; FileInputStream input = new FileInputStream(temp); byte[] buffer = new byte[1024]; out = response.getOutputStream();/*ww w . j a va2s. c o m*/ int i = 0; while ((i = input.read(buffer)) != -1) { out.write(buffer); out.flush(); } fc.responseComplete(); }
From source file:com.smartgwt.extensions.fileuploader.server.DownloadServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) { // url: /thinkspace/download/project/2/..... String path = request.getPathInfo(); String[] items = path.split("/"); if (items.length < 3 || !items[1].equals("project")) { // if no path info then nothing can be downloaded reportError(response);//from w w w . j a v a2s.c om return; } InputStream in = null; try { int pid = Integer.parseInt(items[2]); /* Project project = ProjectService.get().getProjectById(pid); String contextName = project.getContext(); ProjectState state = (ProjectState) request.getSession().getAttribute(contextName); if (state == null) { // if no state then user has not authenticated reportError(response); return; } */ // only files in lib directories can be downloaded boolean hasPermission = false; for (int i = items.length - 1; i > 2; i--) { if (items[i].equals("lib")) { hasPermission = true; break; } } if (!hasPermission) { reportError(response); return; } /* File f = state.getFileManager().getFile(path); String type = ContentService.get().getContentType(path); response.setContentType(type); response.setContentLength((int)f.length()); response.setHeader("Content-Disposition", "inline; filename="+Util.encode(f.getName())); response.setHeader("Last-Modified",hdf.format(new Date(f.lastModified()))); in = new BufferedInputStream(new FileInputStream(f)); */ ServletOutputStream out = response.getOutputStream(); byte[] buf = new byte[8192]; int len = 0; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); out.flush(); } catch (Exception e) { reportError(response); log.error(e); } finally { if (in != null) try { in.close(); } catch (Exception e) { } ; } }