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

Write an http service which accepts a graph of people where edges

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 gracefully

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!