Due Fri 9/5, 11:59pm
The goal of the second lab is to familiarize you with implementing web services from scratch. You will implement a simple HTTP server, using basic Java sockets, that will accept one type of request containing a city name as a query parameter and will return a JSON document containing a list of restaurants in the city, their Yelp ratings, and recent tweets about the restaurant. You will need to use your Lab 1 code for this assignment, and do not be afraid to refactor!
Requirements
- You are expected to use Java for this assignment. Solutions implemented in other languages will only be accepted if you have received an exception, via email, from the professor.
- You may NOT use any frameworks or other HTTP libraries for this assignment. You will use raw sockets to accept network requests in your application. The only external libraries you may use are the ones allowed for Lab 1.
- As with Lab 1, you will assume a configuration file called keys.json located in the directory where the program is run. The object containing the city name/value pair will not be valid for this program; only the keys will be used.
- Your application must accept correctly formatted HTTP GET requests. You should make sure to use curl and/or a web browser to test your application to ensure you are HTTP compliant.
- Your server must be multithreaded. You will use up to 10 threads to process incoming requests concurrently.
- The following is the only valid request your application is required to handle. You may reply to any other request with a valid HTTP 400 Bad Request response.
GET /restaurantmashup?city=<city name>
- Your application will reply to a valid request with a valid HTTP 200 OK response. The body of the response will be a JSON document formatted as follows:
"city":"las vegas",
"restaurants":[
{
"name":"Mesa Grill",
"rating":"4.0",
"tweets":["Mesa Grill Menu http:\/\/t.co\/3WhFb8OsHU",
"Bobby Flay's Mesa Grill Restaurant at Caesars Palace Las Vegas - #travel, #USA http:\/\/t.co\/kc1xeToKIL"
]
},
{
"name":"Gordon Ramsay Steak",
"rating":"4.0",
"tweets":["@GordonRamsay at Gordon Ramsay Steak in Paris, Las Vegas! Looking forward to a delicious meal!",
"I'm at Gordon Ramsay Steak (Las Vegas, NV) http:\/\/t.co\/AzL5Fy2ds2"
]
},
{
"name":"Picasso",
"rating":"4.5",
"tweets":["Las Vegas' priciest listing comes with Picasso, Dali paintings:... http:\/\/t.co\/7gLxVPtWRn",
"Las Vegas' most expensive residence, owned by Phil Maloof, is more than double the price of the No. 2 listing. http:\/\/t.co\/PtGax9z5Rx",
"RT @MySportsLegion: LeBron and DWade had dinner and went clubbing in Las Vegas last night. (Y!)",
"I'm at Picasso - @bellagio (Las Vegas, NV) http:\/\/t.co\/Uh6heO3YHH http:\/\/t.co\/lhV3SZLyKj",
"$38 million Las Vegas #penthouse comes with Dali and Picasso paintings http:\/\/t.co\/4T1G50FLd0 via @MailOnline #lasvegas #vegas #tower"
]
}
]
- Your program will be run as follows. You will accept one command line parameter that specifies the port at which your server will listen.
- By the deadline, your server must be running on the microcloud node/port assigned to you here. I will use curl/a browser to test your running program.
- All java code must be submitted to your github repo <username>-lab2.
- Hints:
- Make sure to handle appropriate error cases. Your program should only reply with a 200 OK for a correctly formatted request.
- You will implement a more fully functioning HTTP server for Project 1, so keep that in mind as you design your server. Your server should be as modular as possible, and should decouple the functionality of handling a specific type of request.
- See the following resources:
- HTTP Request specification
- HTTP Response specification