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   *  U.S. Government, Department of the Army
15   *  Army Materiel Command
16   *  Research Development Engineering Command
17   *  Communications Electronics Research Development and Engineering Center
18   *  ---------------------------------------------------------------------------
19   */
20  package org.miloss.fgsms.examples.export;
21  
22  import java.nio.file.AccessDeniedException;
23  import javax.naming.ServiceUnavailableException;
24  import javax.xml.bind.JAXB;
25  import javax.xml.ws.BindingProvider;
26  import org.miloss.fgsms.services.interfaces.common.SecurityWrapper;
27  import org.miloss.fgsms.services.interfaces.dataaccessservice.DataAccessService;
28  import org.miloss.fgsms.services.interfaces.dataaccessservice.DataAccessService_Service;
29  import org.miloss.fgsms.services.interfaces.dataaccessservice.GetMessageLogsResponseMsg;
30  import org.miloss.fgsms.services.interfaces.dataaccessservice.GetMonitoredServiceListRequestMsg;
31  import org.miloss.fgsms.services.interfaces.dataaccessservice.GetMonitoredServiceListResponseMsg;
32  import org.miloss.fgsms.services.interfaces.dataaccessservice.GetRecentMessageLogsRequestMsg;
33  import us.gov.ic.ism.v2.ClassificationType;
34  
35  public class ExportViaWS {
36  
37      public static void main(String args[]) throws AccessDeniedException, ServiceUnavailableException, Exception {
38          if (args.length != 3) {
39              System.out.println("Usage java -jar ExportDataFromViaWebService.jar <URL to DAS Service> <Admin username> <password>");
40              return;
41          }
42  
43          DataAccessService_Service svc = new DataAccessService_Service();
44          DataAccessService dasPort = svc.getDASPort();
45          BindingProvider bp = (BindingProvider) dasPort;
46          bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, args[0]);
47          bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, args[1]);
48          bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, args[2]);
49  
50          //get the list of services that are monitored that "username" has at least read access to
51          GetMonitoredServiceListRequestMsg req = new GetMonitoredServiceListRequestMsg();
52          req.setClassification(new SecurityWrapper(ClassificationType.U, ""));
53          GetMonitoredServiceListResponseMsg response = dasPort.getMonitoredServiceList(req);
54          if (response != null && response.getServiceList() != null && response.getServiceList() != null) {
55              System.out.println(response.getServiceList().getServiceType().size() + " services found");
56              for (int i = 0; i < response.getServiceList().getServiceType().size(); i++) {
57                  GetRecentMessageLogsRequestMsg req1 = new GetRecentMessageLogsRequestMsg();
58                  req1.setClassification(new SecurityWrapper(ClassificationType.U, ""));
59                  req1.setOffset(0);
60                  req1.setRecords(10);
61                  req1.setURL(response.getServiceList().getServiceType().get(i).getURL());
62                  GetMessageLogsResponseMsg recentMessageLogs = dasPort.getRecentMessageLogs(req1);
63                  //TODO loop the through the records and output what you want
64                  JAXB.marshal(recentMessageLogs, System.out);
65              }
66          } else {
67              System.out.println("no services found");
68          }
69  
70          //Get current status of a service
71          //TODO
72          //Get current statistics for a web service, availability for all others
73          //TODO
74      }
75  }