Question
Write an http service which accepts a graph of people where edges represent friendship relationships private void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Write an http service which accepts a graph of people where edges represent friendship relationships
private void doService(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
// Get received JSON data from HTTP request
BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
String jsonStr = "";
if(br != null){
jsonStr = br.readLine();
}
// Create JsonReader object
StringReader strReader = new StringReader(jsonStr);
JsonReader reader = Json.createReader(strReader);
// Get the singular JSON object (name:value pair) in this message.
JsonObject obj = reader.readObject();
// From the object get the array named "inList"
JsonArray inArray = obj.getJsonArray("inList");
////////////////// WRITE CODE HERE
///////////////////////////
}
// Standard Servlet method
public void destroy()
{
// Do any required tear-down here, likely nothing.
}
}
Goal: Write an HTTP service which accepts a graph of people where edges represent friendship relationships. Return the suggested edges which would create direct friend relationships between two people who currently are at most one friend away - two people who are "friends of a friend (FOAFs) Problem Receive as input an array of friend relationships. Return a set of arrays each representing a new suggested friend relationship. .Example input: nList: t'friends" I"Albert", "Betty" ?friends" : [ "Betty", "Cathy" ] }, t'friends" I"Cathy", "Denis" ] tfriends" "Denis", "Albert"], tfriends" I"Tony", "Bruce" |) J1 Example output: outist":"Albert", "Cathy" .1 "Betty", "Denis"]1 .Do not duplicate the suggestions (in the example above, do not also suggest [ "Cathy", "Albertl If no new friend relationships can be suggested, return the empty array. t'outList" Erroneous input (e.g. malformed JSON) should be handled gracefully. Goal: Write an HTTP service which accepts a graph of people where edges represent friendship relationships. Return the suggested edges which would create direct friend relationships between two people who currently are at most one friend away - two people who are "friends of a friend (FOAFs) Problem Receive as input an array of friend relationships. Return a set of arrays each representing a new suggested friend relationship. .Example input: nList: t'friends" I"Albert", "Betty" ?friends" : [ "Betty", "Cathy" ] }, t'friends" I"Cathy", "Denis" ] tfriends" "Denis", "Albert"], tfriends" I"Tony", "Bruce" |) J1 Example output: outist":"Albert", "Cathy" .1 "Betty", "Denis"]1 .Do not duplicate the suggestions (in the example above, do not also suggest [ "Cathy", "Albertl If no new friend relationships can be suggested, return the empty array. t'outList" Erroneous input (e.g. malformed JSON) should be handled gracefullyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started