package se252.jan15.calvinandhobbes.project0;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* tripInfo web service exposed at "trip" path relative to base URI
*
* @author Arnab sen
* @version 1.0
* @see <a href="http://www.serc.iisc.ernet.in/~simmhan/SE252/">IISc SERC 'SE252:Intro to Cloud Computing' Course Webpage</a>
*
* (c) Arnab sen, 2015
* This work is licensed under a Attribution 4.0 International (CC BY 4.0).
* http://creativecommons.org/licenses/by/4.0/
*/
public class mapService {
/**
* Method handling HTTP GET requests. The request expects a "msg" input parameter with value of type string.
* The returned object will be sent to the client as JSON media type.
*
* @return JSON form of EchoMessage will be returned as response.
* @throws IOException
*/
public static String mapStr = "";
public static String mapStr2 = "";
public static String mapStr3 = "";
@Path("map")
public static class Map{
@GET
@Produces(MediaType.TEXT_HTML)
public String tripinfo() throws IOException {
if(!mapStr.equals(""))
return mapStr;
else {
Scanner map = new Scanner(new File("map.html"));
mapStr = map.useDelimiter("\\Z").next();
map.close();
}
return mapStr;
}
}
@Path("mapEvent")
public static class Map2{
@GET
@Produces(MediaType.TEXT_HTML)
public String tripinfo() throws IOException {
if(!mapStr2.equals(""))
return mapStr2;
else {
Scanner map = new Scanner(new File("map2.html"));
mapStr2 = map.useDelimiter("\\Z").next();
map.close();
}
return mapStr2;
}
}
@Path("mapSDB")
public static class MapSDB{
@GET
@Produces(MediaType.TEXT_HTML)
public String tripinfo() throws IOException {
if(!mapStr3.equals(""))
return mapStr3;
else {
Scanner map = new Scanner(new File("mapSDB.html"));
mapStr3 = map.useDelimiter("\\Z").next();
map.close();
}
return mapStr3;
}
}
@Path("update")
public static class MapUpdate{
@GET
@Produces(MediaType.TEXT_HTML)
public String tripinfo() throws IOException {
String updateStr = "";
Scanner map = new Scanner(new File("update.html"));
updateStr = map.useDelimiter("\\Z").next();
map.close();
return updateStr;
}
}
@Path("clear")
public static class Clear{
@GET
@Produces(MediaType.TEXT_HTML)
public String tripinfo() throws IOException {
Scanner map = new Scanner(new File("map.html"));
String mapStr = map.useDelimiter("\\Z").next();
map.close();
return mapStr;
}
}
}