• No results found

C. SOA PROTOTYPE SYSTEM

6. Reconstruction Project KML servlet

The second 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.

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 single parameter, sector embedded in the URL. The sector variable is used by the servlet to obtain the reconstruction sector desired by the user, in this case the electric sector “ELEC” is desired. 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 <?xml version="1.0" encoding="UTF-8"?>

<NetworkLink>

<description>Track Updates Every 45 Seconds</description> <name>Iraq Reconstruction Projects</name>

<visibility>0</visibility>

<url>http://localhost:8080/iraqdemoproj/iraqdemoprojsev?sector=ELEC</url> <refreshPeriod>45</refreshPeriod>

<refreshVisibility>1</refreshVisibility> </NetworkLink>

• Conduct an SQL query of the RECON database for the sector prescribed by the parameter.

• Convert the results of the SQL query into a KML formatted message • Push the results to the Google Earth client employing the doGet respond

method

The first section of source code highlighted below shows the doGet(HttpServlet request and response) method. Note the sector parameter is called using a

request.getParameter call that looks for the sector string variable. Also note the CONTENT_TYPE output format of text/html. This sets the output of the servlet response.

The next section of source code will examine the database query action. In the public class reconKML 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 sector = request.getParameter("sector"); Timestamp OccuredWhen;

String ProjName = "begin"; String tempQuery = "null"; String ProjectID = "null"; String Contractor = "null";

String ExecutingAgency = "null"; ….

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 direct the Google Earth client which icon and label font to display 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 a 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.

queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "SELECT RMS_ALL.SHORT_NAME,RMS_ALL.URI,RMS_ALL.GRID_LOCATION" + " FROM \"C:\\Documents and Settings\\kjrothen\\My Documents\\RMS_ALL\".RMS_ALL" + " WHERE SECTOR = '"+sector+ "' ", null, true, Load.ALL));

database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:RMS_ALL", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver")); database1.setUseCaseSensitiveId(true); database1.setUseSpacePadding(false); database1.setDatabaseName(""); queryDataSet1.open(); …

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</name>\n"); out.write("<open>1</open>\n"); out.write( "<description><![CDATA[SAMPLE/]></description>\n"); out.write("<Style id=\"ELE\">"); out.write(" <IconStyle>\n"); out.write(" <color>FFFF55FF</color>\n"); out.write(" <Icon>\n"); out.write(" <href>root://icons/palette-4.png</href>\n"); out.write("<LabelStyle>"); out.write(" <color>ffb3cefc</color>\n"); out.write("<scale>1.1</scale>"); out.write("</LabelStyle>"); queryDataSet1.first(); while (queryDataSet1.inBounds()) { String style = ""; ProjName = queryDataSet1.getString("SHORT_NAME"); String MGRS = queryDataSet1.getString("GRID_LOCATION"); Position R = MGRStoLat(MGRS); userlat = R.getLat(); userlon = R.getLng();

String klmString = "<Placemark>\n"

+ "<styleUrl>" + style + "</styleUrl>\n" + "<Point>\n"

+ "<extrude>0</extrude>\n"

+ "<altitudeMode>clampedToGround</altitudeMode>\n" + "<coordinates>" + userlon + "," + userlat +

"</coordinates>\n" + "</Point>\n" + "</Placemark>\n";

This section documented the Reconstruction Project servlet, we will next examine the New Track servlet.