List of usage examples for javax.servlet ServletOutputStream close
public void close() throws IOException
From source file:pivotal.au.se.gemfirexdweb.controller.DiskStoreController.java
@RequestMapping(value = "/diskstores", method = RequestMethod.POST) public String performDiskStoreAction(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {/*from ww w . j a v a 2 s . c o m*/ Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } int startAtIndex = 0, endAtIndex = 0; Result result = new Result(); List<DiskStore> dsks = null; String ddlString = null; logger.debug("Received request to perform an action on the disk stores"); DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO(); if (request.getParameter("search") != null) { dsks = dsDAO.retrieveDiskStoreList("", (String) request.getParameter("search"), (String) session.getAttribute("user_key")); model.addAttribute("search", (String) request.getParameter("search")); } else { String[] tableList = request.getParameterValues("selected_ds[]"); String commandStr = request.getParameter("submit_mult"); logger.debug("tableList = " + Arrays.toString(tableList)); logger.debug("command = " + commandStr); // start actions now if tableList is not null if (tableList != null) { List al = new ArrayList<Result>(); List<String> al2 = new ArrayList<String>(); for (String table : tableList) { if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) { ddlString = dsDAO.generateDDL(table, (String) session.getAttribute("user_key")); al2.add(ddlString); } else { result = null; result = dsDAO.simplediskStoreCommand(table, commandStr, (String) session.getAttribute("user_key")); al.add(result); } } if (commandStr.equalsIgnoreCase("DDL")) { request.setAttribute("arrayresultddl", al2); } else if (commandStr.equalsIgnoreCase("DDL_FILE")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, "DiskStoreDDL")); ServletOutputStream out = response.getOutputStream(); for (String ddl : al2) { out.println(ddl); } out.close(); return null; } else { model.addAttribute("arrayresult", al); } } dsks = dsDAO.retrieveDiskStoreList("", null, (String) session.getAttribute("user_key")); } model.addAttribute("records", dsks.size()); model.addAttribute("estimatedrecords", dsks.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (dsks.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("diskstores", dsks); } else { if (request.getParameter("startAtIndex") != null) { startAtIndex = Integer.parseInt(request.getParameter("startAtIndex")); } if (request.getParameter("endAtIndex") != null) { endAtIndex = Integer.parseInt(request.getParameter("endAtIndex")); if (endAtIndex > dsks.size()) { endAtIndex = dsks.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = dsks.subList(startAtIndex, endAtIndex); model.addAttribute("diskstores", subList); } model.addAttribute("startAtIndex", startAtIndex); model.addAttribute("endAtIndex", endAtIndex); // This will resolve to /WEB-INF/jsp/diskstores.jsp return "diskstores"; }
From source file:pivotal.au.se.gemfirexdweb.controller.HdfsStoreController.java
@RequestMapping(value = "/hdfsstores", method = RequestMethod.POST) public String performHdfsStoreAction(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {/*w ww . ja v a 2s . com*/ Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } int startAtIndex = 0, endAtIndex = 0; Result result = new Result(); List<HdfsStore> hdfsStores = null; String ddlString = null; logger.debug("Received request to perform an action on the hdfs stores"); HdfsStoreDAO hdfsDAO = GemFireXDWebDAOFactory.getHdfsStoreDAO(); if (request.getParameter("search") != null) { hdfsStores = hdfsDAO.retrieveHdfsStoreList("", (String) request.getParameter("search"), (String) session.getAttribute("user_key")); model.addAttribute("search", (String) request.getParameter("search")); } else { String[] tableList = request.getParameterValues("selected_hdfs[]"); String commandStr = request.getParameter("submit_mult"); logger.debug("tableList = " + Arrays.toString(tableList)); logger.debug("command = " + commandStr); // start actions now if tableList is not null if (tableList != null) { List al = new ArrayList<Result>(); List<String> al2 = new ArrayList<String>(); for (String table : tableList) { if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) { ddlString = hdfsDAO.generateDDL(table, (String) session.getAttribute("user_key")); al2.add(ddlString); } else { result = null; result = hdfsDAO.simplehdfsStoreCommand(table, commandStr, (String) session.getAttribute("user_key")); al.add(result); } } if (commandStr.equalsIgnoreCase("DDL")) { request.setAttribute("arrayresultddl", al2); } else if (commandStr.equalsIgnoreCase("DDL_FILE")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, "HDFSStoreDDL")); ServletOutputStream out = response.getOutputStream(); for (String ddl : al2) { out.println(ddl); } out.close(); return null; } else { model.addAttribute("arrayresult", al); } } hdfsStores = hdfsDAO.retrieveHdfsStoreList("", null, (String) session.getAttribute("user_key")); } model.addAttribute("records", hdfsStores.size()); model.addAttribute("estimatedrecords", hdfsStores.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (hdfsStores.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("hdfsstores", hdfsStores); } else { if (request.getParameter("startAtIndex") != null) { startAtIndex = Integer.parseInt(request.getParameter("startAtIndex")); } if (request.getParameter("endAtIndex") != null) { endAtIndex = Integer.parseInt(request.getParameter("endAtIndex")); if (endAtIndex > hdfsStores.size()) { endAtIndex = hdfsStores.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = hdfsStores.subList(startAtIndex, endAtIndex); model.addAttribute("hdfsstores", subList); } model.addAttribute("startAtIndex", startAtIndex); model.addAttribute("endAtIndex", endAtIndex); // This will resolve to /WEB-INF/jsp/hdfsstores.jsp return "hdfsstores"; }
From source file:pivotal.au.se.gemfirexdweb.controller.AsyncController.java
@RequestMapping(value = "/asyncevent", method = RequestMethod.POST) public String performAsyncAction(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {//ww w .j av a 2s . c o m Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } int startAtIndex = 0, endAtIndex = 0; Result result = new Result(); List<Asyncevent> asyncevents = null; String ddlString = null; logger.debug("Received request to perform an action on the async events"); AsynceventDAO asyncDAO = GemFireXDWebDAOFactory.getAsynceventDAO(); if (request.getParameter("search") != null) { asyncevents = asyncDAO.retrieveAsynceventList((String) session.getAttribute("schema"), (String) request.getParameter("search"), (String) session.getAttribute("user_key")); model.addAttribute("search", (String) request.getParameter("search")); } else { String[] tableList = request.getParameterValues("selected_async[]"); String commandStr = request.getParameter("submit_mult"); logger.debug("tableList = " + Arrays.toString(tableList)); logger.debug("command = " + commandStr); // start actions now if tableList is not null if (tableList != null) { List al = new ArrayList<Result>(); List<String> al2 = new ArrayList<String>(); for (String asyncName : tableList) { if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) { ddlString = asyncDAO.generateDDL(asyncName, (String) session.getAttribute("user_key")); al2.add(ddlString); } else { result = null; result = asyncDAO.simpleasynceventCommand(asyncName, commandStr, (String) session.getAttribute("user_key")); al.add(result); } } if (commandStr.equalsIgnoreCase("DDL")) { request.setAttribute("arrayresultddl", al2); } else if (commandStr.equalsIgnoreCase("DDL_FILE")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, "AsyncEventListenerDDL")); ServletOutputStream out = response.getOutputStream(); for (String ddl : al2) { out.println(ddl); } out.close(); return null; } else { model.addAttribute("arrayresult", al); } } asyncevents = asyncDAO.retrieveAsynceventList((String) session.getAttribute("schema"), null, (String) session.getAttribute("user_key")); } model.addAttribute("records", asyncevents.size()); model.addAttribute("estimatedrecords", asyncevents.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (asyncevents.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("asyncevents", asyncevents); } else { if (request.getParameter("startAtIndex") != null) { startAtIndex = Integer.parseInt(request.getParameter("startAtIndex")); } if (request.getParameter("endAtIndex") != null) { endAtIndex = Integer.parseInt(request.getParameter("endAtIndex")); if (endAtIndex > asyncevents.size()) { endAtIndex = asyncevents.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = asyncevents.subList(startAtIndex, endAtIndex); model.addAttribute("asyncevents", subList); } model.addAttribute("startAtIndex", startAtIndex); model.addAttribute("endAtIndex", endAtIndex); // This will resolve to /WEB-INF/jsp/async.jsp return "async"; }
From source file:com.rplt.studioMusik.controller.OperatorController.java
@RequestMapping(value = "/cetakNota", method = RequestMethod.GET) public String cetakNota(HttpServletResponse response) { Connection conn = DatabaseConnection.getmConnection(); // File reportFile = new File(application.getRealPath("Coba.jasper"));//your report_name.jasper file File reportFile = new File( servletConfig.getServletContext().getRealPath("/resources/report/nota_persewaan.jasper")); Map parameters = new HashMap(); Map<String, Object> params = new HashMap<String, Object>(); params.put("P_KODESEWA", request.getParameter("kodeSewa")); byte[] bytes = null; try {//from ww w. j a v a 2s. c o m bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), params, conn); } catch (JRException ex) { Logger.getLogger(OperatorController.class.getName()).log(Level.SEVERE, null, ex); } response.setContentType("application/pdf"); response.setContentLength(bytes.length); try { ServletOutputStream outStream = response.getOutputStream(); outStream.write(bytes, 0, bytes.length); outStream.flush(); outStream.close(); } catch (IOException ex) { Logger.getLogger(MemberController.class.getName()).log(Level.SEVERE, null, ex); } return "halaman-cetakNota-operator"; }
From source file:gov.utah.dts.sdc.actions.StudentSearchAction.java
private void pdfOut(byte[] contents, String fileName) throws Exception { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); ServletOutputStream out = response.getOutputStream(); out.write(contents);/*w w w .j a v a 2s . c o m*/ out.flush(); out.close(); }
From source file:org.dataconservancy.ui.api.DataItemController.java
@RequestMapping(value = "/{idpart}", method = RequestMethod.GET) public void handleDataItemGetRequest(@RequestHeader(value = "Accept", required = false) String mimeType, @RequestHeader(value = "If-Match", required = false) String ifMatch, @RequestHeader(value = "If-None-Match", required = false) String ifNoneMatch, @RequestHeader(value = "If-Modified-Since", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date modifiedSince, HttpServletRequest request, HttpServletResponse response) throws IOException, ArchiveServiceException, BizPolicyException { // Check to see if the user is authenticated (TODO: have Spring Security be responsible for this?) // Note that the fact that the user has to be authenticated, and further authorized, is a policy decision, // but the pattern for the Project and Person controllers is that the Controller has handled this. final Person authenticatedUser = getAuthenticatedUser(); // Rudimentary Accept Header handling; accepted values are */*, application/*, application/xml, // application/octet-stream if (mimeType != null && !(mimeType.contains(APPLICATION_XML) || mimeType.contains(ACCEPT_WILDCARD) || mimeType.contains(ACCEPT_APPLICATION_WILDCARD) || mimeType.contains(ACCEPT_OCTET_STREAM))) { response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE, "Unacceptable value for 'Accept' header: '" + mimeType + "'"); return;/*from ww w . ja v a 2s .c o m*/ } // Resolve the Request URL to the ID of the DataItem (in this case URL == ID) String dataItemId = requestUtil.buildRequestUrl(request); if (dataItemId == null || dataItemId.trim().isEmpty()) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } // Get the DataItem final DataItem dataItem = getDataItem(dataItemId); // Calculate the ETag for the DataItem, may be null. final String etag; if (dataItem != null) { etag = calculateEtag(dataItem); } else { etag = null; } // Handle the 'If-Match' header first; RFC 2616 14.24 if (this.responseHeaderUtil.handleIfMatch(request, response, this.requestUtil, ifMatch, dataItem, etag, dataItemId, "DataItem")) { return; } final DateTime lastModified; if (dataItem != null) { lastModified = getLastModified(dataItem.getId()); } else { lastModified = null; } // Handle the 'If-None-Match' header; RFC 2616 14.26 if (this.responseHeaderUtil.handleIfNoneMatch(request, response, ifNoneMatch, dataItem, etag, dataItemId, lastModified, modifiedSince)) { return; } if (dataItem == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Handle the 'If-Modified-Since' header; RFC 2616 14.26 if (this.responseHeaderUtil.handleIfModifiedSince(request, response, modifiedSince, lastModified)) { return; } // Check to see if the user is authorized if (!authzService.canRetrieveDataSet(authenticatedUser, dataItem)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } // Compose the Business Object Package Bop businessPackage = new Bop(); businessPackage.addDataItem(dataItem); // Serialize the package to an output stream ByteArrayOutputStream out = new ByteArrayOutputStream(); bob.buildBusinessObjectPackage(businessPackage, out); out.close(); // Compose the Response (headers, entity body) this.responseHeaderUtil.setResponseHeaderFields(response, etag, out, lastModified); // Send the Response final ServletOutputStream servletOutputStream = response.getOutputStream(); IOUtils.copy(new ByteArrayInputStream(out.toByteArray()), servletOutputStream); servletOutputStream.flush(); servletOutputStream.close(); }
From source file:net.sourceforge.hunterj.javadocViewer.JavadocViewerServlet.java
/** * //w ww .j a va2 s .c o m * @param response * @param url * @throws IOException */ private void doGetRemoteResource(HttpServletResponse response, String url) throws IOException { URL remoteResource = new URL(url); try (BufferedInputStream in = new BufferedInputStream(remoteResource.openStream())) { int length = -1; int bufferSize = 1024 * 2; byte[] buffer = new byte[bufferSize]; ServletOutputStream out = response.getOutputStream(); while ((length = in.read(buffer)) != -1) { out.write(buffer, 0, length); } in.close(); out.close(); } }
From source file:com.labimo.portlet.DownloadServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String hardwareUuid = request.getParameter("hardwareUuid"); String licenseUuid = request.getParameter("licenseUuid"); String fileName = "license.txt"; License license = null;//from w w w. ja v a 2 s . c o m try { license = LicenseLocalServiceUtil.getLicense(licenseUuid); if (license != null && license.getValid()) { response.setHeader("Content-Type", "application/octet-stream"); ServletOutputStream servletOutputStream = response.getOutputStream(); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); IOUtils.write(LicenseUtils.getChargesLicenseContent(hardwareUuid, license.getIssueDate(), license.getValidDate()), servletOutputStream); servletOutputStream.flush(); servletOutputStream.close(); } } catch (Exception e) { e.printStackTrace(); } /* * String activationId = "1a508567-61f9-3e5a-8923-b27ca6d00028"; String * fileName = "license.txt"; List<Activation> activationList = * LicenseUtils * .getActivationListByLicenseUuid("4091a61b-4b3d-46b9-890d-2a3e63f09d3c" * ); if (activationList != null && activationList.size() > 0) { // * License license = // LicenseLocalServiceUtil.getLicense(licenseUuid); * License license = null; try { license = LicenseLocalServiceUtil * .getLicense("4091a61b-4b3d-46b9-890d-2a3e63f09d3c"); } catch * (PortalException e) { // TODO Auto-generated catch block * e.printStackTrace(); } catch (SystemException e) { // TODO * Auto-generated catch block e.printStackTrace(); } * System.out.println("getIssueDate = " + license.getIssueDate()); * System.out.println("getValidDate = " + license.getValidDate()); * System.out.println("getValid = " + license.getValid()); if * (license.getValid()) { response.setHeader("Content-Type", * "application/octet-stream"); ServletOutputStream servletOutputStream * = response .getOutputStream(); * response.setHeader("Content-Disposition", "attachment; filename=\"" + * fileName + "\""); * * try { IOUtils.write(LicenseUtils.getChargesLicenseContent( * activationId, license.getIssueDate(), license.getValidDate()), * servletOutputStream); } catch (Exception e) { // TODO Auto-generated * catch block e.printStackTrace(); } servletOutputStream.flush(); * servletOutputStream.close(); * * } } */ }
From source file:org.bigbluebuttonproject.fileupload.web.FileUploadController.java
/** * This handler method overwriting the method in MultiActionController. * Its purpose is to stream slide XML from server to the HTTP response. * It writes the response using HttpServletResponse. * //w w w. j av a 2s. c o m * @param request HttpServletRequest * @param response HttpServletResponse where the Slide XML is sent * * @return the xml slides * * @throws Exception the exception */ public ModelAndView getXmlSlides(HttpServletRequest request, HttpServletResponse response) throws Exception { Integer room = new Integer(request.getParameterValues("room")[0]); logger.info("Getting XML Slides [" + room + "]"); logger.info("Servlet Path = [" + request.getServletPath() + "]"); logger.info("Host = [" + request.getServerName() + ":" + request.getServerPort() + "]"); logger.info("Request URI = [" + request.getRequestURI() + "]"); logger.info("Request URL = [" + request.getRequestURL() + "]"); // get URL from client request int lastIndex = request.getRequestURL().lastIndexOf("/"); String url = request.getRequestURL().substring(0, lastIndex); // create slide presentation descriptor XML String slidesXml = createXml(url, getSlidesForRoom(room)); // String slidesXml = this.slideDatabase.getSlidesInXml(room); logger.info("XML Slides = " + slidesXml); // before sending the xml string to the client, // set content type and header response.setContentType("text/xml"); //Ask browser not to chache images response.setHeader("Cache-Control", "no-cache"); // get ServletOutputStream from HttpServletResponse ServletOutputStream out = response.getOutputStream(); // send the xml string to client out.print(slidesXml); out.flush(); out.close(); return null; }
From source file:org.opentaps.common.event.PaginationEvents.java
/** * Download an existing Excel file from the ${opentaps_home}/runtime/output * directory. The Excel file is deleted after the download. * * @param filename the file name String object * @param request a <code>HttpServletRequest</code> value * @param response a <code>HttpServletResponse</code> value * @return a <code>String</code> value *///from w ww . j a v a 2s . c om private static String downloadExcel(String filename, HttpServletRequest request, HttpServletResponse response) { File file = null; ServletOutputStream out = null; FileInputStream fileToDownload = null; try { out = response.getOutputStream(); file = new File(UtilCommon.getAbsoluteFilePath(request, filename)); fileToDownload = new FileInputStream(file); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=" + filename); response.setContentLength(fileToDownload.available()); int c; while ((c = fileToDownload.read()) != -1) { out.write(c); } out.flush(); } catch (FileNotFoundException e) { Debug.logError("Failed to open the file: " + filename, MODULE); return "error"; } catch (IOException ioe) { Debug.logError("IOException is thrown while trying to download the Excel file: " + ioe.getMessage(), MODULE); return "error"; } finally { try { out.close(); if (fileToDownload != null) { fileToDownload.close(); // Delete the file under /runtime/output/ this is optional file.delete(); } } catch (IOException ioe) { Debug.logError("IOException is thrown while trying to download the Excel file: " + ioe.getMessage(), MODULE); return "error"; } } return "success"; }