List of usage examples for javax.servlet ServletOutputStream close
public void close() throws IOException
From source file:CounterServer.java
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(true); int count = 1; Integer i = (Integer) session.getAttribute(COUNTER_KEY); if (i != null) { count = i.intValue() + 5;//from w w w . j a v a 2 s. co m } session.setAttribute(COUNTER_KEY, new Integer(count)); DataInputStream in = new DataInputStream(req.getInputStream()); resp.setContentType("application/octet-stream"); ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(byteOut); out.writeInt(count); out.flush(); byte[] buf = byteOut.toByteArray(); resp.setContentLength(buf.length); ServletOutputStream servletOut = resp.getOutputStream(); servletOut.write(buf); servletOut.close(); }
From source file:it.cilea.osd.jdyna.web.controller.AutocompleteUsersView.java
protected void renderMergedOutputModel(Map model, HttpServletRequest httpServletRequest, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); List<DTOAutocomplete> users = (List<DTOAutocomplete>) model.get("result"); String xml = new AjaxXmlBuilder().addItems(users, "display", "id", true).toString(); ServletOutputStream out = response.getOutputStream(); out.print(xml);//from w w w . j av a 2s. c o m out.close(); }
From source file:test.be.fedict.eid.applet.XmlSignatureServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug("doGet"); HttpSession httpSession = request.getSession(); String documentStr = (String) httpSession.getAttribute("xmlDocument"); response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1 response.setHeader("Pragma", "no-cache, no-store"); // http 1.0 response.setDateHeader("Expires", -1); ServletOutputStream out = response.getOutputStream(); out.write(documentStr.getBytes());//from w w w. j a v a 2s. c o m out.close(); }
From source file:werecloud.api.view.StringView.java
@Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { if (model.containsKey("string")) { String data = model.get("string").toString(); byte[] _data = data.getBytes(); response.setContentType(getContentType()); response.setContentLength(_data.length); ServletOutputStream out = response.getOutputStream(); out.write(_data);//from ww w .j ava2 s. co m out.flush(); out.close(); return; } throw new Exception("Could not find model."); }
From source file:P5MX.Components.java
public static void ImportFile(HttpServletRequest request, HttpServletResponse response) { System.out.println("file"); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); ServletOutputStream out = null; Integer UserId = 0;//from w w w .j ava2 s . c o m FileBLL fx = new FileBLL(); try { List items = upload.parseRequest(request); Iterator iter = items.iterator(); response.setContentType("text/html"); out = response.getOutputStream(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { UserId = Integer.valueOf(item.getString()); System.out.println("[ name :> " + item.getFieldName() + " ]"); System.out.println("[ value :> " + item.getString() + " ]"); } else { fx.setFilename(item.getName().split("\\.")[0]); fx.setFiletype(item.getName().split("\\.")[1]); fx.setData(item.get()); fx.setSize((int) item.getSize()); } } out.close(); } catch (FileUploadException | IOException fue) { } Integer FileId = InsertFile(fx); // file = SelectFileByName(file.getFilename()); System.out.println("[ generatedKey :: " + FileId + " ]"); AccessBLL ax = new AccessBLL(UserId, FileId); AccessDAL.GrantAccess(ax); TagDAL.InsertTag(new TagBLL(FileId, "Local")); System.out.println("Granted access!"); }
From source file:org.onebusaway.nyc.vehicle_tracking.webapp.servlets.VehicleLocationCollectionServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { BufferedReader reader = req.getReader(); StringBuffer out = new StringBuffer(); char[] buf = new char[4096]; while (true) { int n = reader.read(buf); if (n == -1) { break; }//from ww w . j a v a 2 s. com out.append(new String(buf, 0, n)); } String body = out.toString(); Siri siri = (Siri) _xstream.fromXML(body); _vehicleLocationService.handleVehicleLocation(siri, body); resp.setStatus(200); resp.setContentType("text/html;charset=UTF-8"); ServletOutputStream writer = resp.getOutputStream(); writer.print("ok"); writer.close(); }
From source file:pt.ist.fenix.ui.struts.action.externalServices.ExternalInterfaceDispatchAction.java
protected void writeJSONObject(HttpServletResponse response, final JSONObject jsonObject) throws IOException { response.setContentType("application/json; charset=utf-8"); final ServletOutputStream outputStream = response.getOutputStream(); outputStream.write(jsonObject.toJSONString().getBytes()); outputStream.close(); }
From source file:org.inbio.common.web.controller.XMLResponseMultiActionController.java
/** * /*from w w w .jav a 2 s .co m*/ * @param request * @param response * @param doc * @return * @throws Exception */ public ModelAndView writeXMLDocumentOnResponse(HttpServletRequest request, HttpServletResponse response, Document doc) throws Exception { // return response XML XMLOutputter xmlOutputter = new XMLOutputter(); response.setCharacterEncoding(urlCharset); response.setContentType("text/xml;charset=" + urlCharset); ServletOutputStream out = response.getOutputStream(); // binary output xmlOutputter.output(doc, out); out.flush(); out.close(); return null; }
From source file:com.google.appinventor.server.WebAppLaunchServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String userId = userInfoProvider.getUserId(); String launchFile;//from w w w . jav a 2s . c o m try { String uri = req.getRequestURI(); // First, call split with no limit parameter. String[] uriComponents = uri.split("/"); String launchKind = uriComponents[REQUEST_INDEX]; if (launchKind.equals(ServerLayout.WEBAPP_FILE)) { uriComponents = uri.split("/", SPLIT_LIMIT_FILE); if (FILE_PATH_INDEX > uriComponents.length) { throw CrashReport.createAndLogError(LOG, req, null, new IllegalArgumentException("Missing web app file path.")); } String fileName = uriComponents[FILE_PATH_INDEX]; launchFile = storageIo.downloadUserFile(userId, fileName, "UTF-8"); } else { throw CrashReport.createAndLogError(LOG, req, null, new IllegalArgumentException("Unknown launch kind: " + launchKind)); } } catch (IllegalArgumentException e) { throw CrashReport.createAndLogError(LOG, req, null, e); } byte[] content = launchFile.getBytes(); // Set http response information resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/html"); resp.setContentLength(launchFile.length()); // Attach download data ServletOutputStream out = resp.getOutputStream(); out.write(content); out.close(); }
From source file:com.indeed.imhotep.web.SplitterServlet.java
@RequestMapping("/split") protected void doGet(final HttpServletRequest req, final HttpServletResponse resp, @RequestParam("q") String query) throws ServletException, IOException { resp.setContentType("application/json"); final ObjectMapper mapper = new ObjectMapper(); final ObjectNode json = mapper.createObjectNode(); QueryParts parts = null;//from w ww .j a v a 2 s .c o m try { parts = QuerySplitter.splitQuery(query); } catch (Exception e) { json.put("error", e.toString()); } if (parts != null) { json.put("from", parts.from); json.put("where", parts.where); json.put("groupBy", parts.groupBy); json.put("select", parts.select); json.put("limit", parts.limit); FromClause fromClause = null; try { fromClause = StatementParser.parseFromClause(parts.from); } catch (Exception ignored) { } json.put("dataset", fromClause != null ? fromClause.getDataset() : ""); json.put("start", fromClause != null ? fromClause.getStart().toString(dateTimeFormatter) : ""); json.put("end", fromClause != null ? fromClause.getEnd().toString(dateTimeFormatter) : ""); json.put("startRawString", fromClause != null ? fromClause.getStartRawString() : ""); json.put("endRawString", fromClause != null ? fromClause.getEndRawString() : ""); } final ServletOutputStream outputStream = resp.getOutputStream(); mapper.writeValue(outputStream, json); outputStream.close(); }