1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.miloss.fgsms.services.rs.impl;
21
22 import org.miloss.fgsms.plugins.reporting.ReportGeneratorPlugin;
23 import java.io.*;
24 import java.sql.Connection;
25 import java.sql.PreparedStatement;
26 import java.sql.ResultSet;
27 import java.sql.SQLException;
28 import java.util.*;
29 import java.util.zip.ZipEntry;
30 import java.util.zip.ZipOutputStream;
31 import javax.annotation.Resource;
32 import javax.jws.WebMethod;
33 import javax.jws.WebParam;
34 import javax.jws.WebResult;
35 import javax.jws.WebService;
36 import javax.jws.soap.SOAPBinding;
37 import javax.servlet.http.HttpServletRequest;
38 import javax.xml.datatype.DatatypeConfigurationException;
39 import javax.xml.datatype.DatatypeFactory;
40 import javax.xml.ws.RequestWrapper;
41 import javax.xml.ws.ResponseWrapper;
42 import javax.xml.ws.WebServiceContext;
43 import javax.xml.ws.handler.MessageContext;
44 import org.apache.log4j.Level;
45 import org.miloss.fgsms.common.AuditLogger;
46 import org.miloss.fgsms.common.Constants;
47 import org.miloss.fgsms.common.DBUtils;
48 import org.miloss.fgsms.common.Logger;
49 import org.miloss.fgsms.common.UserIdentityUtil;
50 import org.miloss.fgsms.common.Utility;
51 import org.miloss.fgsms.services.interfaces.common.GetOperatingStatusRequestMessage;
52 import org.miloss.fgsms.services.interfaces.common.GetOperatingStatusResponseMessage;
53 import org.miloss.fgsms.services.interfaces.common.PolicyType;
54 import org.miloss.fgsms.services.interfaces.common.SecurityWrapper;
55 import org.miloss.fgsms.services.interfaces.faults.ServiceUnavailableFaultCodes;
56 import org.miloss.fgsms.services.interfaces.reportingservice.*;
57 import org.miloss.fgsms.services.interfaces.status.OpStatusService;
58 import us.gov.ic.ism.v2.ClassificationType;
59
60
61
62
63
64
65
66 @WebService(name = "reportingService", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService"
67 )
68
69 @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED, use = SOAPBinding.Use.LITERAL)
70 public class Reporting implements ReportingService, OpStatusService {
71
72 protected static final String delimiter = "|";
73 protected static final String name = "fgsms.ReportingService";
74 private static DatatypeFactory df = null;
75 public final static Logger log = Logger.getLogger(name);
76 private static Calendar started = null;
77 public final static String allitems = "All-Methods";
78 private static Map<String, ReportGeneratorPlugin> reportingPlugins;
79
80
81 public Reporting() throws DatatypeConfigurationException {
82 InitDF();
83 }
84
85 private synchronized void InitDF() throws DatatypeConfigurationException {
86 if (df == null) {
87 df = DatatypeFactory.newInstance();
88 }
89 if (started == null) {
90 GregorianCalendar gcal = new GregorianCalendar();
91 gcal.setTimeInMillis(System.currentTimeMillis());
92 started = (gcal);
93 }
94 reportingPlugins = new HashMap<String, ReportGeneratorPlugin>();
95
96 }
97
98
99
100
101
102
103 public Reporting(WebServiceContext w) throws DatatypeConfigurationException {
104 ctx = w;
105 InitDF();
106 }
107 @Resource
108 private WebServiceContext ctx;
109
110
111
112
113
114
115
116
117
118 @WebMethod(operationName = "ExportDataToHTML", action = "urn:org:miloss:fgsms:services:interfaces:reportingService/reportingService/ExportDataToHTML")
119 @WebResult(name = "ExportDataToHTMLResult", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService")
120 @RequestWrapper(localName = "ExportDataToHTML", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService", className = "org.miloss.fgsms.services.interfaces.reportingservice.ExportDataToHTML")
121 @ResponseWrapper(localName = "ExportDataToHTMLResponse", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService", className = "org.miloss.fgsms.services.interfaces.reportingservice.ExportDataToHTMLResponse")
122 public ExportDataToHTMLResponseMsg exportDataToHTML(
123 @WebParam(name = "request", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService") ExportDataRequestMsg request)
124 throws AccessDeniedException, ServiceUnavailableException {
125 String currentUser = UserIdentityUtil.getFirstIdentityToString(ctx);
126 return generateHtmlReport(currentUser,request);
127 }
128
129 protected ExportDataToHTMLResponseMsg generateHtmlReport(String currentUser,ExportDataRequestMsg request)
130 throws AccessDeniedException, ServiceUnavailableException {
131 if (request == null) {
132 AuditLogger.logItem(this.getClass().getCanonicalName(), "exportDataToHTML", currentUser, "", "not specified", ctx.getMessageContext());
133 throw new IllegalArgumentException("request is null");
134 }
135 Utility.validateClassification(request.getClassification());
136
137 AuditLogger.logItem(this.getClass().getCanonicalName(), "exportDataToHTML", currentUser, "", (request.getClassification()), ctx!=null? ctx.getMessageContext():null);
138
139
140 if (request.getRange() == null || request.getRange().getEnd() == null || request.getRange().getStart() == null) {
141 throw new IllegalArgumentException("range is null");
142 }
143 if (request.getReportTypes() == null
144 || request.getReportTypes().getReportTypeContainer() == null
145 || request.getReportTypes().getReportTypeContainer().isEmpty()) {
146 throw new IllegalArgumentException("ReportTypes is null, at least one must be specified");
147 }
148 if (request.isAllServices() == false
149 && (request.getURLs() == null
150 || request.getURLs().isEmpty())) {
151 throw new IllegalArgumentException("AllServices must be true or at least one URL must be specified");
152 }
153
154
155
156
157 String path = "";
158 String header = "";
159 String currentFolder = "";
160 String footer = "";
161 File targetfolder = null;
162 UUID id = UUID.randomUUID();
163 try {
164 currentFolder = System.getProperty("jboss.server.temp.dir");
165 if (currentFolder == null || currentFolder.equals("") || currentFolder.equalsIgnoreCase("null")) {
166 currentFolder = System.getProperty("java.io.tmpdir");
167 }
168
169 path = currentFolder + getFilePathDelimitor() + id.toString();
170 targetfolder = new File(path);
171 boolean mkdir = targetfolder.mkdir();
172 if (!mkdir) {
173 HttpServletRequest session = ((HttpServletRequest) ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST));
174
175 targetfolder = (File) session.getAttribute("javax.servlet.context.tmpdir");
176
177 }
178
179 if (!targetfolder.exists()) {
180 log.log(Level.INFO, name + "exportDataToHTML, unable to create temporary directory " + currentFolder + targetfolder.getAbsolutePath());
181 ServiceUnavailableException f = new ServiceUnavailableException("", null);
182 f.getFaultInfo().setCode(ServiceUnavailableFaultCodes.MISCONFIGURATION);
183 throw f;
184 }
185
186 header = getHeader();
187 footer = getFooter();
188
189 } catch (Exception e) {
190 log.log(Level.INFO, name + "exportDataToHTML, load props" + e);
191 ServiceUnavailableException f = new ServiceUnavailableException("", null);
192 f.getFaultInfo().setCode(ServiceUnavailableFaultCodes.MISCONFIGURATION);
193 throw f;
194 }
195 List<String> files = new ArrayList<String>();
196
197 Calendar time = null;
198
199 header = header.replaceAll("%DATETIME_NOW%",
200 new Date().toString());
201 time = request.getRange().getStart();
202 header = header.replaceAll("%DATETIME_FROM%",
203 time.getTime().toString());
204 time = request.getRange().getEnd();
205 header = header.replaceAll("%DATETIME_TO%",
206 time.getTime().toString());
207
208 if (request.getClassification() == null) {
209 request.setClassification(getClassLevelFromDB());
210 }
211 header = header.replaceAll("%CLASSIFICATION%", (Utility.ICMClassificationToString(request.getClassification().getClassification()) + " - " + request.getClassification().getCaveats()));
212 header = header.replaceAll("%COLOR%", Utility.ICMClassificationToColorCodeString(request.getClassification().getClassification()));
213
214 footer = footer.replaceAll("%CLASSIFICATION%", (Utility.ICMClassificationToString(request.getClassification().getClassification()) + " - " + request.getClassification().getCaveats()));
215 footer = footer.replaceAll("%COLOR%", Utility.ICMClassificationToColorCodeString(request.getClassification().getClassification()));
216
217 StringBuilder x = new StringBuilder();
218 x.append("<ul>");
219
220 if (request.isAllServices()) {
221 x.append(buildAllServiceList(request, currentUser));
222 } else {
223 for (int i = 0; i < request.getURLs().size(); i++) {
224
225 x.append("<li>").append(Utility.encodeHTML(request.getURLs().get(i))).append("</li>\n");
226 }
227 }
228 x.append("</ul>");
229
230 header = header.replaceAll("%SERVICE_LIST%", x.toString());
231
232 OutputStreamWriter fw = null;
233 try {
234 File f = new File(path + getFilePathDelimitor() + "index.html");
235 fw = new OutputStreamWriter(
236 new FileOutputStream(f), Constants.CHARSET);
237 List<String> urls = urlListRead(request.isAllServices(), request.getURLs(), currentUser, request.getClassification());
238
239 fw.write(header);
240 for (int i = 0; i < request.getReportTypes().getReportTypeContainer().size(); i++) {
241 ReportGeneratorPlugin plugin=null;
242 String name = request.getReportTypes().getReportTypeContainer().get(i).getType();
243 if (reportingPlugins.containsKey(name)){
244 plugin = reportingPlugins.get(name);
245 }
246 if (plugin==null) {
247 try{
248 plugin = (ReportGeneratorPlugin)Class.forName(name).newInstance();
249 reportingPlugins.put(name, plugin);
250 }catch (Throwable t) {
251 log.log(Level.WARN, name + " could not load the user specified reporting plugin", t);
252 }
253 }
254 if (plugin == null) {
255 throw new IllegalArgumentException("unknwon report type;" + request.getReportTypes().getReportTypeContainer().get(i).getType());
256 }
257 plugin.generateReport(fw, urls, path, files, request.getRange(), currentUser, getClassLevelFromDB(), ctx);
258 }
259
260 fw.write(footer);
261 fw.flush();
262 } catch (IllegalArgumentException ex) {
263 throw ex;
264 } catch (Exception e) {
265 log.log(Level.INFO, name + "WriteAllText, ", e);
266 } finally {
267 if (fw != null) {
268 try {
269 fw.close();
270 } catch (IOException ex) {
271 log.log(Level.INFO, name + "WriteAllText, ", ex);
272 }
273 }
274 }
275
276 x = null;
277
278 files.add(path + getFilePathDelimitor() + "index.html");
279 ExportDataToHTMLResponseMsg response = new ExportDataToHTMLResponseMsg();
280 response.setClassification(getClassLevelFromDB());
281 response.setZipFile(generateZipFileandDelete(files, path));
282 return response;
283
284 }
285
286 protected String getHeader() {
287 String x = null;
288 InputStream s = null;
289 try {
290 s = this.getClass().getClassLoader().getResourceAsStream("org/miloss/fgsms/services/rs/impl/header.txt");
291 x = readAllText(s);
292
293 } catch (Exception ex) {
294 log.error(null, ex);
295 } finally {
296 if (s != null) {
297 try {
298 s.close();
299 } catch (IOException ex) {
300 }
301 }
302 }
303 return x;
304 }
305
306 protected String getFooter() {
307 String x = null;
308 InputStream s = null;
309 try {
310 s = this.getClass().getClassLoader().getResourceAsStream("org/miloss/fgsms/services/rs/impl/footer.txt");
311 x = readAllText(s);
312
313 } catch (Exception ex) {
314 log.error(null, ex);
315 } finally {
316 if (s != null) {
317 try {
318 s.close();
319 } catch (IOException ex) {
320 }
321 }
322 }
323 return x;
324
325 }
326
327 private String buildAllServiceList(ExportDataRequestMsg request, String currentUser) {
328 List<String> urls = urlListRead(request.isAllServices(), request.getURLs(), currentUser, request.getClassification());
329 StringBuilder list = new StringBuilder();
330 for (int i = 0; i < urls.size(); i++) {
331 list.append("<li>").append(Utility.encodeHTML(urls.get(i))).append("</li>\n");
332 }
333 return list.toString();
334 }
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350 private List<String> urlListRead(boolean allServices, List<String> requestedurls, String currentUser, SecurityWrapper sec) {
351 List<String> urls = new ArrayList<String>();
352 if (allServices) {
353 Connection con = Utility.getConfigurationDBConnection();
354 PreparedStatement cmd = null;
355 ResultSet rs = null;
356 try {
357 if (UserIdentityUtil.hasGlobalAdministratorRole(currentUser, "GenerateReports", (sec), ctx)) {
358 cmd = con.prepareStatement("select URI from servicepolicies;");
359 } else {
360 cmd = con.prepareStatement("select ObjectURI as URI from UserPermissions "
361 + "where username=? and "
362 + "ReadObject=1 or WriteObject=1 or AdministerObject=1 or AuditObject=1;");
363 cmd.setString(1, currentUser);
364 }
365 rs = cmd.executeQuery();
366 while (rs.next()) {
367 urls.add(rs.getString("URI"));
368 }
369
370 } catch (Exception ex) {
371 log.log(Level.INFO, name + "GenerateReports", ex);
372 } finally {
373 DBUtils.safeClose(rs);
374 DBUtils.safeClose(cmd);
375 DBUtils.safeClose(con);
376 }
377 } else {
378
379 if (requestedurls != null
380 && requestedurls.size() > 0) {
381 for (int i = 0; i < requestedurls.size(); i++) {
382 urls.add(requestedurls.get(i));
383 UserIdentityUtil.assertReadAccess(urls.get(i), currentUser, "urlListRead", sec, ctx);
384 }
385 }
386 }
387 return urls;
388 }
389
390
391
392
393
394
395
396
397 protected static String readAllText(InputStream stream) {
398 try {
399
400 int size = 1024;
401 byte chars[] = new byte[size];
402 int k = stream.read(chars);
403 StringBuilder str = new StringBuilder();
404 while (k > 0) {
405
406 for (int i = 0; i < k; i++) {
407 str.append((char) chars[i]);
408 }
409 k = stream.read(chars);
410 }
411
412
413 return str.toString();
414
415 } catch (Exception e) {
416 log.log(Level.ERROR, name + "ReadAllText, ", e);
417
418 return "";
419 }
420 }
421
422 protected void writeAllText(String filename, String text) {
423 OutputStreamWriter fw = null;
424 try {
425 File f = new File(filename);
426
427 log.log(Level.INFO, "WriteAllText Current Dir = " + f.getName() + f.getAbsolutePath());
428 fw = new OutputStreamWriter(
429 new FileOutputStream(filename), Constants.CHARSET);
430
431 fw.write(text);
432 fw.flush();
433 } catch (Exception e) {
434 log.log(Level.INFO, name + "WriteAllText, ", e);
435 } finally {
436 if (fw != null) {
437 try {
438 fw.close();
439 } catch (IOException ex) {
440 log.log(Level.INFO, name + "WriteAllText, ", ex);
441 }
442 }
443 }
444 }
445
446 protected static byte[] generateZipFileandDelete(List<String> files, String path) {
447
448 log.log(Level.INFO, "Report Service, Building Zip file at " + path + " for " + files.size() + " files");
449
450 byte[] buf = new byte[1024];
451
452 ByteArrayOutputStream fos = null;
453 ZipOutputStream out = null;
454 try {
455
456
457
458 fos = new ByteArrayOutputStream();
459 out = new ZipOutputStream(fos);
460
461
462 for (int i = 0; i < files.size(); i++) {
463 String temp = files.get(i);
464 log.log(Level.DEBUG, "adding " + files.get(i) + " to the zip");
465 FileInputStream in = null;
466 try {
467 in = new FileInputStream(files.get(i));
468
469 ZipEntry z = new ZipEntry(temp.substring(temp.lastIndexOf(getFilePathDelimitor()) + 1));
470 out.putNextEntry(z);
471
472
473 int len;
474 while ((len = in.read(buf)) > 0) {
475 out.write(buf, 0, len);
476 }
477 out.closeEntry();
478 } catch (Exception ex) {
479
480 } finally {
481 if (in != null) {
482 in.close();
483 }
484 }
485
486 in = null;
487 }
488
489 out.flush();
490 out.finish();
491 out.flush();
492 out.close();
493 out = null;
494
495 fos.flush();
496 byte[] data = fos.toByteArray();
497 fos.close();
498 fos = null;
499
500 File f;
501 log.log(Level.DEBUG, "Zip file created at " + data.length + " bytes");
502 for (int i = 0; i < files.size(); i++) {
503 try {
504 f = new File(files.get(i)).getCanonicalFile();
505 f.setWritable(true);
506 if (f != null && !f.delete()) {
507 log.log(Level.WARN, "Error deleting file " + files.get(i));
508 f.deleteOnExit();
509 }
510
511 } catch (Exception ex) {
512 log.log(Level.WARN, "Error deleting file " + files.get(i), ex);
513 }
514 }
515 f = null;
516
517 try {
518
519
520 f = new File(path).getCanonicalFile();
521 f.setWritable(true);
522 if (!f.delete()) {
523 log.log(Level.WARN, "Error deleting temp folder" + path);
524 f.deleteOnExit();
525 }
526 } catch (Exception ex) {
527 log.log(Level.WARN, "Error deleting file " + path + getFilePathDelimitor() + "output.zip", ex);
528 }
529 return data;
530 } catch (IOException e) {
531 log.log(Level.INFO, name + "generateZipFileandDelete", e);
532 } finally {
533 if (fos != null) {
534 try {
535 fos.close();
536 } catch (Exception ex) {
537 log.log(Level.DEBUG, name + "generateZipFileandDelete", ex);
538 }
539 }
540 if (out != null) {
541 try {
542 out.close();
543 } catch (Exception ex) {
544 log.log(Level.DEBUG, name + "generateZipFileandDelete", ex);
545 }
546 }
547 }
548 return null;
549 }
550
551 protected SecurityWrapper getClassLevelFromDB() {
552 Connection con = Utility.getConfigurationDBConnection();
553 PreparedStatement com = null;
554 ResultSet rs = null;
555 try {
556 com = con.prepareStatement("select classification, caveat from globalpolicies;");
557 rs = com.executeQuery();
558 if (rs.next()) {
559 ClassificationType t = ClassificationType.fromValue(rs.getString(1));
560 String cav = rs.getString(2);
561 return new SecurityWrapper(t, cav);
562 } else {
563 log.log(Level.ERROR, "unable to determine current classification level, defaulting to UNCLASSIFIED");
564 return new SecurityWrapper(ClassificationType.U, "None");
565 }
566 } catch (SQLException ex) {
567 log.log(Level.ERROR, "error determining classification level from config db", ex);
568 log.log(Level.ERROR, "unable to determine current classification level, defaulting to UNCLASSIFIED");
569 return new SecurityWrapper(ClassificationType.U, "None");
570 } finally {
571 DBUtils.safeClose(rs);
572 DBUtils.safeClose(com);
573 DBUtils.safeClose(con);
574 }
575 }
576
577 public static int pixelHeightCalc(int items) {
578 if (items > 0 && items < 3) {
579 return items * 200;
580 }
581 if (items == 0) {
582 return 200;
583 }
584 return items * 50;
585
586 }
587
588
589
590
591
592
593
594
595
596
597
598
599
600 @WebMethod(operationName = "ExportDataToCSV", action = "urn:org:miloss:fgsms:services:interfaces:reportingService/reportingService/ExportDataToCSV")
601 @WebResult(name = "ExportDataToCSVResult", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService")
602 @RequestWrapper(localName = "ExportDataToCSV", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService", className = "org.miloss.fgsms.services.interfaces.reportingservice.ExportDataToCSV")
603 @ResponseWrapper(localName = "ExportDataToCSVResponse", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService", className = "org.miloss.fgsms.services.interfaces.reportingservice.ExportDataToCSVResponse")
604 public ExportDataToCSVResponseMsg exportDataToCSV(
605 @WebParam(name = "request", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:reportingService") ExportCSVDataRequestMsg request) throws ServiceUnavailableException {
606
607
608
609 String currentUser = UserIdentityUtil.getFirstIdentityToString(ctx);
610
611 if (request == null) {
612 AuditLogger.logItem(this.getClass().getCanonicalName(), "exportDataToHTML", currentUser, "null request", "not specified", ctx.getMessageContext());
613 throw new IllegalArgumentException("request is null");
614 }
615 Utility.validateClassification(request.getClassification());
616
617 if (request.getRange() == null) {
618 throw new IllegalArgumentException("time range");
619 }
620 if (request.getExportType() == null) {
621 throw new IllegalArgumentException("a records type must be specified");
622 }
623
624 UserIdentityUtil.assertGlobalAdministratorRole(currentUser, "exportDataToCSV", request.getClassification(), ctx);
625
626 return CsvExporter.exportDataToCSV(ctx, currentUser, getClassLevelFromDB(), request);
627
628 }
629
630 public static String getFilePathDelimitor() {
631
632 return File.separator;
633
634 }
635
636 public static boolean isPolicyTypeOf(String uri, PolicyType p) {
637 Connection con = Utility.getConfigurationDBConnection();
638 PreparedStatement com = null;
639 ResultSet rs = null;
640 try {
641 com = con.prepareStatement("select policytype from servicepolicies where uri=?");
642 com.setString(1, uri);
643 rs = com.executeQuery();
644 if (rs.next()) {
645 int x = rs.getInt(1);
646 if (PolicyType.values()[x].equals(p)) {
647 return true;
648 }
649 }
650
651 } catch (Exception ex) {
652 log.log(Level.WARN, null, ex);
653 } finally {
654 DBUtils.safeClose(rs);
655 DBUtils.safeClose(com);
656 DBUtils.safeClose(con);
657 }
658 return false;
659
660 }
661
662 protected static String toSafeFileName(String url) {
663 if (Utility.stringIsNullOrEmpty(url)) {
664 return "EmptyFileName";
665 }
666 String s = url;
667 s = s.replace("-", "--");
668 s = s.replace('/', '-');
669 s = s.replace('\\', '-');
670 s = s.replace(':', '-');
671 s = s.replace('*', '-');
672 s = s.replace('|', '-');
673 s = s.replace('<', '-');
674 s = s.replace('>', '-');
675 s = s.replace('?', '-');
676 s = s.replace('"', '-');
677 s = s.replace('%', '-');
678 s = s.replace('"', '-');
679 s = s.replace('{', '-');
680 s = s.replace('}', '-');
681 s = s.replace('[', '-');
682 s = s.replace(']', '-');
683 s = s.replace('~', '-');
684 s = s.replace('!', '-');
685 s = s.replace('$', '-');
686 s = s.replace('&', '-');
687 s = s.replace(';', '-');
688 s = s.replace('#', '-');
689 s = s.replace('@', '-');
690 s = s.replace('(', '-');
691 s = s.replace(')', '-');
692
693 return s;
694 }
695
696 protected static String stripCommas(String string) {
697 if (Utility.stringIsNullOrEmpty(string)) {
698 return string;
699 }
700 return string.replace(',', ' ').trim();
701 }
702
703
704
705
706
707
708
709
710 @WebMethod(operationName = "GetOperatingStatus", action = "urn:org:miloss:fgsms:services:interfaces:opStatusService/GetOperatingStatus")
711 @WebResult(name = "response", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:common")
712 @RequestWrapper(localName = "GetOperatingStatus", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:common", className = "org.miloss.fgsms.services.interfaces.common.GetOperatingStatus")
713 @ResponseWrapper(localName = "GetOperatingStatusResponse", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:common", className = "org.miloss.fgsms.services.interfaces.common.GetOperatingStatusResponse")
714 public GetOperatingStatusResponseMessage getOperatingStatus(
715 @WebParam(name = "request", targetNamespace = "urn:org:miloss:fgsms:services:interfaces:common") GetOperatingStatusRequestMessage request) {
716 String currentUser = UserIdentityUtil.getFirstIdentityToString(ctx);
717
718 Utility.validateClassification(request.getClassification());
719 AuditLogger.logItem(this.getClass().getCanonicalName(), "getOperatingStatus", currentUser, "", (request.getClassification()), ctx.getMessageContext());
720
721 GetOperatingStatusResponseMessage res = new GetOperatingStatusResponseMessage();
722
723 res.setClassification(request.getClassification());
724 res.setVersionInfo(new GetOperatingStatusResponseMessage.VersionInfo());
725 res.getVersionInfo().setVersionData(org.miloss.fgsms.common.Constants.Version);
726 res.getVersionInfo().setVersionSource(org.miloss.fgsms.common.Constants.class.getCanonicalName());
727 res.setStartedAt(started);
728 boolean ok = true;
729 Connection con = Utility.getConfigurationDBConnection();
730 Connection con2 = Utility.getPerformanceDBConnection();
731 PreparedStatement prepareStatement = null;
732 PreparedStatement prepareStatement2 = null;
733 try {
734 prepareStatement = con.prepareStatement("select 1=1;");
735 prepareStatement.execute();
736
737 prepareStatement2 = con2.prepareStatement("select 1=1;");
738 prepareStatement2.execute();
739 res.setStatusMessage("OK");
740 } catch (Exception ex) {
741 ok = false;
742 res.setStatusMessage("One or more of the database connections is available");
743 } finally {
744 DBUtils.safeClose(prepareStatement);
745 DBUtils.safeClose(prepareStatement2);
746 DBUtils.safeClose(con);
747 DBUtils.safeClose(con2);
748 }
749 res.setStatus(ok);
750 return res;
751 }
752
753
754 }