List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:pt.sapo.pai.vip.VipServlet.java
private void processRequest(HttpServletRequest request, HttpServletResponse response, Supplier<HttpRequestBase> supplier) throws ServletException, IOException { try (OutputStream out = response.getOutputStream(); CloseableHttpClient http = builder.build()) { Optional.ofNullable(servers[rand.nextInt(2)]).map(server -> server.split(":")) .map(parts -> Tuple.of(parts[0], Integer.valueOf(parts[1]))).ifPresent(server -> { try { HttpRequestBase method = supplier.get(); method.setURI(new URI(request.getScheme(), null, server._1, server._2, request.getRequestURI(), request.getQueryString(), null)); HttpResponse rsp = http.execute(method); Collections.list(request.getHeaderNames()) .forEach(name -> Collections.list(request.getHeaders(name)) .forEach(value -> method.setHeader(name, value))); response.setStatus(rsp.getStatusLine().getStatusCode()); response.setContentType(rsp.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue()); IOUtils.copy(rsp.getEntity().getContent(), out); } catch (IOException | URISyntaxException ex) { log.error(null, ex); }/*from w w w . j a v a 2 s . c o m*/ }); } }
From source file:de.mpg.imeji.presentation.upload.UploadServlet.java
private void writeResponse(HttpServletResponse resp, String errorMessage) throws IOException { resp.getOutputStream().write(("<error>" + errorMessage + "</error>").getBytes(Charset.forName("UTF-8"))); }
From source file:com.sonicle.webtop.core.app.servlet.response.GZippableOutputStream.java
public GZippableOutputStream(HttpServletResponse response) throws IOException { super();//from w w w . j a v a 2s . c om this.response = response; outputStream = response.getOutputStream(); }
From source file:com.devnexus.ting.web.controller.SpeakerController.java
@RequestMapping(value = "/s/speakers/{speakerId}.jpg", method = RequestMethod.GET) public void getSpeakerPicture(@PathVariable("speakerId") Long speakerId, HttpServletResponse response) { byte[] speakerImage = businessService.getSpeakerImage(speakerId); try {/* ww w. jav a 2s.c o m*/ org.apache.commons.io.IOUtils.write(speakerImage, response.getOutputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } response.setContentType("image/jpg"); }
From source file:org.katzorke.cage.CageController.java
@RequestMapping("/cage/gcaptcha") public void gcaptcha(HttpSession session, HttpServletResponse response) throws IOException { CaptchaToken captchaToken = new CaptchaToken(gcage.getTokenGenerator().next()); session.setAttribute("gcageToken", captchaToken); OutputStream os = response.getOutputStream(); try {//from ww w . j a va 2 s .c o m gcage.draw(captchaToken.token, os); } finally { os.close(); } }
From source file:org.katzorke.cage.CageController.java
@RequestMapping("/cage/ycaptcha") public void ycaptcha(HttpSession session, HttpServletResponse response) throws IOException { CaptchaToken captchaToken = new CaptchaToken(ycage.getTokenGenerator().next()); session.setAttribute("ycageToken", captchaToken); OutputStream os = response.getOutputStream(); try {/*from w w w . j a v a2 s . co m*/ ycage.draw(captchaToken.token, os); } finally { os.close(); } }
From source file:org.openmeetings.servlet.outputhandler.BackupExportFacade.java
@Override protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { try {/* www .jav a 2s . c o m*/ if (getBackupExport() == null) { OutputStream out = httpServletResponse.getOutputStream(); String msg = "Server is not booted yet"; out.write(msg.getBytes()); out.flush(); out.close(); return; } getBackupExport().service(httpServletRequest, httpServletResponse, getServletContext()); } catch (Exception er) { log.error("ERROR ", er); log.debug("Error exporting: " + er); er.printStackTrace(); } }
From source file:DeleteBlobFromServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Connection conn = null;// ww w.j ava 2s . c om PreparedStatement pstmt = null; String id = "0001"; ServletOutputStream out = response.getOutputStream(); response.setContentType("text/html"); out.println("<html><head><title>Delete Photo</title></head>"); try { conn = getHSQLConnection(); pstmt = conn.prepareStatement("delete from MyPictures where id = ?"); pstmt.setString(1, id); pstmt.executeUpdate(); out.println("<body><h3>deleted photo with id=" + id + "</h3></body></html>"); } catch (Exception e) { out.println("<body><h1>Error=" + e.getMessage() + "</h1></body></html>"); } finally { try { pstmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:com.nominanuda.springmvc.HttpEntityView.java
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType(getContentType()); InputStream is = entity.getContent(); byte[] b = io.readAndClose(is); response.setContentLength(b.length); response.getOutputStream().write(b); }
From source file:org.magnum.dataup.VideoService.java
@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.GET) public HttpServletResponse getData(@PathVariable("id") long id, HttpServletResponse response) { Video v = videos.get(id);// w w w .j av a 2 s.c o m ServletOutputStream out = null; try { out = response.getOutputStream(); } catch (Exception e) { sendError(response, 500, "Internal error."); } try { vfm.copyVideoData(v, out); out.flush(); } catch (Exception e) { sendError(response, 404, "Video data could not be found."); } return response; }