List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:com.eviware.soapui.impl.rest.mock.RestMockActionTest.java
private RestMockRequest makeRestMockRequest() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); Enumeration enumeration = mock(Enumeration.class); when(request.getHeaderNames()).thenReturn(enumeration); HttpServletResponse response = mock(HttpServletResponse.class); ServletOutputStream os = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(os); WsdlMockRunContext context = mock(WsdlMockRunContext.class); return new RestMockRequest(request, response, context); }
From source file:org.eclipse.jgit.lfs.server.fs.ObjectDownloadListener.java
/** * @param repository//from w ww.ja v a 2 s. c om * the repository storing large objects * @param context * the servlet asynchronous context * @param response * the servlet response * @param id * id of the object to be downloaded * @throws IOException */ public ObjectDownloadListener(FileLfsRepository repository, AsyncContext context, HttpServletResponse response, AnyLongObjectId id) throws IOException { this.context = context; this.response = response; this.in = repository.getReadChannel(id); this.out = response.getOutputStream(); this.outChannel = Channels.newChannel(out); response.addHeader(HttpSupport.HDR_CONTENT_LENGTH, String.valueOf(repository.getSize(id))); response.setContentType(Constants.HDR_APPLICATION_OCTET_STREAM); }
From source file:org.reallysqs.server.views.QueueListView.java
@SuppressWarnings("unchecked") @Override/*ww w .j a v a 2 s.c o m*/ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); Map<String, Queue> queues = (Map<String, Queue>) model.get("queues"); Collection<Queue> queueList = queues.values(); ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(prelude); for (Queue queue : queueList) { outputStream.print("<QueueUrl>"); outputStream.print("http://" + request.getLocalName() + ":" + request.getLocalPort() + request.getContextPath() + request.getServletPath() + "/queues/" + queue.getName()); outputStream.print("</QueueUrl>"); } outputStream.print(epilogue); }
From source file:com.byd.test.actions.OrderAction.java
License:asdf
@RequestMapping("xopera") public ModelAndView xopera(HttpServletRequest request, HttpServletResponse response) { try {/*from www . j av a 2 s . c o m*/ OutputStream out = response.getOutputStream(); response.reset(); response.setHeader("content-disposition", "attachment;filename=" + "fileName.xls"); response.setContentType("application/x-octetstream;charset=gb2312"); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = null; String sheetName = "first sheet"; sheet = workbook.createSheet(sheetName); System.out.println("*-*-----------------------"); HSSFCell cell = sheet.createRow(1).createCell((short) 2); cell.setCellValue(323); workbook.write(out); out.flush(); out.close(); } catch (IOException ex) { Logger.getLogger(OrderAction.class.getName()).log(Level.SEVERE, null, ex); } String s = (String) request.getParameter("plantCode");//String a = request.getQueryString(""); System.out.println("plantCode: " + s); return new ModelAndView("myname"); }
From source file:com.xyxy.platform.examples.showcase.demos.web.StaticContentServlet.java
/** * Gzip HeaderGZIPOutputStream./*ww w .jav a 2 s. c o m*/ */ private OutputStream buildGzipOutputStream(HttpServletResponse response) throws IOException { response.setHeader("Content-Encoding", "gzip"); response.setHeader("Vary", "Accept-Encoding"); return new GZIPOutputStream(response.getOutputStream()); }
From source file:com.formkiq.web.config.TestDataController.java
/** * Provider Sample generic XML data with text/xml content type. * @param request {@link HttpServletRequest} * @param response {@link HttpServletResponse} * @throws IOException IOException/* w w w .j ava 2s . c om*/ */ @RequestMapping(value = "/testdata/sample-generic1.xml", method = RequestMethod.GET) public void sampleGeneric1(final HttpServletRequest request, final HttpServletResponse response) throws IOException { byte[] data = Resources.getResourceAsBytes("/testdata/sample-generic.xml"); response.setContentType("text/xml"); response.setContentLengthLong(data.length); IOUtils.write(data, response.getOutputStream()); }
From source file:org.apache.struts2.dispatcher.ChartResult.java
/** * Executes the result. Writes the given chart as a PNG or JPG to the servlet output stream. * * @param invocation an encapsulation of the action execution state. * @throws Exception if an error occurs when creating or writing the chart to the servlet output stream. */// w w w. j a v a 2s .c o m public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { initializeProperties(invocation); if (!chartSet) // if our chart hasn't been set (by the testcase), we'll look it up in the value stack chart = (JFreeChart) invocation.getStack().findValue(value, JFreeChart.class); if (chart == null) // we need to have a chart object - if not, blow up throw new NullPointerException("No JFreeChart object found on the stack with name " + value); // make sure we have some value for the width and height if (height == null) throw new NullPointerException("No height parameter was given."); if (width == null) throw new NullPointerException("No width parameter was given."); // get a reference to the servlet output stream to write our chart image to HttpServletResponse response = ServletActionContext.getResponse(); OutputStream os = response.getOutputStream(); try { // check the type to see what kind of output we have to produce if ("png".equalsIgnoreCase(type)) { response.setContentType("image/png"); ChartUtilities.writeChartAsPNG(os, chart, getIntValueFromString(width), getIntValueFromString(height)); } else if ("jpg".equalsIgnoreCase(type) || "jpeg".equalsIgnoreCase(type)) { response.setContentType("image/jpg"); ChartUtilities.writeChartAsJPEG(os, chart, getIntValueFromString(width), getIntValueFromString(height)); } else throw new IllegalArgumentException( type + " is not a supported render type (only JPG and PNG are)."); } finally { if (os != null) os.flush(); } }
From source file:controllers.CCOController.java
@RequestMapping("/getXls") public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=CARCOMPOPTION.xls"); carCompletionOptionService.getXls().write(response.getOutputStream()); }
From source file:org.fusesource.restygwt.examples.server.GreetingServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("Sending Hello World"); try {//from ww w. ja v a 2 s.c om ObjectMapper mapper = new ObjectMapper(); JsonNode helloJsonNode = mapper.readTree(helloWorldJson); mapper.writeValue(resp.getOutputStream(), helloJsonNode); } catch (Throwable e) { e.printStackTrace(); } finally { System.out.flush(); System.err.flush(); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.epfl.ExportPhdIndividualProgramProcessInformation.java
private void writeResponse(HttpServletResponse response, final byte[] presentationPage, final String contentType) throws IOException { final ServletOutputStream outputStream = response.getOutputStream(); response.setContentType(contentType); outputStream.write(presentationPage); outputStream.close();//w w w . j a v a2 s. c o m }