Skip to content

Lab Assignment 8: Cloud Rest App

Moulika Chadalavada edited this page Oct 21, 2016 · 5 revisions

Cloud Based REST Application

Class Id: 8
Student Id: 16234180
Student Name: Moulika Chadalavada


Objective

The main aim of this tutorial is to develop a application with atleast two REST Service using Tomcat Server. Testing of the application is done using JUNIT. This application is used to fetch latitude & longitude from Address and Address from Latitude & Longitude.

Softwares/Tools Used

Eclipse,Java,WebStorm,JSP,HTML,CSS,Bootstrap,Tomcat Server,Mongo DB

Implementation of REST Services

Implemented 2 Rest Services to fetch Address from Latitude&Longitude and Latitude&Longitude from Address.The GUI is created in Webstrom where the Address/Latitude & Longitude is given to fetch respective details. Initially the GUI screen is displayed as below.

Address to Latitude & Longitude

Screen to fetch latitude & longitude from address


If the address is entered in the text field and clicks on **Get Latitude Longitude**, then the REST service is invoked using below link and based on address Latitude and Longitude is fetched by invoking **AddressConverter** class.

$http.get("http://localhost:8091/RESTExample/restexample/AddressConverter/"+h);

In AddressConverter class using below link Google Maps API is invoked and the JSON is fetched, and using ObjectMapper the JSON file is read and latitude and longitude is fetched.

maps.googleapis.com/maps/api/geocode/json?address=University of Missouri Kansas City&sensor=true

Screen that shows how Google Maps API is invoked



Screen that shows the JSON file of Google API



Screen that shows how latitude and longitude is passed to JSON Object


$scope.cal={"address":data.address,"latitude":data.latitude,"location":data.location, "longitude":data.longitude};

Screen that displays latitude and longitude from address

Latitude & Longitude to Address

Screen to fetch address from latitude & longitude


If the latitude and longitude is entered in the text field and clicks on **Get Address**, then the REST service is invoked using below link and based on address Latitude and Longitude is fetched by invoking **LatLngConverter** class.

$http.get("http://localhost:8091/RESTExample/restexample/LatLngConverter/"+lat+"/"+lng);

In LatLngConverter class using below link Google Maps API is invoked and the JSON is fetched, and using ObjectMapper the JSON file is read and address is fetched.

maps.googleapis.com/maps/api/geocode/json?latlng=28.6353080,77.2249600&sensor=true

Screen that shows how Google Maps API invocation and JSON parsing



Screen that shows the JSON file of Google API



$scope.cal={"address":data.address,"latitude":data.latitude,"location":data.location, "longitude":data.longitude};

Screen that displays latitude and longitude from address

JUNIT Testing

JUnit is a unit testing framework for Java programming language. JUnit has been important in the development of test-driven development. For this application the below test cases are executed.

In CalculateTest.java the expected values are given and the logic class file is invoked from where for given address latitude and longitude is fetched. Using assertEquals() the given and extracted values are compared & results are displayed.

JUNIT failure scenario for Address to Lat & Long



JUNIT success scenario which gives Lat & Long for given Address



JUNIT success scenario which gives Address for Lat & Long

MONGO DB CRUD Operations

The below link contains the CRUD operations that are performed using Mongo DB

https://github.com/cmoulika009/ASE-Lab-Assignments/wiki/MONGO-CRUD-OPERATIONS

References

ASE Tutorial 8

http://stackoverflow.com

http://www.tutorialspoint.com/junit/

https://mlab.com

Clone this wiki locally