List of usage examples for java.io OutputStreamWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.AverageMessageSizeByServiceByMethod.java
/** * {@inheritDoc}//from www. j a v a 2s .com */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { int itemcount = 0; Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>"); data.append(GetDisplayName()); data.append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); //add description data.append( "<table class=\"table table-hover\"><tr><th>URL</th><th>Action</th><th>Average Message Size (bytes)</th></tr>"); itemcount = 0; for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); try { List<String> actions = getSoapActions(urls.get(i), con); for (int k = 0; k < actions.size(); k++) { itemcount++; long count = -1; try { cmd = con.prepareStatement( "select AVG(responseSize + requestSize) as messagesSize from RawData where URI=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=?"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); cmd.setString(4, actions.get(k)); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, " error querying database for average message size url:" + urls.get(i), ex); } } catch (Exception ex) { log.log(Level.ERROR, "Error opening or querying the database." + this.getClass().getSimpleName(), ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<tr><td>").append(url).append("</td><td>"); data.append(Utility.encodeHTML(actions.get(k))); data.append("</td><td>"); if (count >= 0) { data.append(count + " bytes"); } else { data.append("N/A"); } data.append("</td></tr>"); if (count >= 0) { set.addValue(count, actions.get(k), url); } } } catch (Exception ex) { data.append("0 bytes</td></tr>"); log.log(Level.ERROR, "Error opening or querying the database." + this.getClass().getSimpleName(), ex); } } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { int height = pixelHeightCalc(itemcount); ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, height); } catch (Exception ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.os.NetworkIOReport.java
@Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try {/* w ww. j a v a 2s.c om*/ PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append("This represents the network throughput rates of a machine over time.<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URI</th><th>Average Send Rate</th><th>Average Recieve Rate</th></tr>"); TimeSeriesCollection col = new TimeSeriesCollection(); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); data.append("<tr><td>").append(url).append("</td>"); double average = 0; try { cmd = con.prepareStatement( "select avg(sendkbs) from rawdatanic where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td>"); average = 0; try { cmd = con.prepareStatement( "select avg(receivekbs) from rawdatanic where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td></tr>"); //ok now get the raw data.... TimeSeriesContainer tsc = new TimeSeriesContainer(); try { cmd = con.prepareStatement( "select receivekbs, sendkbs, utcdatetime, nicid from rawdatanic where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); while (rs.next()) { TimeSeries ts = tsc.Get(url + " " + rs.getString("nicid") + " RX", Millisecond.class); TimeSeries ts2 = tsc.Get(url + " " + rs.getString("nicid") + " TX", Millisecond.class); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(rs.getLong(3)); Millisecond m = new Millisecond(gcal.getTime()); ts.addOrUpdate(m, rs.getLong(1)); ts2.addOrUpdate(m, rs.getLong(2)); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } for (int ik = 0; ik < tsc.data.size(); ik++) { col.addSeries(tsc.data.get(ik)); } } chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Rate", col, true, false, false); data.append("</table>"); try { // if (set.getRowCount() != 0) { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, 400); data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); // } } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.InvocationsByConsumer.java
/** * {@inheritDoc}/*from ww w .j a v a2 s . c o m*/ */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; PreparedStatement userQuery = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append("This represents service usage by consumer for the provided services.<br />"); //add description data.append("<table class=\"table table-hover\"><tr><th>User</th><th>Invocations</th></tr>"); ResultSet actionRS = null; Set<String> users = new HashSet<String>(); try { userQuery = con.prepareStatement("select consumeridentity from rawdata group by consumeridentity"); actionRS = userQuery.executeQuery(); users.add("unspecified"); while (actionRS.next()) { try { String s = actionRS.getString(1); s = s.trim(); if (!Utility.stringIsNullOrEmpty(s)) { String[] items = s.split(";"); for (int x = 0; x < items.length; x++) { if (!Utility.stringIsNullOrEmpty(items[x])) { users.add(items[x].trim()); } } } } catch (Exception ex) { log.log(Level.WARN, " error querying database", ex); } } } catch (Exception ex) { log.log(Level.WARN, " error querying database", ex); } finally { DBUtils.safeClose(actionRS); DBUtils.safeClose(userQuery); } try { Iterator<String> iterator = users.iterator(); while (iterator.hasNext()) { String u = iterator.next(); try { if (u.equalsIgnoreCase("unspecified")) { cmd = con.prepareStatement( "select count(*) from RawData where consumeridentity is null and " + "(UTCdatetime > ?) and (UTCdatetime < ?)"); cmd.setLong(1, range.getStart().getTimeInMillis()); cmd.setLong(2, range.getEnd().getTimeInMillis()); } else { cmd = con.prepareStatement("select count(*) from RawData where consumeridentity=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?)"); cmd.setString(1, u); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); } rs = cmd.executeQuery(); long count = 0; try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, " error querying database", ex); } data.append("<tr><td>").append(Utility.encodeHTML(u)).append("</td><td>"); data.append(count + "").append("</td></tr>"); if (count > 0) { set.addValue(count, u, u); } } catch (Exception ex) { log.log(Level.WARN, " error querying database", ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } } } catch (Exception ex) { data.append("0</td></tr>"); log.log(Level.ERROR, "Error opening or querying the database.", ex); } finally { DBUtils.safeClose(cmd); } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Consumers", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.InvocationsByConsumerByService.java
/** * {@inheritDoc}//from w w w.jav a 2 s. c om */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); data.append( "<table class=\"table table-hover\"><tr><th>Consumer</th><th>URL</th><th>Invocations</th></tr>"); Set<String> consumers = new HashSet<String>(); // for (int i = 0; i < (consumers.size()-1); i++) { for (int k = 0; k < urls.size(); k++) { if (!isPolicyTypeOf(urls.get(k), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(k), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(k))); consumers.clear(); try { try { cmd = con.prepareStatement( "select consumeridentity from rawdata where uri=? and (UTCdatetime > ?) and (UTCdatetime < ?) group by consumeridentity;"); cmd.setString(1, urls.get(k)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); while (rs.next()) { String s = rs.getString(1); if (!Utility.stringIsNullOrEmpty(s)) { String ids[] = s.split(";"); for (int i = 0; i < ids.length; i++) { if (!Utility.stringIsNullOrEmpty(ids[i])) { consumers.add(ids[i]); } } } } } catch (Exception ex) { log.log(Level.WARN, " error querying database forINVOCATIONS_BY_CONSUMER_BY_SERVICE" + urls.get(k), ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } consumers.add("unspecified"); //ok for this service, count the times each consumer as hit it Iterator<String> iterator = consumers.iterator(); while (iterator.hasNext()) { String user = iterator.next(); long count = 0; try { cmd = con.prepareStatement("select count(*) from RawData where URI=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and consumeridentity ~* ?;"); cmd.setString(1, urls.get(k)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); cmd.setString(4, user); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.WARN, " error querying database forINVOCATIONS_BY_CONSUMER_BY_SERVICE" + urls.get(k), ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } if (count > 0) { //cut down on the chatter data.append("<tr><td>").append(url).append("</td><td>").append(Utility.encodeHTML(user)) .append("</td><td>"); data.append(count + ""); data.append("</td></tr>"); set.addValue(count, user, urls.get(k)); } } //this is for anonymous users or for when an identity was not //recorded by the agent long count = 0; try { cmd = con.prepareStatement("select count(*) from RawData where URI=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and consumeridentity is null;"); cmd.setString(1, urls.get(k)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.WARN, " error querying database forINVOCATIONS_BY_CONSUMER_BY_SERVICE" + urls.get(k), ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } if (count > 0) { //cut down on the chatter data.append("<tr><td>").append(url).append("</td><td>(not recorded)</td><td>"); data.append(count + ""); data.append("</td></tr>"); set.addValue(count, "unspecified", url); } } catch (Exception ex) { data.append("0 bytes</td></tr>"); log.log(Level.ERROR, "Error opening or querying the database.", ex); } } // insert query for unspecified chart = org.jfree.chart.ChartFactory.createBarChart(toFriendlyName(get.getType()), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); try { int height = pixelHeightCalc(set.getColumnCount()); ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, height); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.InvocationsByDataCollector.java
/** * {@inheritDoc}//from w ww . ja v a2 s. c o m */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { int itemcount = 0; Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; if (!UserIdentityUtil.hasGlobalAdministratorRole(currentuser, "THROUGHPUT_BY_HOSTING_SERVER", classification, ctx)) { data.append("<h2>Access for " + GetDisplayName() + " was denied for non-global admin users</h2>"); return; } data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append("This represents Data Collector Service utilization.<br />"); data.append("<table class=\"table table-hover\"><tr><th>Host</th><th>Invocations</th></tr>"); List<String> dcs = new ArrayList<String>(); try { //was select distinct monitorsource from RawData; cmd = con.prepareStatement("select monitorsource from rawdata group by monitorsource;"); rs = cmd.executeQuery(); while (rs.next()) { dcs.add(rs.getString(1)); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } try { itemcount = dcs.size(); for (int i = 0; i < dcs.size(); i++) { data.append("<tr><td>").append(Utility.encodeHTML(dcs.get(i))).append("</td><td>"); int success = 0; try { cmd = con.prepareStatement( "select count(*) from RawData where monitorsource=? and UTCdatetime > ? and UTCdatetime < ?;"); cmd.setString(1, dcs.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); if (rs.next()) { success = rs.getInt(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(success + "").append("</td></tr>"); set.addValue(success, dcs.get(i), dcs.get(i)); } } catch (Exception ex) { log.log(Level.ERROR, "Error generating chart information.", ex); } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Monitoring Servers", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(itemcount)); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:com.csounds.examples.tests.MultiTouchXYActivity.java
private void writeToFile(String data) { try {/* w ww . j a va2 s. c om*/ if (!txtfile.exists()) { Log.d("txtfile", "txtfile doesn't exist"); ContextWrapper cw = new ContextWrapper(this); File directory = cw.getExternalFilesDir(null); txtfile = new File(directory, "temp.txt"); } System.out.println("zz" + txtfile); FileOutputStream outStream = new FileOutputStream(txtfile, true); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outStream); String output = String.format(data); // BufferedWriter oFile = new BufferedWriter(new OutputStreamWriter( // new FileOutputStream("test.txt"), "UTF-16")); outputStreamWriter.append("\r\n"); outputStreamWriter.append(output); outputStreamWriter.close(); } catch (IOException e) { Log.e("Exception", "File write failed: " + e.toString()); } }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.InvocationsByConsumerByServiceByMethod.java
@Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try {/*from ww w .j a va 2s . c o m*/ PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URL</th><th>Consumer</th><th>Method</th><th>Invocations</th></tr>"); Set<String> consumers2 = new HashSet<String>(); List<String> actions = new ArrayList<String>(); for (int k = 0; k < urls.size(); k++) { if (!isPolicyTypeOf(urls.get(k), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(k), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(k))); consumers2.clear(); actions.clear(); try { actions = getSoapActions(urls.get(k), con); rs = null; for (int k2 = 0; k2 < actions.size(); k2++) { try { consumers2.clear(); cmd = con.prepareStatement( "select consumeridentity from rawdata where uri=? and (UTCdatetime > ?) and (UTCdatetime < ?) and soapaction=? group by consumeridentity;"); cmd.setString(1, urls.get(k)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); cmd.setString(4, actions.get(k2)); rs = cmd.executeQuery(); while (rs.next()) { String s = rs.getString(1); // log.log(Level.WARN, " debug INVOCATIONS_BY_CONSUMER_BY_SERVICE url:" + urls.get(k) + " user: " + s); if (!Utility.stringIsNullOrEmpty(s)) { String ids[] = s.split(";"); for (int i = 0; i < ids.length; i++) { if (!Utility.stringIsNullOrEmpty(ids[i])) { // log.log(Level.WARN, " debug2 INVOCATIONS_BY_CONSUMER_BY_SERVICE url:" + urls.get(k) + " user: " + ids[i]); if (!consumers2.contains(ids[i])) { consumers2.add(ids[i]); } } } } } } catch (Exception ex) { log.log(Level.WARN, " error querying database forINVOCATIONS_BY_CONSUMER_BY_SERVICE" + urls.get(k), ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } consumers2.add("unspecified"); //ok for this service, count the times each consumer as hit it Iterator<String> iterator = consumers2.iterator(); while (iterator.hasNext()) { String u = iterator.next(); long count = 0; try { cmd = con.prepareStatement( "select count(*) from RawData where URI=? and soapaction=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and consumeridentity ~* ?;"); cmd.setString(1, urls.get(k)); cmd.setString(2, actions.get(k2)); cmd.setLong(3, range.getStart().getTimeInMillis()); cmd.setLong(4, range.getEnd().getTimeInMillis()); cmd.setString(5, u); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.WARN, " error querying database forINVOCATIONS_BY_CONSUMER_BY_SERVICE" + urls.get(k), ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } if (count > 0) { //cut down on the noise data.append("<tr><td>").append(url).append("</td><td>") .append(Utility.encodeHTML(u)).append("</td><td>") .append(Utility.encodeHTML(actions.get(k2))).append("</td><td>"); data.append(count + ""); data.append("</td></tr>"); set.addValue(count, u, urls.get(k) + " " + actions.get(k2)); } } long count = 0; try { cmd = con.prepareStatement( "select count(*) from RawData where URI=? and soapaction=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) and consumeridentity is null;"); cmd.setString(1, urls.get(k)); cmd.setString(2, actions.get(k2)); cmd.setLong(3, range.getStart().getTimeInMillis()); cmd.setLong(4, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.WARN, " error querying database forINVOCATIONS_BY_CONSUMER_BY_SERVICE" + urls.get(k), ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } if (count > 0) { //cut down on the noise data.append("<tr><td>").append(url).append("</td><td>unspecified</td><td>") .append(Utility.encodeHTML(actions.get(k2))).append("</td><td>"); data.append(count + ""); data.append("</td></tr>"); set.addValue(count, "unspecified", url + " " + actions.get(k2)); } } } catch (Exception ex) { log.log(Level.ERROR, "Error opening or querying the database.", ex); } } // insert query for unspecified chart = org.jfree.chart.ChartFactory.createBarChart(toFriendlyName(get.getType()), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getColumnCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.envirocar.aggregation.AggregatedTracksServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { OutputStreamWriter writer = new OutputStreamWriter(resp.getOutputStream(), Charset.forName("UTF-8")); resp.setContentType("application/json"); String uri = req.getRequestURI(); String subPath = uri.substring(uri.indexOf(PATH) + PATH.length()); String trackId = null;/*from w w w.j a v a 2 s . co m*/ if (!subPath.isEmpty() && !(subPath.length() == 1 && subPath.equals("/"))) { trackId = subPath.startsWith("/") ? subPath.substring(1) : subPath; } String json; try { if (trackId != null) { json = createTrackExists(trackId); } else { json = createAggregatedTracksList(); } } catch (SQLException e) { throw new IOException(e); } writer.append(json); writer.flush(); writer.close(); resp.setStatus(200); }
From source file:org.miloss.fgsms.services.rs.impl.reports.ws.ThroughputByServiceByMethod.java
/** * {@inheritDoc}// w ww .j ava 2s . c o m */ @Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { double d = range.getEnd().getTimeInMillis() - range.getStart().getTimeInMillis(); double day = d / 86400000; double hours = d / 3600000; double min = d / 60000; double sec = d / 1000; Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URL</th><th>Method</th><th>Invocations</th><th>Msg/Day</th><th>Msg/Hour</th><th>Msg/Min</th><th>Msg/Sec</th></tr>"); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.TRANSACTIONAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); try { List<String> actions = getSoapActions(urls.get(i), con); for (int k = 0; k < actions.size(); k++) { long count = 0; try { cmd = con.prepareStatement( "select count(*) from RawData where URI=? and soapaction=? and " + "(UTCdatetime > ?) and (UTCdatetime < ?) ;"); cmd.setString(1, urls.get(i)); cmd.setString(2, actions.get(k)); cmd.setLong(3, range.getStart().getTimeInMillis()); cmd.setLong(4, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); try { if (rs.next()) { count = rs.getLong(1); } } catch (Exception ex) { log.log(Level.DEBUG, null, ex); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<tr><td>").append(url).append("</td><td>") .append(Utility.encodeHTML(actions.get(k))).append("</td><td>"); data.append(count + ""); data.append("</td><td>").append(format.format((double) ((double) count / day))) .append("</td><td>").append(format.format((double) ((double) count / hours))) .append("</td><td>").append(format.format((double) ((double) count / min))) .append("</td><td>").append(format.format((double) ((double) count / sec))) .append("</td></tr>"); if (count > 0) { set.addValue((double) ((double) count / day), actions.get(k), url); } } } catch (Exception ex) { log.log(Level.ERROR, "Error opening or querying the database.", ex); } } chart = org.jfree.chart.ChartFactory.createBarChart(GetDisplayName(), "Service URL", "", set, PlotOrientation.HORIZONTAL, true, false, false); data.append("</table>"); try { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, pixelHeightCalc(set.getRowCount())); } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.opendatakit.briefcase.util.ExportToCsv.java
private void emitString(OutputStreamWriter osw, boolean first, String string) throws IOException { osw.append(first ? "" : ","); if (string == null) return;/*from w ww.j a v a 2 s.c o m*/ if (string.length() == 0 || string.contains("\n") || string.contains("\"") || string.contains(",")) { string = string.replace("\"", "\"\""); string = "\"" + string + "\""; } osw.append(string); }