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  
22  package org.miloss.fgsms.presentation;
23  
24  import java.util.List;
25  import javax.xml.ws.BindingProvider;
26  import org.apache.log4j.Level;
27  import org.miloss.fgsms.common.Constants;
28  import org.miloss.fgsms.services.interfaces.agentcallbackservice.RemoteAgentCallbackPort;
29  import org.miloss.fgsms.services.interfaces.common.GetOperatingStatusRequestMessage;
30  import org.miloss.fgsms.services.interfaces.common.GetOperatingStatusResponseMessage;
31  import org.miloss.fgsms.services.interfaces.common.SecurityWrapper;
32  import org.miloss.fgsms.services.interfaces.policyconfiguration.PropertyPair;
33  import org.miloss.fgsms.services.interfaces.status.OpStatusService;
34  
35  /**
36   * This class provides an html render status indicator for an OS agent, given
37   * its hostname
38   *
39   * @author AO
40   */
41  public class OsAgentStatusHelper {
42  
43      public static String GetStatus(OpStatusService svc, String callbackUrl, SecurityWrapper c) {
44          GetOperatingStatusRequestMessage req = new GetOperatingStatusRequestMessage();
45          req.setClassification(c);
46          BindingProvider bp = (BindingProvider) svc;
47          bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, callbackUrl);
48          GetOperatingStatusResponseMessage operatingStatus;
49          try {
50              operatingStatus = svc.getOperatingStatus(req);
51              return OpStatHelper.toHtmlFormatedString(operatingStatus, callbackUrl);
52          } catch (Exception ex) {
53              LogHelper.getLog().log(Level.WARN, null, ex);
54              return ex.getMessage();
55          }
56      }
57  
58      /**
59       * returns true if the OS agent has reported its callback address
60       * @param list
61       * @return 
62       */
63      public static boolean ContainsOSAgentCallbackURL(List<PropertyPair> list) {
64          if (list == null) {
65              return false;
66          }
67          for (int i = 0; i < list.size(); i++) {
68              if (list.get(i).getPropertyname().equalsIgnoreCase(org.miloss.fgsms.common.Constants.PROPERTYPAIR_OS_AGENT_CALLBACK_URL)) {
69                  return true;
70              }
71          }
72          return false;
73      }
74  
75      /**
76       * Returns the url of the OS agent callback endpoint
77       *
78       * @param list
79       * @return null if not found, otherwise the value of the
80       */
81      public static String GetOSAgentCallBackURL(List<PropertyPair> list) {
82          if (list == null) {
83              return null;
84          }
85          for (int i = 0; i < list.size(); i++) {
86              if (list.get(i).getPropertyname().equalsIgnoreCase(org.miloss.fgsms.common.Constants.PROPERTYPAIR_OS_AGENT_CALLBACK_URL)) {
87                  return list.get(i).getPropertyvalue();
88              }
89          }
90          return null;
91      }
92  }