1 /**
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * If it is not possible or desirable to put the notice in a particular
7 * file, then You may include the notice in a location (such as a LICENSE
8 * file in a relevant directory) where a recipient would be likely to look
9 * for such a notice.
10
11 *
12 */
13
14 /* ---------------------------------------------------------------------------
15 * U.S. Government, Department of the Army
16 * Army Materiel Command
17 * Research Development Engineering Command
18 * Communications Electronics Research Development and Engineering Center
19 * ---------------------------------------------------------------------------
20 */
21 package org.miloss.fgsms.presentation;
22
23 import de.laures.cewolf.DatasetProduceException;
24 import de.laures.cewolf.DatasetProducer;
25 import java.io.Serializable;
26 import java.net.URL;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.List;
30 import java.util.Map;
31 import org.miloss.fgsms.common.Utility;
32 import org.miloss.fgsms.services.interfaces.dataaccessservice.GetMessageLogsResponseMsg;
33 import org.miloss.fgsms.services.interfaces.dataaccessservice.TransactionLog;
34 import org.apache.log4j.Level;
35 import org.miloss.fgsms.common.Logger;;
36 import org.jfree.data.time.Millisecond;
37 import org.jfree.data.time.TimeSeries;
38 import org.jfree.data.time.TimeSeriesCollection;
39
40 /**
41 *
42 * @author AO
43 */
44 public class TransactionLogViewerData implements DatasetProducer, Serializable {
45
46 public TransactionLogViewerData() {
47 }
48
49 public TransactionLogViewerData(URL url) {
50 dasu = url;
51 }
52 private URL dasu=null;
53 private List<TransactionLog> data=null;
54
55 /*
56 * this is only called from the service profile page
57
58 *
59
60 @Deprecated
61 private String GetRenderedData(String URL, int offset, int records, boolean slaFaultsOnly, boolean faultsOnly, HttpSession session, String username, String password, SecurityWrapper c, AuthMode mode_) {
62 LogHelper.getLog().log(Level.INFO, "fgsmsWEB TransactionLogViewerData, produce rendered data");
63 String out = "";
64 try {
65
66 DataAccessService_Service das = new DataAccessService_Service(this.getClass().getResource("/META-INF/" + org.miloss.fgsms.common.Constants.DAS_META));
67 DataAccessService dasport = das.getDASPort();
68 BindingProvider bpPCS = (BindingProvider) dasport;
69 Map<String, Object> contextPCS = bpPCS.getRequestContext();
70 contextPCS.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, dasu.toString());
71 StubExt sec = (StubExt) bpPCS;
72 if (mode_ == AuthMode.UsernamePassword) {
73 sec.setSecurityConfig("fgsms-username-config.xml");
74 contextPCS.put(BindingProvider.USERNAME_PROPERTY, username);
75 contextPCS.put(BindingProvider.PASSWORD_PROPERTY, Utility.DE(password));
76 }
77 if (mode_ == AuthMode.PKI) {
78 sec.setSecurityConfig("fgsms-pki-config.xml");
79 }
80
81 GetRecentMessageLogsRequestMsg req1 = new GetRecentMessageLogsRequestMsg();
82 req1.setClassification(c);
83 req1.setURL(URL);
84 req1.setOffset(offset);
85 req1.setRecords(records);
86
87 req1.setSlaViolationsOnly(slaFaultsOnly);
88 req1.setFaultsOnly(faultsOnly);
89 GetMessageLogsResponseMsg res = dasport.getRecentMessageLogs(req1);
90 out += ("Total Records available: " + res.getTotalRecords());
91
92 if (res.getLogs() != null
93 && res.getLogs().getValue() != null
94 && res.getLogs().getValue().getTransactionLog() != null
95 && res.getLogs().getValue().getTransactionLog().size() > 0) {
96 out += ("<table border=1><tr>"
97 + "<th>Action</th>"
98 + "<th>Success/Fault</th>"
99 + "<th>Requestor Identity</th>"
100 + "<th>Response Time</th>"
101 // + "<th>Request / Response</th>"
102 + "<th>Timestamp</th>"
103 + "<th>SLA Violation</th>"
104 + "<th>Details</th></tr>");
105 data = res.getLogs().getValue().getTransactionLog();
106
107 // is this needed? no it isn't
108 //session.setAttribute("fgsms.transactionlog" + URL, data);
109 boolean colorflag = false;
110 for (int i = 0; i < res.getLogs().getValue().getTransactionLog().size(); i++) {
111 out += ("<tr ");
112 colorflag = !colorflag;
113 if (colorflag) {
114 out += " bgcolor=#EEFFEE><td>";
115 } else {
116 out += " bgcolor=#DDFFDD><td>";
117 }
118 int clip = 0;
119
120 if (Utility.stringIsNullOrEmpty(res.getLogs().getValue().getTransactionLog().get(i).getAction())) {
121 out += "NA</td><td>";
122 } else {
123 out += (res.getLogs().getValue().getTransactionLog().get(i).getAction() + "</td><td>");
124 }
125 if (!res.getLogs().getValue().getTransactionLog().get(i).isIsFault()) {
126 out += ("<font color=#FF0000><b>Fault</b></font>");
127 } else {
128 out += ("Success");
129 }
130 out += ("</td><td>" + Utility.encodeHTML(ParseIdentities(res.getLogs().getValue().getTransactionLog().get(i).getIdentity()))
131 + "</td><td>" + res.getLogs().getValue().getTransactionLog().get(i).getResponseTime()
132 + "ms</td>");
133
134 out += ("<td>" + res.getLogs().getValue().getTransactionLog().get(i).getTimestamp().toString()
135 + "</td><td>");
136 if (res.getLogs().getValue().getTransactionLog().get(i).isIsSLAFault()) {
137 out += ("<font color=#FF0000><b>Fault</b></font>");
138 }
139 out += "</td><td>"
140 + Utility.encodeHTML(res.getLogs().getValue().getTransactionLog().get(i).getSlaFaultMsg())
141 + "<a href=\"SpecificTransactionLogViewer.jsp?ID=" + res.getLogs().getValue().getTransactionLog().get(i).getTransactionId() + "\">Details</a>"
142 + "</td></tr></tr>";
143
144 }
145
146
147 } else {
148 out += "<br><Br>No records were returned.";
149 }
150
151 } catch (SecurityException ex) {
152 out += ("Access was denied to the requested resource.");
153 LogHelper.getLog().log(Level.ERROR, "TransactionLogViewer, access denied when error rendering data for user " + username);
154 } catch (Exception ex) {
155 Logger.getLogger("fgsms.Web").log(Level.WARN, "Error caught", ex);
156 out += ("There was an error processing your request. Message: " + ex.getLocalizedMessage());
157 LogHelper.getLog().log(Level.ERROR, "TransactionLogViewer, error rendering data for user " + username, ex);
158 }
159 return out;
160 }
161 */
162 public String GetRenderedData(GetMessageLogsResponseMsg res)
163 {
164 String out = "";
165 if (res == null)
166 return out;
167 try
168 {
169 out += ("Total Records available: " + res.getTotalRecords());
170
171 if (res.getLogs() != null
172 && res.getLogs() != null
173 && res.getLogs().getTransactionLog() != null
174 && res.getLogs().getTransactionLog().size() > 0) {
175 out += ("<table border=1><tr>"
176 + "<th>Action</th>"
177 + "<th>Success/Fault</th>"
178 + "<th>Requestor Identity</th>"
179 + "<th>Response Time</th>"
180 // + "<th>Request / Response</th>"
181 + "<th>Timestamp</th>"
182 + "<th>SLA Violation</th>"
183 + "<th>Details</th></tr>");
184 data = res.getLogs().getTransactionLog();
185
186 // is this needed? no it isn't
187 //session.setAttribute("fgsms.transactionlog" + URL, data);
188 boolean colorflag = false;
189 for (int i = 0; i < res.getLogs().getTransactionLog().size(); i++) {
190 out += ("<tr ");
191 colorflag = !colorflag;
192 if (colorflag) {
193 out += " bgcolor=#EEFFEE><td>";
194 } else {
195 out += " bgcolor=#DDFFDD><td>";
196 }
197 int clip = 0;
198
199 if (Utility.stringIsNullOrEmpty(res.getLogs().getTransactionLog().get(i).getAction())) {
200 out += "NA</td><td>";
201 } else {
202 out += (res.getLogs().getTransactionLog().get(i).getAction() + "</td><td>");
203 }
204 if (!res.getLogs().getTransactionLog().get(i).isIsFault()) {
205 out += ("<font color=#FF0000><b>Fault</b></font>");
206 } else {
207 out += ("Success");
208 }
209 out += ("</td><td>" + Utility.encodeHTML(ParseIdentities(res.getLogs().getTransactionLog().get(i).getIdentity()))
210 + "</td><td>" + res.getLogs().getTransactionLog().get(i).getResponseTime()
211 + "ms</td>");
212
213 out += ("<td>" + res.getLogs().getTransactionLog().get(i).getTimestamp().toString()
214 + "</td><td>");
215 if (res.getLogs().getTransactionLog().get(i).isIsSLAFault()) {
216 out += ("<font color=#FF0000><b>Fault</b></font>");
217 }
218 out += "</td><td>"
219 + Utility.encodeHTML(res.getLogs().getTransactionLog().get(i).getSlaFaultMsg())
220 + "<a href=\"SpecificTransactionLogViewer.jsp?ID=" + res.getLogs().getTransactionLog().get(i).getTransactionId() + "\">Details</a>"
221 + "</td></tr></tr>";
222
223 }
224
225
226 } else {
227 out += "<br><Br>No records were returned.";
228 }
229
230 } catch (SecurityException ex) {
231 out += ("Access was denied to the requested resource.");
232 LogHelper.getLog().log(Level.ERROR, "TransactionLogViewer, access denied when error rendering data for user ");
233 } catch (Exception ex) {
234 Logger.getLogger("fgsms.Web").log(Level.WARN, "Error caught", ex);
235 out += ("There was an error processing your request. Message: " + ex.getLocalizedMessage());
236 LogHelper.getLog().log(Level.ERROR, "TransactionLogViewer, error rendering data for user ", ex);
237 }
238 return out;
239 }
240 public Object produceDataset(Map params) throws DatasetProduceException {
241
242 // Logger.getAnonymousLogger().log(Level.INFO, "fgsmsWEB TransactionLogViewerData, produce chart data");
243 TimeSeriesCollection col = new TimeSeriesCollection();
244
245
246 try {
247 GetMessageLogsResponseMsg res = (GetMessageLogsResponseMsg) params.get("fgsms.data");
248 TransactionLogData recordset = new TransactionLogData();
249 if (res != null && res.getLogs() != null && res.getLogs() != null && res.getLogs().getTransactionLog() != null && res.getLogs().getTransactionLog().size() > 0) {
250
251 //loop through all records
252 for (int i = 0; i < res.getLogs().getTransactionLog().size(); i++) {
253 String action = res.getLogs().getTransactionLog().get(i).getAction();
254 int clip = 0;
255 if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("/") > clip) {
256 clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("/");
257 }
258 if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("}") > clip) {
259 clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("}");
260 }
261 if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf(":") > clip) {
262 clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf(":");
263 }
264 if (res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("#") > clip) {
265 clip = res.getLogs().getTransactionLog().get(i).getAction().lastIndexOf("#");
266 }
267
268 if (clip > 0) {
269 action = (res.getLogs().getTransactionLog().get(i).getAction().substring(clip + 1));
270 }
271 TransactionLogTimeStampStruct t2 = new TransactionLogTimeStampStruct();
272 t2.ResponseTime = res.getLogs().getTransactionLog().get(i).getResponseTime();
273 t2.cal = res.getLogs().getTransactionLog().get(i).getTimestamp();
274 if (recordset.Contains(action)) {
275 recordset.get(action).add(t2);
276 } else {
277 TransactionLogStruct t3 = new TransactionLogStruct();
278 t3.action = action;
279 t3.data = new ArrayList<TransactionLogTimeStampStruct>();
280 t3.data.add(t2);
281 recordset.add(t3);
282 }
283
284
285 }
286
287 for (int i = 0; i < recordset.stuff.size(); i++) {
288 TimeSeries s = new TimeSeries(recordset.stuff.get(i).action, org.jfree.data.time.Millisecond.class);
289
290 for (int k = 0; k < recordset.stuff.get(i).data.size(); k++) {
291 Millisecond m = new Millisecond(recordset.stuff.get(i).data.get(k).cal.getTime());
292
293 // TimeSeriesDataItem t = new TimeSeriesDataItem(m,
294 // recordset.stuff.get(i).data.get(k).ResponseTime);
295 // s.add(t);
296 s.addOrUpdate(m, recordset.stuff.get(i).data.get(k).ResponseTime);
297
298 }
299
300 col.addSeries(s);
301 //col.addSeries((TimeSeries)s.clone());
302 }
303 }
304 } catch (Exception ex) {
305 LogHelper.getLog().log(Level.ERROR, "TransactionLogViewerData produce chart data " + ex.getLocalizedMessage());
306 }
307
308 return col;
309 }
310
311 public boolean hasExpired(Map params, Date since) {
312 return (System.currentTimeMillis() - since.getTime()) > 5000;
313 }
314
315 public String getProducerId() {
316 return "fgsms.TransactionLogViewerData";
317 }
318
319 public static String ParseIdentities(List<String> identity) {
320 if (identity == null || identity.isEmpty()) {
321
322 return "";
323 }
324 StringBuilder ret = new StringBuilder();
325 for (int i = 0; i < identity.size(); i++) {
326 ret= ret.append(identity.get(i)).append(", ");
327 }
328 String r = ret.toString().trim();
329
330 return r.substring(0, ret.length() - 1);
331
332 }
333 }