1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.miloss.fgsms.agentcore;
22
23 import java.util.Map;
24 import javax.xml.ws.BindingProvider;
25 import org.miloss.fgsms.common.Utility;
26 import org.miloss.fgsms.services.interfaces.datacollector.AddStatisticalDataRequestMsg;
27 import org.miloss.fgsms.services.interfaces.datacollector.AddStatisticalDataResponseMsg;
28 import org.apache.log4j.Level;
29 import org.miloss.fgsms.common.Logger;;
30
31
32
33
34
35
36
37
38
39
40 public class StatisticalHelper extends HelperBase{
41
42 protected static ConfigLoader cfg = null;
43 static Logger log = Logger.getLogger(org.miloss.fgsms.common.Constants.LoggerName);
44
45 private static void Init() throws ConfigurationException {
46 if (cfg == null) {
47 cfg = new ConfigLoader();
48 }
49
50 }
51
52
53
54
55
56
57
58
59
60
61
62 public static boolean send(AddStatisticalDataRequestMsg req) throws ConfigurationException {
63 if (cfg == null) {
64 Init();
65 }
66 discoverEndpoints();
67 req.setClassification(cfg.classlevel);
68 int retrycount = 0;
69 int urlcount = 0;
70 switch (cfg.DCSalgo) {
71 case FAILOVER:
72 retrycount = 0;
73 urlcount = 0;
74 while ((retrycount < cfg.DCSRetryCount)) {
75
76 urlcount = 0;
77 while (urlcount < cfg.DCS_URLS.size()) {
78 try {
79
80 BindingProvider bp = (BindingProvider) cfg.dcsport;
81 Map<String, Object> context = bp.getRequestContext();
82
83 context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, cfg.DCS_URLS.get(urlcount));
84 if (cfg.mode_ == org.miloss.fgsms.common.Constants.AuthMode.UsernamePassword) {
85 context.put(BindingProvider.USERNAME_PROPERTY, cfg.username);
86 context.put(BindingProvider.PASSWORD_PROPERTY, Utility.DE(cfg.password));
87 }
88 if (Utility.stringIsNullOrEmpty(System.getProperty("javax.net.ssl.trustStore")) && !Utility.stringIsNullOrEmpty(System.getProperty("javax.net.ssl.trustStorePassword"))) {
89 context.put("javax.net.ssl.trustStorePassword", Utility.DE(cfg.getJavaxtruststorepass()));
90 context.put("javax.net.ssl.trustStore", Utility.DE(cfg.getJavaxtruststore()));
91 }
92 try {
93 if (cfg.mode_ == org.miloss.fgsms.common.Constants.AuthMode.PKI) {
94 if (Utility.stringIsNullOrEmpty(System.getProperty("javax.net.ssl.keyStore")) && !Utility.stringIsNullOrEmpty(System.getProperty("javax.net.ssl.keyStorePassword"))) {
95 context.put("javax.net.ssl.keyStorePassword", Utility.DE(cfg.getJavaxkeystorepass()));
96 context.put("javax.net.ssl.keyStore", Utility.DE(cfg.getJavaxkeystore()));
97 }
98 }
99
100 } catch (Exception ex) {
101 log.log(Level.FATAL, "error caught when referencing (get or set) System.properties for SSL communication. Check to ensure that this is enabled in your JAAS managemer", ex);
102 }
103
104 AddStatisticalDataResponseMsg addStatisticalData = cfg.dcsport.addStatisticalData(req);
105 cfg.classlevel = addStatisticalData.getClassification();
106
107 return true;
108
109
110 } catch (Exception ex) {
111 log.log(Level.WARN, "fgsms unable to transmit to CS at " + cfg.DCS_URLS.get(urlcount) + " will retry " + (cfg.DCSRetryCount - retrycount) + " times." + ex.getMessage(), ex);
112 }
113 urlcount++;
114 }
115 retrycount++;
116 }
117
118 log.log(Level.FATAL, "fgsms unable to transmit to any of the DCS[" + cfg.DCS_URLS.size() + "] URLs, retry count exceeded. Falling back to default policy");
119 return false;
120 case ROUNDROBIN:
121 retrycount = 0;
122 urlcount = 0;
123 while ((retrycount < cfg.DCSRetryCount)) {
124
125 urlcount = 0;
126 while (urlcount < cfg.DCS_URLS.size()) {
127 try {
128
129 BindingProvider bp = (BindingProvider) cfg.dcsport;
130 Map<String, Object> context = bp.getRequestContext();
131
132 context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, cfg.DCS_URLS.get(urlcount));
133
134 if (cfg.mode_ == org.miloss.fgsms.common.Constants.AuthMode.UsernamePassword) {
135
136 context.put(BindingProvider.USERNAME_PROPERTY, cfg.username);
137 context.put(BindingProvider.PASSWORD_PROPERTY, Utility.DE(cfg.password));
138 }
139 if (cfg.mode_ == org.miloss.fgsms.common.Constants.AuthMode.PKI) {
140 if (Utility.stringIsNullOrEmpty(System.getProperty("javax.net.ssl.keyStore")) && !Utility.stringIsNullOrEmpty(System.getProperty("javax.net.ssl.keyStorePassword"))) {
141 System.setProperty("javax.net.ssl.keyStorePassword", Utility.DE(cfg.getJavaxkeystorepass()));
142 System.setProperty("javax.net.ssl.keyStore", Utility.DE(cfg.getJavaxkeystore()));
143 }
144 }
145 if (Utility.stringIsNullOrEmpty(System.getProperty("javax.net.ssl.trustStore")) && !Utility.stringIsNullOrEmpty(System.getProperty("javax.net.ssl.trustStorePassword"))) {
146 System.setProperty("javax.net.ssl.trustStorePassword", Utility.DE(cfg.getJavaxtruststorepass()));
147 System.setProperty("javax.net.ssl.trustStore", Utility.DE(cfg.getJavaxtruststore()));
148 }
149
150 AddStatisticalDataResponseMsg addStatisticalData = cfg.dcsport.addStatisticalData(req);
151 cfg.classlevel = addStatisticalData.getClassification();
152 return true;
153 } catch (Exception ex) {
154 log.log(Level.WARN, "fgsms unable to transmit to DCS at " + cfg.DCS_URLS.get(urlcount) + " will retry " + (cfg.DCSRetryCount - retrycount) + " times." + ex.getMessage(), ex);
155 }
156 urlcount++;
157 }
158 retrycount++;
159 }
160 log.log(Level.FATAL, "fgsms unable totransmit to any of the DCS[" + cfg.DCS_URLS.size() + "] URLs, retry count exceeded.");
161 }
162 return false;
163 }
164 }