List of usage examples for javax.servlet ServletOutputStream println
public void println(double d) throws IOException
double
value to the client, followed by a carriage return-line feed (CRLF). From source file:org.openlaszlo.servlets.HistoryServlet.java
private void sendError(ServletOutputStream out, String error) { try {/*ww w .java 2 s .c om*/ out.println(error); } catch (IOException e) { } }
From source file:org.apache.jena.fuseki.ctl.ActionStats.java
private void statsTxt(ServletOutputStream out, DataAccessPoint desc) throws IOException { DataService dSrv = desc.getDataService(); out.println("Dataset: " + desc.getName()); out.println(" Requests = " + dSrv.getCounters().value(CounterName.Requests)); out.println(" Good = " + dSrv.getCounters().value(CounterName.RequestsGood)); out.println(" Bad = " + dSrv.getCounters().value(CounterName.RequestsBad)); out.println(" SPARQL Query:"); out.println(" Request = " + counter(dSrv, Operation.Query, CounterName.Requests)); out.println(" Good = " + counter(dSrv, Operation.Query, CounterName.RequestsGood)); out.println(" Bad requests = " + counter(dSrv, Operation.Query, CounterName.RequestsBad)); out.println(" Timeouts = " + counter(dSrv, Operation.Query, CounterName.QueryTimeouts)); out.println(" Bad exec = " + counter(dSrv, Operation.Query, CounterName.QueryExecErrors)); out.println(" IO Errors = " + counter(dSrv, Operation.Query, CounterName.QueryIOErrors)); out.println(" SPARQL Update:"); out.println(" Request = " + counter(dSrv, Operation.Update, CounterName.Requests)); out.println(" Good = " + counter(dSrv, Operation.Update, CounterName.RequestsGood)); out.println(" Bad requests = " + counter(dSrv, Operation.Update, CounterName.RequestsBad)); out.println(" Bad exec = " + counter(dSrv, Operation.Update, CounterName.UpdateExecErrors)); out.println(" Upload:"); out.println(" Requests = " + counter(dSrv, Operation.Upload, CounterName.Requests)); out.println(" Good = " + counter(dSrv, Operation.Upload, CounterName.RequestsGood)); out.println(" Bad = " + counter(dSrv, Operation.Upload, CounterName.RequestsBad)); out.println(" SPARQL Graph Store Protocol:"); out.println(" GETs = " + gspValue(dSrv, CounterName.HTTPget) + " (good=" + gspValue(dSrv, CounterName.HTTPgetGood) + "/bad=" + gspValue(dSrv, CounterName.HTTPgetBad) + ")"); out.println(" PUTs = " + gspValue(dSrv, CounterName.HTTPput) + " (good=" + gspValue(dSrv, CounterName.HTTPputGood) + "/bad=" + gspValue(dSrv, CounterName.HTTPputBad) + ")"); out.println(" POSTs = " + gspValue(dSrv, CounterName.HTTPpost) + " (good=" + gspValue(dSrv, CounterName.HTTPpostGood) + "/bad=" + gspValue(dSrv, CounterName.HTTPpostBad) + ")"); out.println(" PATCHs = " + gspValue(dSrv, CounterName.HTTPpatch) + " (good=" + gspValue(dSrv, CounterName.HTTPpatchGood) + "/bad=" + gspValue(dSrv, CounterName.HTTPpatchBad) + ")"); out.println(" DELETEs = " + gspValue(dSrv, CounterName.HTTPdelete) + " (good=" + gspValue(dSrv, CounterName.HTTPdeleteGood) + "/bad=" + gspValue(dSrv, CounterName.HTTPdeleteBad) + ")"); out.println(" HEADs = " + gspValue(dSrv, CounterName.HTTPhead) + " (good=" + gspValue(dSrv, CounterName.HTTPheadGood) + "/bad=" + gspValue(dSrv, CounterName.HTTPheadBad) + ")"); }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateAsyncController.java
@RequestMapping(value = "/createasync", method = RequestMethod.POST) public String createAsyncAction(@ModelAttribute("asyncAttribute") NewAsync asyncAttribute, 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 w ww.j av a2s.c om*/ 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; } } } logger.debug("Received request to action an event for create Async Event Listener"); DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO(); List<DiskStore> dsks = dsDAO.retrieveDiskStoreForCreateList((String) session.getAttribute("user_key")); model.addAttribute("diskstores", dsks); String asyncName = asyncAttribute.getAsyncName(); String listenerClass = asyncAttribute.getListenerClass(); logger.debug("New Async Event Listener Name = " + asyncName); logger.debug("New Async Event Listener Class = " + listenerClass); // perform some action here with what we have String submit = request.getParameter("pSubmit"); boolean needCloseBracket = false; if (submit != null) { // build create HDFS Store SQL StringBuffer createAsync = new StringBuffer(); createAsync.append("CREATE ASYNCEVENTLISTENER " + asyncName + " (\n"); createAsync.append("LISTENERCLASS '" + listenerClass + "' \n"); if (!checkIfParameterEmpty(request, "initParams")) { createAsync.append("INITPARAMS " + asyncAttribute.getInitParams() + " \n"); } else { createAsync.append("INITPARAMS '' \n"); } if (!checkIfParameterEmpty(request, "manualStart")) { createAsync.append("MANUALSTART " + asyncAttribute.getManualStart() + " \n"); } if (!checkIfParameterEmpty(request, "enableBatchConflation")) { createAsync.append("ENABLEBATCHCONFLATION " + asyncAttribute.getEnableBatchConflation() + " \n"); } if (!checkIfParameterEmpty(request, "batchSize")) { createAsync.append("BATCHSIZE " + asyncAttribute.getBatchSize() + " \n"); } if (!checkIfParameterEmpty(request, "batchTimeInterval")) { createAsync.append("BATCHTIMEINTERVAL " + asyncAttribute.getBatchTimeInterval() + " \n"); } if (!checkIfParameterEmpty(request, "enablePersistence")) { createAsync.append("ENABLEPERSISTENCE " + asyncAttribute.getEnablePersistence() + " \n"); if (asyncAttribute.getEnablePersistence().equals("TRUE")) { if (!checkIfParameterEmpty(request, "diskStore")) { createAsync.append("DISKSTORENAME " + asyncAttribute.getDiskStore() + " \n"); } } } if (!checkIfParameterEmpty(request, "maxQueueMemory")) { createAsync.append("MAXQUEUEMEMORY " + asyncAttribute.getMaxQueueMemory() + " \n"); } if (!checkIfParameterEmpty(request, "alertThreshold")) { createAsync.append("ALERTTHRESHOLD " + asyncAttribute.getAlertThreshold() + " \n"); } createAsync.append(") \n"); if (!checkIfParameterEmpty(request, "serverGroups")) { createAsync.append("SERVER GROUPS (" + asyncAttribute.getServerGroups() + ") \n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating async event listener as -> " + createAsync.toString()); result = GemFireXDWebDAOUtil.runCommand(createAsync.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create Async SQL as follows as -> " + createAsync.toString()); model.addAttribute("sql", createAsync.toString()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, asyncName)); ServletOutputStream out = response.getOutputStream(); out.println(createAsync.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/create-async.jsp return "create-async"; }
From source file:DisplayClobServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Clob fileAsCLOB = null;//from ww w . java2s . com Connection conn = null; Statement stmt = null; ResultSet rs = null; String id = "001"; String query = "select fileBody from DataFiles where id = " + id; ServletOutputStream out = response.getOutputStream(); // all responses will be in text/html format response.setContentType("text/html"); try { conn = getHSQLConnection(); } catch (Exception e) { out.println("<html><head><title>CLOB Example</title></head>"); out.println("<body><h4>Database Connection Problem.</h4>"); out.println("<h5>" + e.getMessage() + "</h5></body></html>"); return; } try { stmt = conn.createStatement(); rs = stmt.executeQuery(query); if (rs.next()) { fileAsCLOB = rs.getClob(1); } else { out.println("<html><head><title>CLOB Example</title></head>"); out.println("<body><h4>No file found for id=" + id + "</h4></body></html>"); return; } // Materialize the CLOB as a String object (get the whole clob). long length = fileAsCLOB.length(); // note that the first character is at position 1 String fileAsString = fileAsCLOB.getSubString(1, (int) length); // write it for display out.println(fileAsString); System.out.println("CLOB writing done."); } catch (SQLException e) { out.println("<html><head><title>Error: CLOB Example</title></head>"); out.println("<body><h4>Error=" + e.getMessage() + "</h4></body></html>"); return; } finally { try { rs.close(); stmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:org.apache.jena.fuseki.mgt.ActionDataset.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { // request.getRemoteUser() ; // request.getUserPrincipal() ; String dataset = FusekiLib.safeParameter(request, "dataset"); HttpSession session = request.getSession(true); session.setAttribute("dataset", dataset); session.setMaxInactiveInterval(15 * 60); // 10 mins boolean known = DatasetRegistry.get().isRegistered(dataset); if (!known) { response.sendError(HttpSC.BAD_REQUEST_400, "No such dataset: " + dataset); return;//from www . j a v a2 s . co m } if (true) { // Redirect to GET page. response.setHeader(HttpNames.hLocation, PageNames.pageAfterLogin); response.setStatus(HttpSC.SEE_OTHER_303); } else { // Welcome style - but HTML inline :-( response.setContentType("text/html"); response.setStatus(HttpSC.OK_200); ServletOutputStream out = response.getOutputStream(); out.print("<p>" + dataset + "(" + known + ")</p>"); for (String name : DatasetRegistry.get().keys()) { out.print("<li>"); out.print(name); out.println("</li>"); } out.println("</ul>"); out.println("<p><a href=\"info\">Next</a></p>"); } // Cookie cookie = new Cookie("org.apache.jena.fuseki.session", dataset) ; // // 24 hours. // cookie.setMaxAge(24*60*60) ; }
From source file:org.openmrs.module.tracdataquality.web.controller.DownloadController.java
/** * Auto generated method comment//w w w. ja v a 2 s . c o m * * @param request * @param response * @param patients * @param filename * @param title * @throws IOException */ private void doDownload(HttpServletRequest request, HttpServletResponse response, List<Patient> patients, String filename, String title) throws IOException { //creating file writer object ServletOutputStream outputStream = response.getOutputStream(); //creating the file response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); //creating file header outputStream.println("Report Name, " + title); outputStream.println("Author, " + Context.getAuthenticatedUser().getPersonName()); outputStream.println("Printed on, " + new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").format(new Date())); outputStream.println("Number of Patients, " + patients.size()); outputStream.println(); outputStream.println("Identifier,Given Name,Middle Name,Family Name,Age,Gender,Creator"); outputStream.println(); //populating content of the report for (Patient patient : patients) { outputStream.println(patient.getPatientIdentifier() + "," + patient.getGivenName() + "," + patient.getMiddleName() + "," + patient.getFamilyName() + "," + patient.getAge() + "," + patient.getGender() + "," + patient.getCreator()); } outputStream.flush(); outputStream.close(); }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateGatewaySenderController.java
@RequestMapping(value = "/creategatewaysender", method = RequestMethod.POST) public String createGatewaySenderAction( @ModelAttribute("gatewaySenderAttribute") NewGatewaySender gatewaySenderAttribute, 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 w w w.j a va 2s .co 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; } } } logger.debug("Received request to action an event for create Gateway Sender"); DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO(); List<DiskStore> dsks = dsDAO.retrieveDiskStoreForCreateList((String) session.getAttribute("user_key")); model.addAttribute("diskstores", dsks); String gatewaySenderName = gatewaySenderAttribute.getGatewaySenderName(); logger.debug("New Gateway Sender Name = " + gatewaySenderName); // perform some action here with what we have String submit = request.getParameter("pSubmit"); boolean needCloseBracket = false; if (submit != null) { // build create HDFS Store SQL StringBuffer createGatewaySender = new StringBuffer(); createGatewaySender.append("CREATE GATEWAYSENDER " + gatewaySenderName + " (\n"); createGatewaySender.append("REMOTEDSID " + gatewaySenderAttribute.getRemoteSID() + " \n"); if (!checkIfParameterEmpty(request, "socketBufferSize")) { createGatewaySender .append("SOCKETBUFFERSIZE " + gatewaySenderAttribute.getSocketBufferSize() + " \n"); } if (!checkIfParameterEmpty(request, "socketReadTimeout")) { createGatewaySender .append("SOCKETREADTIMEOUT " + gatewaySenderAttribute.getSocketReadTimeout() + " \n"); } if (!checkIfParameterEmpty(request, "manualStart")) { createGatewaySender.append("MANUALSTART " + gatewaySenderAttribute.getManualStart() + " \n"); } if (!checkIfParameterEmpty(request, "enableBatchConflation")) { createGatewaySender.append( "ENABLEBATCHCONFLATION " + gatewaySenderAttribute.getEnableBatchConflation() + " \n"); } if (!checkIfParameterEmpty(request, "batchSize")) { createGatewaySender.append("BATCHSIZE " + gatewaySenderAttribute.getBatchSize() + " \n"); } if (!checkIfParameterEmpty(request, "batchTimeInterval")) { createGatewaySender .append("BATCHTIMEINTERVAL " + gatewaySenderAttribute.getBatchTimeInterval() + " \n"); } if (!checkIfParameterEmpty(request, "enablePersistence")) { createGatewaySender .append("ENABLEPERSISTENCE " + gatewaySenderAttribute.getEnablePersistence() + " \n"); if (gatewaySenderAttribute.getEnablePersistence().equals("TRUE")) { if (!checkIfParameterEmpty(request, "diskStore")) { createGatewaySender .append("DISKSTORENAME " + gatewaySenderAttribute.getDiskStore() + " \n"); } } } if (!checkIfParameterEmpty(request, "maxQueueMemory")) { createGatewaySender.append("MAXQUEUEMEMORY " + gatewaySenderAttribute.getMaxQueueMemory() + " \n"); } if (!checkIfParameterEmpty(request, "alertThreshold")) { createGatewaySender.append("ALERTTHRESHOLD " + gatewaySenderAttribute.getAlertThreshold() + " \n"); } createGatewaySender.append(") \n"); if (!checkIfParameterEmpty(request, "serverGroups")) { createGatewaySender.append("SERVER GROUPS (" + gatewaySenderAttribute.getServerGroups() + ") \n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating gateway sender as -> " + createGatewaySender.toString()); result = GemFireXDWebDAOUtil.runCommand(createGatewaySender.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create Gateway Sender SQL as follows as -> " + createGatewaySender.toString()); model.addAttribute("sql", createGatewaySender.toString()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, gatewaySenderName)); ServletOutputStream out = response.getOutputStream(); out.println(createGatewaySender.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/create-gatewaysender.jsp return "create-gatewaysender"; }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateHDFSStoreController.java
@RequestMapping(value = "/createhdfsstore", method = RequestMethod.POST) public String createHDFSStoreAction(@ModelAttribute("hdfsStoreAttribute") NewHDFSStore hdfsStoreAttribute, 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 w w .j a v 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; } } } logger.debug("Received request to action an event for create HDFS Store"); String storeName = hdfsStoreAttribute.getStoreName(); String nameNode = hdfsStoreAttribute.getNameNode(); String homeDir = hdfsStoreAttribute.getHomeDir(); logger.debug("New HDFS Store Name = " + storeName); // perform some action here with what we have String submit = request.getParameter("pSubmit"); if (submit != null) { // build create HDFS Store SQL StringBuffer createHDFSStore = new StringBuffer(); createHDFSStore.append("create HDFSSTORE " + storeName + " \n"); createHDFSStore.append("NAMENODE '" + nameNode + "' \n"); createHDFSStore.append("HOMEDIR '" + homeDir + "' \n"); if (!checkIfParameterEmpty(request, "batchSize")) { createHDFSStore.append("BatchSize " + hdfsStoreAttribute.getBatchSize() + " \n"); } if (!checkIfParameterEmpty(request, "batchTimeInterval")) { createHDFSStore.append("BatchTimeInterval " + hdfsStoreAttribute.getBatchTimeInterval() + " \n"); } if (!checkIfParameterEmpty(request, "maxQueueMemory")) { createHDFSStore.append("MaxQueueMemory " + hdfsStoreAttribute.getMaxQueueMemory() + " \n"); } if (!checkIfParameterEmpty(request, "minorCompact")) { createHDFSStore.append("MinorCompact " + hdfsStoreAttribute.getMinorCompact() + " \n"); } if (!checkIfParameterEmpty(request, "maxInputFileSize")) { createHDFSStore.append("MaxInputFileSize " + hdfsStoreAttribute.getMaxInputFileSize() + " \n"); } if (!checkIfParameterEmpty(request, "minInputFileCount")) { createHDFSStore.append("MinInputFileCount " + hdfsStoreAttribute.getMinInputFileCount() + " \n"); } if (!checkIfParameterEmpty(request, "maxInputFileCount")) { createHDFSStore.append("MaxInputFileCount " + hdfsStoreAttribute.getMaxInputFileCount() + " \n"); } if (!checkIfParameterEmpty(request, "minorCompactionThreads")) { createHDFSStore .append("MinorCompactionThreads " + hdfsStoreAttribute.getMinorCompactionThreads() + " \n"); } if (!checkIfParameterEmpty(request, "majorCompact")) { createHDFSStore.append("MajorCompact " + hdfsStoreAttribute.getMajorCompact() + " \n"); } if (!checkIfParameterEmpty(request, "majorCompactionInterval")) { createHDFSStore.append( "MajorCompactionInterval " + hdfsStoreAttribute.getMajorCompactionInterval() + " \n"); } if (!checkIfParameterEmpty(request, "majorCompactionThreads")) { createHDFSStore .append("MajorCompactionThreads " + hdfsStoreAttribute.getMajorCompactionThreads() + " \n"); } if (!checkIfParameterEmpty(request, "maxWriteOnlyFileSize")) { createHDFSStore .append("MaxWriteOnlyFileSize " + hdfsStoreAttribute.getMaxWriteOnlyFileSize() + " \n"); } if (!checkIfParameterEmpty(request, "writeOnlyRolloverInterval")) { createHDFSStore.append("WriteOnlyFileRolloverInterval " + hdfsStoreAttribute.getWriteOnlyRolloverInterval() + " \n"); } if (!checkIfParameterEmpty(request, "additionalParams")) { createHDFSStore.append(hdfsStoreAttribute.getAdditionalParams()); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating hdfs store as -> " + createHDFSStore.toString()); result = GemFireXDWebDAOUtil.runCommand(createHDFSStore.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create HDFS Store SQL as follows as -> " + createHDFSStore.toString()); model.addAttribute("sql", createHDFSStore.toString()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, storeName)); ServletOutputStream out = response.getOutputStream(); out.println(createHDFSStore.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/create-table.jsp return "create-hdfsstore"; }
From source file:it.cnr.icar.eric.server.interfaces.rest.FilePathURLHandler.java
/** Write the partial directory listing showing specified members for the specified folder */ private void writeDirectoryListing(String pathInfo, RegistryPackageType pkg, List<?> members) throws IOException, RegistryException { ServletOutputStream sout = null; try {//from w w w . ja v a2 s . com sout = response.getOutputStream(); sout.println("<html>"); sout.println("<head>"); sout.println("<title>Index of " + pathInfo + "</title>"); sout.println("</head>"); sout.println("<body>"); sout.println("<h1>Index of " + pathInfo + "</h1>"); sout.println("<pre>ObjectType\t\t<a href=\"?N=D\">Name</a>\t\t<a ref=\"?D=A\">Description</a>"); sout.println("<hr/>"); sout.println("<a href=\"./..\">Goto Parent Directory</a> <br/>"); Iterator<?> iter = members.iterator(); while (iter.hasNext()) { RegistryObjectType member = (RegistryObjectType) iter.next(); writeDirectoryListingItem(sout, member); } sout.println("</pre>"); sout.println("<hr/>"); sout.println("<address>freebXML Regisry Server version 3.0</address>"); sout.println("</body>"); sout.println("</html>"); } finally { if (sout != null) { sout.close(); } } }
From source file:org.inbio.ait.web.ajax.controller.TaxonomyAutoCompleteController.java
/** * Writes the response in the output!./* w ww.j a v a2s . c om*/ * @param request * @param response * @param acnList * @return * @throws Exception */ private ModelAndView writeReponse(HttpServletRequest request, HttpServletResponse response, List<AutocompleteNode> acnList) throws Exception { response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); // Binary output ServletOutputStream out = response.getOutputStream(); if (acnList != null) { for (AutocompleteNode sp : acnList) { out.println(sp.getItemName() + "\t" + sp.getItemId()); } } out.flush(); out.close(); return null; }