View Javadoc
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.plugins;
22  
23  import java.net.URL;
24  import java.util.ArrayList;
25  import java.util.GregorianCalendar;
26  import java.util.List;
27  import java.util.concurrent.atomic.AtomicReference;
28  import java.util.logging.Level;
29  import java.util.logging.Logger;
30  import javax.xml.datatype.DatatypeFactory;
31  import javax.xml.ws.BindingProvider;
32  import javax.xml.ws.WebServiceFeature;
33  import org.miloss.fgsms.plugins.sla.alertservice.AlertRecieverPortType;
34  import org.miloss.fgsms.plugins.sla.alertservice.AlertRecieverService;
35  import org.miloss.fgsms.common.DBSettingsLoader;
36  import org.miloss.fgsms.common.Utility;
37  import org.miloss.fgsms.plugins.sla.AlertContainer;
38  import org.miloss.fgsms.plugins.sla.SLAActionInterface;
39  import org.miloss.fgsms.services.interfaces.common.NameValuePair;
40  import org.miloss.fgsms.services.interfaces.common.PolicyType;
41  import org.miloss.fgsms.services.interfaces.policyconfiguration.KeyNameValueEnc;
42  
43  /**
44   * This sample action calls a remote web service when the rule is triggered
45   * @author AO
46   * @since 6.2
47   */
48  public class CustomSLAAction implements SLAActionInterface {
49  
50      
51     
52      private URL LoadWSDL() {
53          URL wsdl = null;
54          try {
55              wsdl = Thread.currentThread().getContextClassLoader().getResource("META-INF/SLAPluginWebService.wsdl");
56          } catch (Exception ex) {
57          }
58          try {
59              wsdl = Thread.currentThread().getContextClassLoader().getResource("/META-INF/SLAPluginWebService.wsdl");
60          } catch (Exception ex) {
61          }
62          try {
63              wsdl = this.getClass().getClassLoader().getResource("/META-INF/SLAPluginWebService.wsdl");
64          } catch (Exception ex) {
65          }
66          try {
67              wsdl = this.getClass().getClassLoader().getResource("META-INF/SLAPluginWebService.wsdl");
68          } catch (Exception ex) {
69          }
70  
71          return wsdl;
72      }
73  
74   
75      @Override
76      public List<NameValuePair> GetRequiredParameters() {
77          return new ArrayList<NameValuePair>();
78      }
79  
80      @Override
81      public List<NameValuePair> GetOptionalParameters() {
82          return new ArrayList<NameValuePair>();
83      }
84  
85      @Override
86      public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError) {
87          return true;
88      }
89  
90      @Override
91      public String GetHtmlFormattedHelp() {
92          return "Hello World";
93      }
94  
95      @Override
96      public String GetDisplayName() {
97          return "Custom SLA Action Example";
98      }
99  
100     @Override
101     public void ProcessAction(AlertContainer alert, List<NameValuePair> params) {
102            try {
103             KeyNameValueEnc settings = DBSettingsLoader.GetPropertiesFromDB(true, "SDK.Samples.AlertRecieverService", "URL");
104             if (settings != null && settings.getKeyNameValue() != null && settings.getKeyNameValue().getPropertyValue() != null) {
105                 AlertRecieverService svc = new AlertRecieverService(LoadWSDL());
106 
107                 AlertRecieverPortType port = svc.getAlertRecieverPort();
108                 BindingProvider bp = (BindingProvider) port;
109                 bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, settings.getKeyNameValue().getPropertyValue());
110                 DatatypeFactory fac = DatatypeFactory.newInstance();
111                 GregorianCalendar gcal = new GregorianCalendar();
112                 gcal.setTimeInMillis(System.currentTimeMillis());
113 
114                 port.recieveServiceAlert(gcal, alert.getSLAID() + " " + alert.getFaultMsg() + " " + alert.getModifiedurl());
115             } else {
116                 Logger.getLogger("SDK.Samples.AlertRecieverService").log(Level.WARNING, "Plugin SDK.Samples.AlertRecieverService is not configured, add the general setting SDK.Samples.AlertRecieverService, URL");
117             }
118         } catch (Exception ex) {
119             ex.printStackTrace();
120         }
121     }
122 
123     @Override
124     public List<PolicyType> GetAppliesTo() {
125         return Utility.getAllPolicyTypes();
126     }
127 }