List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:com.turn.splicer.ConfigServlet.java
private void doGetWork(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("application/json"); JsonGenerator generator = new JsonFactory().createGenerator(response.getOutputStream(), JsonEncoding.UTF8); Config.get().writeAsJson(generator); generator.close();/*w ww . j a v a 2s . c o m*/ }
From source file:org.zalando.logbook.servlet.example.ExampleController.java
@RequestMapping(value = "/stream", produces = MediaType.TEXT_PLAIN_VALUE) public void stream(final HttpServletRequest request, final HttpServletResponse response) throws IOException { ByteStreams.copy(request.getInputStream(), response.getOutputStream()); }
From source file:org.iwethey.forums.web.json.FastJsonView.java
public void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws ServletException { try {/*from www . j a v a 2s .c o m*/ OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream()); Object data = model.get("json"); Object serTmp = model.get("serializer"); JacksonSerializer ser = null; if (serTmp != null && JacksonSerializer.class.isAssignableFrom(serTmp.getClass())) { ser = (JacksonSerializer) serTmp; } else { ser = new JacksonSerializer(); } if (data != null) { ser.serialize(data, out); } out.flush(); } catch (IOException ie) { throw new ServletException(ie); } catch (JsonException e) { throw new ServletException(e); } }
From source file:com.mycompany.capstone.controllers.ImageController.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody//from www . j a va2 s . c o m public void showImage(@PathVariable("id") Integer imageId, HttpServletResponse response, HttpServletRequest request) throws IOException { Image apImage = adminPageImageDao.get(imageId); response.getOutputStream().write(apImage.getImageData()); response.getOutputStream().close(); }
From source file:io.apicurio.studio.fe.servlet.servlets.ReadyServlet.java
/** * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///www . j av a2 s . c o m @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setHeader("Content-Type", "application/json"); IOUtils.copy(new StringReader("{ \"up\": true }"), resp.getOutputStream()); resp.getOutputStream().flush(); }
From source file:io.github.jass2125.pesoa.jpa.core.servlets.RegisterImageServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//ww w . j a v a 2 s.c o m byte img[] = getImage(request); response.getOutputStream().write(img); response.getOutputStream().flush(); manager.add(new Images(img)); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.bermuda.arquillian.example.ContentTypeProxyServlet.java
private void copyResponseContent(HttpServletResponse resp, HttpMethod post) throws IOException { OutputStream out = resp.getOutputStream(); InputStream input = post.getResponseBodyAsStream(); StringBuilder responseBody = new StringBuilder(); byte[] buffer = new byte[1024]; while (input.read(buffer) >= 0) { responseBody.append(new String(buffer)); out.write(buffer);//from ww w. jav a 2s . co m } requestLogger.info("ResponseBody: " + responseBody.toString()); }
From source file:com.xumpy.timesheets.controller.pages.TimesheetsCtrl.java
@RequestMapping(value = "timesheets/printTimesheet", method = RequestMethod.GET) public @ResponseBody ResponseEntity<byte[]> fetchDocumentBlob(@RequestParam Integer jobsGroupId, @RequestParam String month, HttpServletResponse response) throws IOException { OutputStream out = response.getOutputStream(); response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "inline;filename=\"timesheet.pdf\""); out = timesheetSrv.getTimesheet(jobsGroupId, month, out); out.flush();// www . jav a 2 s . c om out.close(); return null; }
From source file:net.sf.jsfcomp.chartcreator.Chartlet.java
private void writeChart(HttpServletResponse response, JFreeChart chart, ChartData chartData) throws IOException { OutputStream stream = response.getOutputStream(); response.setContentType(ChartUtils.resolveContentType(chartData.getOutput())); if (chartData.getOutput().equalsIgnoreCase("png")) ChartUtilities.writeChartAsPNG(stream, chart, chartData.getWidth(), chartData.getHeight()); else if (chartData.getOutput().equalsIgnoreCase("jpeg")) ChartUtilities.writeChartAsJPEG(stream, chart, chartData.getWidth(), chartData.getHeight()); stream.flush();/*from w ww .j ava 2 s . c o m*/ stream.close(); }
From source file:eu.europa.ejusticeportal.dss.controller.action.ActionHandlerTest.java
private HttpServletResponse getResponse(final OutputStream os) throws IOException { HttpServletResponse response = Mockito.mock(HttpServletResponse.class); Mockito.when(response.getOutputStream()).thenReturn(new ServletOutputStreamImpl(os)); return response; }