Spot the International Space Station using third-party APIs and the Liberty runtime

11 August 2014
PDF (430 KB)
 

If you know when to look up, the International Space Station is easy to see. It's the third brightest object in the sky. I built the SPOT International Space Station (SPOT ISS) application so you can find the International Space Station from your city.

This application uses external third-party APIs to create a unique system of engagement and highlights the ease of creating, deploying, and managing applications using pre-built services and IBM DevOps Services. Although SPOT ISS is a hobbyist application, you can apply the concept and technical implementation to business scenarios using other third-party API services.

This application tells users when the International Space Station can be seen from their city. It uses third-party APIs to create a unique system of engagement, and it's deployed on Bluemix.

The third-party APIs used for this application include:

  • The NASA.gov RSS feed lists upcoming International Space Station sighting opportunities at a selected location. For example, see the XML feed returned for Houston, Texas.
  • The Open Notify API service is an open source project that provides interfaces to NASA data. This application uses an API that returns the current number of people in space and their names. See the JSON response from Open Notify.

What you'll need for your application

 

Step 1. Fork the application

 

Click the Get the code button above, and fork the project on DevOps Services:

  1. Click EDIT CODE (enter your DevOps Services credentials if you're not already signed in). SPOT ISS is a simple application with a single JSP file: spotSpaceStation.jsp.
  2. Click FORK to create a new project.
  3. When you see the prompt, name your new project and click Save to create a copy of the code in your project.

Step 2. Build and deploy

 
  1. Click BUILD & DEPLOY in the top right corner: BUILD & DEPLOY button
  2. The BUILD & DEPLOY screen offers SIMPLE and ADVANCED choices for deployment. Select SIMPLE, which turns on and starts automatic deployment for your new project. Choose SIMPLE to turn on autodeployment

    Click to see larger image

  3. When deployment is complete, the status message is updated and you see the MANAGE button next to CONFIGURE. Click MANAGE, which redirects you to the Bluemix Dashboard page. Routes and the CODE link are automatically created with the Git integration aligned to the Bluemix project. The Liberty profile runtime is configured automatically for this application. Java Liberty Profile configures automatically

    Click to see larger image

  4. Click the Routes link to test the application. It opens the application URL in a new browser window, where you can view and test the application.
  5. A new application is created automatically on your Bluemix dashboard. You can modify or enhance the application's functionality and perform automatic and iterative deployments. Modify the app's functionality

Consuming the RSS feed of International Space Station sightings

 

The SPOT ISS application contains a single JSP file, spotSpaceStation.jsp, which consumes the RSS feed from the NASA.gov API service. The feed returns a list of sightings of the International Space Station and other satellites in a selected city and country in a feed format. Each sighting is returned in an <item></item> tag:

<item>
	<title>2014-06-07 ISS Sighting</title>
	<pubDate>07 Jun 2014 07:36:35 GMT</pubDate>
	<description>
	Date: Saturday Jun 7, 2014
	Time: 8:50 PM
	Duration: 1 minute
	Maximum Elevation: 14
	Approach: 14  above NNW
	Departure: 10 above N
	</description>
	<guid>http://spotthestation.nasa.gov/sightings/view.cfm?country=United_States
	&amp;region=Texas&amp;city=Houston&amp;ss=9493A663-E74D-9B2B-2595498DE38B423B</guid>
</item>

The feed URL is in this format:

http://spotthestation.nasa.gov/sightings/indexrss.cfm?country=<country>&region= <region>&city=<city>

The city/state and country from request parameters is appended to the URL at runtime. The location (Houston, Texas) is the default:

String state = request.getParameter("state");
   if (state != null || state == "") {	
	String makeStr = "http://spotthestation.nasa.gov/sightings/indexrss.cfm?country="
		+ request.getParameter("country")
		+ "&region=None&city="
		+ request.getParameter("state");
			rssURL = new URL(makeStr);
    } else {
	    rssURL = new URL(
		"http://spotthestation.nasa.gov/sightings/indexrss.cfm?country=United_States
		&region=Texas&city=Houston");
    }

The BufferedReader reads the InputStream contents of the RSS XML feed and parses each line for sightings data such as date, time, and duration. It then displays these in a tabular format:

BufferedReader in = new BufferedReader(new InputStreamReader(
					rssURL.openStream()));
….....
while ((line = in.readLine()) != null) {
				
				 if (line.contains("Date:")) {
					int thirdpos = line.indexOf("Date:");

Consuming the Open-Notify API

 

The Open-Notify API returns the number of people in space and their names in JSON format. The response is shown here:

{
  "number": 6,
  "people": [
    {
      "name": "Alexander Skvortsov",
      "craft": "ISS"
    },
    {
      "name": "Oleg Artemyev",
      "craft": "ISS"
    },
    {
      "name": "Steve Swanson",
      "craft": "ISS"
    },
    {
      "name": "Maxim Suraev",
      "craft": "ISS"
    },
    {
      "name": "Reid Wiseman",
      "craft": "ISS"
    },
    {
      "name": "Alexander Gerst",
      "craft": "ISS"
    }
  ],
  "message": "success"
}

The application uses the JQuery getJSON method to load JSON response data from Open-Notify URL. The number of people in space and their names are inserted into the specific elements and displayed:

$.getJSON("http://api.open-notify.org/astros.json?callback=?",
	function(data) {
		$("#numSpace").append(data['number']);
		var names = "";
		for ( var i = 0; i < data.people.length; i++) {
			names += data.people[i].name + ", ";
			}
		$("#listSpace").append(names);
	});

Here's an overview of the SPOT ISS application:

Diagram of the SPOT ISS application's dependencies

Conclusion

 

You've now seen how to create a Bluemix application that integrates with external API services to create a unique system of engagement. The JazzHub web IDE and DevOps Services help you to easily manage and automatically deploy code to a Bluemix server. You can further enhance the application to send push notifications to mobile devices when the International Space Station is closer to a specific city location.


RELATED TOPICS:System of engagementLiberty profileOpen Notify API

Add a comment

Note: HTML elements are not supported within comments.


1000 characters left

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing, Web development
ArticleID=980276
ArticleTitle=Spot the International Space Station using third-party APIs and the Liberty runtime
publish-date=08112014