• No results found

C. SOA PROTOTYPE SYSTEM

5. SIGACT KML Servlet

The first servlet we will review provides a dynamic KML formatted message to Google Earth. The architecture employs a ReST model and does not use SOAP messages but rather sends the data directly over HTTP using the doGet and doPost java methods. We will examine two files for the servlet. One is the KML file that Google Earth opens that provides the location and refresh rate of the servlet, the other is the servlet source code. Similar to the previous sections only critical portions of the source code are placed in the gray boxes with all the source code available in appendix A and binaries available from the Naval Postgraduate School.

The XML file below is opened by Google Earth to direct the client to interface with a servlet to obtain overlays. The first highlighted section provides the location of the servlet. As in previous sections, localhost is employed to assist in duplicating the prototype, however any IP address or port can be employed. Note the two parameters embedded in the URL. They include a start and stop date. Those dates are used by the servlet to obtain the period desired by the user. The second highlighted section in a red box shows the desired refresh rate. In this case the 45 seconds, directs the client to execute a refresh from the servlet at the determine interval.

Next let’s examine the Java Servlet source code. The servlet conducts a number of functions to include:

• Performing the doGet function and receive the parameters from the URL • Conduct an SQL query of the SIGACT database for the period prescribed

by the parameters

• Convert the results of the SQL query into a KML formatted message • Push the results to the Google Earth client employing the doGet method We will examine the major processing logic in the below section.

The first section of source code highlighted below shows the doGet(HttpServlet request and response) method. Note the start and finish parameters are called using a request.getParameter call that looks for the start and finish string variables. Also note the CONTENT_TYPE output format of text/html. This sets the output of the servlet

response.

<?xml version="1.0" encoding="UTF-8"?> <NetworkLink>

<description>Track Updates Every 45 Seconds</description> <name>Significent Attack Postion Feed</name>

<visibility>0</visibility> <url>http://localhost:8080/sigactKMLV3/learnerServ?start=07-01- 2000&amp;finish=07-01-2008</url> <refreshPeriod>45</refreshPeriod> <refreshVisibility>1</refreshVisibility> </NetworkLink>

The next section of source code will examine the database query action. In the case of the KML servlets we employ the boreland© database methods to conduct the queries. The first highlighted section shows the embedding of the start and finish dates in the SQL query. The second highlighted section shows the database interface driver.

public class sigactMLV3 extends HttpServlet {

private static final String CONTENT_TYPE = "text/html"; Database database1 = new Database();

QueryDataSet queryDataSet1 = new QueryDataSet();

DBDisposeMonitor dBDisposeMonitor1 = new DBDisposeMonitor();

//Process the HTTP Get request

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String start = request.getParameter("start"); String finish = request.getParameter("finish");

Timestamp OccuredWhen; String EventType = "begin"; String Name = "null"; String Relative = "null"; String Location = "null"; String MGRS = "null"; …. queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "SELECT SIGACT.EventType,SIGACT.EventCategory,SIGACT.OccuredWhen,SIGACT.Poste dWhen,SIGACT.region,SIGACT.MGRS,SIGACT.PrimaryTarget,SIGACT.TargetCat egory,SIGACT.City,SIGACT.Province FROM \"C:\\Documents and

Settings\\kjrothen\\My Documents\\SIGACT\".SIGACT"

+ " WHERE OccuredWhen BETWEEN #" + start + "# AND #" + finish + "# ", null, true, Load.ALL));

The final section we will examine is the KML formatting code. The KML format is documented via Google Earth’s tutorial [GOOGLE EARTH], however some key elements are highlighted below. The top section of the KML file is a header which describes attributes such as icon and label style, the second portion of the KML file is a repeating element where each object is described. For the file shown below, first note the icon and label style descriptions, which provide the Google Earth client with icon and label font information for each object. The second highlighted section shows the procedure employed to write the output of the database to the KML document. The prototype uses an while loop based on remaining objects in the query set. The third highlighted section shows where a conversion from Military Grid Reference System to latitude and longitude is executed using the position method. The EJB section has a more detailed explanation of the MGRS to LL conversion, however the source code is adapted from National Geo-spatial Agency (NGA) source code available via the NGA site and employed by the eXtensible Tactical C4I Framework (XTCF) project at SPAWAR San Diego labs. The final section highlighted is where the latitude and longitude position is placed in the KML file.

out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); out.write("<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"); out.write("<Document>\n");

out.write("<name> USACE Map Creater (SIGACT)</name>\n"); out.write("<open>1</open>\n"); out.write("<description><![SAMPLE DATA]></description>\n"); out.write("<Style id=\"Standard\">"); out.write(" <IconStyle>\n"); out.write(" <color>ff0000ff</color>\n"); out.write(" <Icon>\n"); out.write(" <href>root://icons/palette-4.png</href>\n"); …. out.write("</IconStyle>\n"); out.write("<LabelStyle>"); …..

out.write("<name>SIGACT " + start + " to " + finish + "</name>\n"); out.write("<open>0</open>\n"); out.write("/Folder>\n"); queryDataSet1.first(); while (queryDataSet1.inBounds()) { ++mapcountstart; // String style = ""; EventType = queryDataSet1.getString("EventType");

String EventCategory = queryDataSet1.getString("EventCategory"); OccuredWhen = queryDataSet1.getTimestamp("OccuredWhen"); MGRS = queryDataSet1.getString("MGRS"); String MGR = MGRS.replaceAll(" ", ""); Position R = MGRStoLat(MGR); userlat = R.getLat(); userlon = R.getLng();

String klmString = "<Placemark>\n"

+ "<name>"+ EventCategory+ "</name>\n"

+"<description><![CDATA[Name-"+ EventType + "<br /> Occured-" + OccuredWhen + "<br /> Target-" + PrimaryTarget +…

This section documented the SIGACT servlet, we will next examine the Reconstruction Project Servlet.