List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
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 ww . j ava 2s. c om*/ */ @RequestMapping(value = "/testdata/sample-generic1.json", method = RequestMethod.GET) public void sampleGeneric3(final HttpServletRequest request, final HttpServletResponse response) throws IOException { byte[] data = Resources.getResourceAsBytes("/testdata/sample-generic.json"); response.setContentType("application/json"); response.setContentLengthLong(data.length); IOUtils.write(data, response.getOutputStream()); }
From source file:jp.co.opentone.bsol.linkbinder.view.servlet.WebResourceServlet.java
protected void write(HttpServletResponse resp, String path) throws ServletException, IOException { InputStream in = getServletContext().getResourceAsStream(path); if (in != null) { try {/*ww w . j ava 2 s. com*/ OutputStream o = resp.getOutputStream(); byte[] b = new byte[4096]; int i = 0; while ((i = in.read(b, 0, b.length)) != -1) { o.write(b, 0, i); } } finally { in.close(); } } }
From source file:controllers.FeatureController.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=Feature.xls"); featureService.getXls().write(response.getOutputStream()); }
From source file:br.com.munif.personalsecurity.aplicacao.autorizacao.GenericTokenApi.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json;charset=UTF-8"); List<Usuario> todos = service.findAll(); Usuario usuario = todos.get(0);// w w w. j a v a 2 s. c o m mapper.writeValue(response.getOutputStream(), TokenAdapter.getLoginData(usuario)); }
From source file:org.openxdata.server.servlet.FormDownloadServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream os = response.getOutputStream(); try {/*from www . ja va2 s. c o m*/ String action = request.getParameter(OpenXDataConstants.REQUEST_PARAMETER_ACTION); if (action == null) formsServer.processConnection(request.getInputStream(), os); else { User user = authenticationService.authenticate( request.getParameter(OpenXDataConstants.REQUEST_PARAM_USERNAME), request.getParameter(OpenXDataConstants.REQUEST_PARAM_PASSWORD)); if (user == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); XformSerializer formSerializer = serializationService.getFormSerializer( request.getParameter(OpenXDataConstants.REQUEST_PARAM_FORM_SERIALIZER)); formSerializer.serializeAccessDenied(os); } else { if (OpenXDataConstants.REQUEST_ACTION_UPLOAD_DATA.equalsIgnoreCase(action)) { uploadData(request, response); String serializerKey = request .getParameter(OpenXDataConstants.REQUEST_PARAM_FORM_SERIALIZER); XformSerializer formSerializer = serializationService.getFormSerializer(serializerKey); formSerializer.serializeSuccess(os); } else if (OpenXDataConstants.REQUEST_ACTION_DOWNLOAD_FORMS.equalsIgnoreCase(action)) downloadForms(request, response); else if (OpenXDataConstants.ACTION_DOWNLOAD_STUDIES.equalsIgnoreCase(action)) downloadStudies(request, response); else if (OpenXDataConstants.REQUEST_ACTION_DOWNLOAD_USERS.equalsIgnoreCase(action)) downloadUsers(request, response); } } } catch (Exception ex) { try { String serializerKey = request.getParameter(OpenXDataConstants.REQUEST_PARAM_FORM_SERIALIZER); XformSerializer formSerializer = serializationService.getFormSerializer(serializerKey); formSerializer.serializeFailure(os, ex); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); } } }
From source file:com.impala.paga.all.QueryBalance.java
/** * /*from w ww . j av a 2s . c om*/ * @param request * @param response * @throws ServletException * , IOException */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream out = response.getOutputStream(); response.setContentType("text/plain;charset=UTF-8"); response.setDateHeader("Expires", new Date().getTime()); // Expiration // date response.setDateHeader("Date", new Date().getTime()); // Date and time try { // that the // message was // sent out.write(moneytransfer(request).getBytes()); } catch (JSONException ex) { Logger.getLogger(QueryBalance.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(QueryBalance.class.getName()).log(Level.SEVERE, null, ex); } out.flush(); out.close(); }
From source file:com.sifcoapp.report.util.ReportConfigUtil.java
public static void exportReportASPDF(JasperPrint jasperPrint, HttpServletResponse response) { //JasperExportManager exporter = null; JRExporter exporter = null;/*from w w w . j a v a 2 s . c om*/ String pdfName = "/reports/testReport.pdf"; try { /* exporter.exportReportToPdfFile(jasperPrint,pdfPath); ec.responseReset(); ec.setResponseContentType(ec.getMimeType(pdfPath)); //ec.setResponseContentLength(contentLength); ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + pdfName + "\""); InputStream input = new FileInputStream(pdfPath); OutputStream output = ec.getResponseOutputStream(); IOUtils.copy(input, output); System.out.println("Sending to browser..."); */ response.setContentType("application/pdf"); //if ("application/pdf".equals(type)) { exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream()); exporter.exportReport(); } catch (IOException ex) { Logger.getLogger(ReportConfigUtil.class.getName()).log(Level.SEVERE, null, ex); } catch (JRException ex) { Logger.getLogger(ReportConfigUtil.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.unc.lib.dl.ui.controller.DjatokaContentController.java
/** * Handles requests for individual region tiles. * //from www .j a v a 2 s . c o m * @param model * @param request * @param response */ @RequestMapping("/jp2Region/{id}/{datastream}") public void getRegion(@PathVariable("id") String id, @PathVariable("datastream") String datastream, @RequestParam("svc.region") String region, @RequestParam("svc.level") String scale, @RequestParam("svc.rotate") String rotate, HttpServletResponse response) { // Check if the user is allowed to view this object if (this.hasAccess(id, datastream)) { try { djatokaContentService.streamJP2(id, region, scale, rotate, datastream, response.getOutputStream(), response); } catch (IOException e) { LOG.error("Error retrieving streaming JP2 content for " + id, e); } } else { LOG.debug("Access was forbidden to " + id + " for user " + GroupsThreadStore.getUsername()); response.setStatus(HttpStatus.SC_FORBIDDEN); } }
From source file:net.sourceforge.subsonic.controller.AvatarController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { Avatar avatar = getAvatar(request);//from w w w . j av a2 s. c o m if (avatar == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; } response.setContentType(avatar.getMimeType()); response.getOutputStream().write(avatar.getData()); return null; }
From source file:org.apache.hadoop.gateway.dispatch.DefaultDispatchTest.java
@Test public void testJiraKnox58() throws URISyntaxException, IOException { URI uri = new URI("http://unreachable-host"); BasicHttpParams params = new BasicHttpParams(); HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpUriRequest.class); EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes(); EasyMock.expect(outboundRequest.getURI()).andReturn(uri).anyTimes(); EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes(); HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class); HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.expect(outboundResponse.getOutputStream()) .andAnswer(new IAnswer<SynchronousServletOutputStreamAdapter>() { @Override//from www . j ava 2 s.c om public SynchronousServletOutputStreamAdapter answer() throws Throwable { return new SynchronousServletOutputStreamAdapter() { @Override public void write(int b) throws IOException { throw new IOException("unreachable-host"); } }; } }); EasyMock.replay(outboundRequest, inboundRequest, outboundResponse); DefaultDispatch dispatch = new DefaultDispatch(); dispatch.setHttpClient(new DefaultHttpClient()); try { dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse); fail("Should have thrown IOException"); } catch (IOException e) { assertThat(e.getMessage(), not(containsString("unreachable-host"))); assertThat(e, not(instanceOf(UnknownHostException.class))); assertThat("Message needs meaningful content.", e.getMessage().trim().length(), greaterThan(12)); } }