SolutionsTools & SDKSupport  



Quick Links
 
June 2003
 
 
Jack's Hack for the month of June, 2003:

Using Openwave Location Studio

This month in Jack's Hacks, we'll take a look at combining several Openwave server side technologies including WAP Push, MMS, and Location Studio. In case you missed us on the show floor at JavaOne, we were running a developer contest where we provisioned a phone number, 1-206-696-8500, in the developer instance of Location Studio. To win the phone, developers had to build an application that found the phone, and then sent its location back to via WAP Push or MMS. We want to congratulate our two winners who went home with brand spanking new Sharp GX-10i phones (with the Openwave 6.1 browser), and provide you with our solution code so you can see how it all fits together.

There are a couple pieces to the puzzle for an application to leverage location data from the network.

  1. Determine location
  2. Convert lat/lon into a street address, map, etc...
  3. Deliver data based on this location to the handset
Each of these three steps leverages different infrastructure and uses different libraries. Openwave provides infrastructure, tools, and sample code to accomplish tasks 1 and 3, and leverages our partners for step 2.

Starting at the top, Openwave Location Studio is the developer's interface into the location information that the wireless operators around the world have access to. Location access is restricted for privacy reasons. Developers must be granted access to Location Studio, and an end user must grant permission to disclose their location information. For enterprise customers, carriers may grant access in advance for device owned by the corporation (i.e. a taxi dispatch company would be able to query the location of every device that it pays the bill for). For developers Openwave has created a single developer account that can query the location of devices in our development environment. To be clear, the locations of the devices in Openwave Location Studio are not real, in that they are not being extracted from the network, but the response that Location Studio provides back to developers is "real".
To access Location Studio, use the id infoservdemo1 and a password of infoservdemo1 The code that actually results in obtaining the latitude and longitude of the subscriber is as simple as:


	 //retrieve the latitude and longitude
	  WLP10Position[] positions = responseL.getWLP10Position();
        if ( positions.length > 0 )
           {
               
             x = positions[0].getLatitude();
             y = positions[0].getLongitude();
           }
        }
Once the location of the subscriber was obtained, the next part of the contest was to convert the lat/lon into a real street address. This can be done by using any source for reverse geocoding. Openwave leveraged our relationship with Webraska and used the Smartzone Geospatial Platform to convert lat/lon into a street address and/or a map. Webraska has a full and vast array of geospatial functions in their platform, but we used they very simple URL based interface, and called it from a perl script

...
$x = $cgiVars{"x"};
$y=$cgiVars{"y"};

if ($x < 0.0){
$url="http://sgp3.na.developer.webraska.com/gns?mode=server_1.3&user=javaone&pass=speM4f2a&geolang=en&function=revgeo&wgs84=".$x."|".$y;
 }else{
  $url="http://sgp3.eu.developer.webraska.com/gns?mode=server_1.3&user=javaone&pass=speM4f2a&geolang=en&function=revgeo&wgs84=".$x."|".$y;

}
#retrieve response from location server (Webraska) and store the info in @response
if (&AppUtils::HTTPConnectAndBuffer($url, \@response)) {
...
We parse the resulting XML response to extract the location information to display. Since we built an interactive (rather than an automatic) application, we presented the user with an HTML page which presented the option of sending the information to the phone via a WAP Push or an MMS Message.



The Send MMS Message link kicks off a servlet that is a modified version of the servlet example that is packaged with the Openwave MM7 SDK. The core of the doGet method of our servlet include:


public void doGet(HttpServletRequest request, 
                    HttpServletResponse response)
            throws IOException, ServletException {
    String userName = "16504808000";
    String password = "developer";
    String mmscUrl = "http://skara.openwave.com:8080/mm7";
    Vector mmFiles = new Vector();
    mmFiles.add("/usr/local/java/tomcat4/webapps/java1/test1.txt");
    mmFiles.add("/usr/local/java/tomcat4/webapps/java1/map.gif");
    Vector recipients = new Vector();
    SubmitResponse resp = null;
	
	try{
    recipients.add( new Recipient( Recipient.Type.TO, Recipient.AddressType.NUMBER, "12066968500"));

                // create a connection to an relay and send the MM
                RelayConnection conn = RelayConnection.createSender( mmscUrl, userName, password );
                conn.setWeakCN( true );
                resp = sendMM( conn, userName, mmFiles, recipients ); 
				
	....			
	
The other solution would be to send a WAP Push message back to the handset. Since we did the work of creating the xhtml output in the getAddress.cgi script, we can simply push that URI to the handset The Send Push link invokes a sendPush servlet. This servlet was built from the samples that shipped with the Openwave WAP Push library. The core of the work done to send the push takes place in the submitMessage method of the servlet whcih looks like:


    String ppgAddress = "http://surf.openwave.com:9002/pap";
    String address = "12066968500/TYPE=PLMN@www.openwave.com";
    String SvcIndURI = URL;
    String pushID = Integer.toString((int) (Math.random()* 1000000000));
    URL ppgURL = null;
    URL siURI = null; 
    ppgURL = new URL (ppgAddress);
    siURI = new URL (SvcIndURI);
   
    //instantiate the PPG object
    Pusher ppg = new Pusher(ppgURL);
    //ppg.initialize();
    
    //this is the text string sent to the device 
    String alertText = title;
    //instantiate the Service Indication object
    ServiceIndication serviceIndication = new ServiceIndication(alertText);
    
    //set the URI for this SI
    serviceIndication.setHref(siURI);

    //set the Service Indication action to signal-high
    serviceIndication.setAction(ServiceIndicationAction.signalHigh);

    //instantiate the push message object 
    PushMessage pushMessage = new PushMessage(pushID, address);
    // Set the Quality of Service to high and confirmed always
    QualityOfService qos = new QualityOfService();
    qos.setDeliveryMethod(DeliveryMethod.unconfirmed);
    qos.setDeliveryPriority(DeliveryPriority.high);
    qos.setBearer("SMS");
    // Set the QoS for the Push Message
    pushMessage.setQualityOfService(qos);
    
    MimeEntity me = new MimeEntity();
    me.addEntity(pushMessage);
    me.addEntity(serviceIndication);
   
    //send the push message to the PPG
    PushResponse pushResponse = (PushResponse) ppg.send(me);
	
	
So to recap, to discover the location of the phone we used a servlet (location.java). This servlet passed the latitude and longitude off to a Perl script (getAddress.cgi) that made a call into the Webraska SmartZone Geospatial Platform, and displayed the resulting street address on an XHTML page. This page gave the option of sending and MMS Message (sendMMS.java), or a WAP Push (push.java).
Now, if you could have figured all of this out during the course of JavaOne, you too could have walked away with a spaking new Sharp GX-10i! If not, hey, that's ok too. Here is a zip file which contains all of the source files that we used to make this work.

 
Copyright © 2000-2008 Openwave Systems Inc.    Openwave  |  Terms & Conditions  |  Privacy Policy