/** Copyright 2003 Akamai Technologies, Inc. The information herein is proprietary
* and confidential to Akamai, and it may only be used under appropriate agreements
* with the Company. Access to this information does not imply or grant you any right
* to use the information, all such rights being expressly reserved.
*/
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.akamai.ej.apputil.edgescape.*;
public class EdgeScapeTest extends HttpServlet {
//Initialize global variables
public void init() throws ServletException { }
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
ServletOutputStream out = response.getOutputStream();
/**
* To test EdgeScapeData API using JTS, pass the following HTTP
* header from your client in the request. Example:
*
* X-Akamai-Edgescape: georegion=263,country_code=US,region_code=MA,city=CAMBRIDGE,dma=506,pmsa=1120,msa=,areacode=617,county=MIDDLESEX,fips=25017,lat=42.3933,long=-71.1333,timezone=EST,zip=02138-02142+02238-02239,continent=NA,network=,network_type=,asnum=21399,throughput=vhigh
*/
EdgeScapeData geoData = new EdgeScapeData(request);
/**
* Obtaining geo-data info using convenience methods
*/
out.println("<HTML><BODY>");
out.println("<P><B>Geo-data obtained using convenience methods: </B>");
out.println("<BR>COUNTRY : " + geoData.getCountryCode());
out.println("<BR>REGION : " + geoData.getGeoRegion());
out.println("<BR>REGION CODE: " + geoData.getRegionCode());
out.println("<BR>CITY : " + geoData.getCity());
out.println("<BR>DMA : " + geoData.getDma());
out.println("<BR>PMSA : " + geoData.getPmsa());
out.println("<BR>MSA : " + geoData.getMsa());
out.println("<BR>AREA CODE : " + geoData.getAreaCode());
out.println("<BR>COUNTY : " + geoData.getCounty());
out.println("<BR>FIPS : " + geoData.getFips());
out.println("<BR>LAT : " + geoData.getLat());
out.println("<BR>LONG : " + geoData.getLong());
out.println("<BR>TIME ZONE :" + geoData.getTimeZone());
out.println("<BR>NETWORK : " + geoData.getNetwork());
out.println("<BR>NETWORK TYPE : " + geoData.getNetworkType());
out.println("<BR>THROUGHPUT : " + geoData.getThroughput());
out.println("<P><B>Geo-data obtained using the Iterator: </B>");
/**
* Obtaining and iterating through a geo-data collection
*/
Collection geoDataCollection = geoData.getAll();
Iterator iterator = geoDataCollection.iterator();
for (; iterator.hasNext();) {
String nextItem = (String)iterator.next();
out.println("<BR> " + nextItem + " = " );
out.println(geoData.getAttribute(nextItem));
}
/**
* Obtaining the geoData using getAttribute(...) method
*/
String geoRegion = geoData.getAttribute("georegion");
out.println("<P><B>Geo-data obtained using getAttribute(\"georegion\"): </B> " + geoRegion);
String geoAsnum = geoData.getAttribute("asnum");
out.println("<P><B>Geo-data obtained using getAttribute(\"asnum\"): </B> " + geoAsnum);
String geoZip = geoData.getAttribute("zip");
out.println("<P><B>Geo-data obtained using getAttribute(\"zip\"): </B> " + geoZip);
String test1 = geoData.getAttribute(null);
out.println("<P><B>Geo-data obtained using getAttribute(null): </B> " + test1);
out.println("<P><B>DONE</B></BODY></HTML>");
}
}