source: src/main/java/geniusweb/runserver/RunNego.java@ 10

Last change on this file since 10 was 10, checked in by bart, 5 years ago

Added ANAC2019 Example parties: Agentgg and WinkyAgent

File size: 2.3 KB
RevLine 
[1]1package geniusweb.runserver;
2
3import java.io.IOException;
4import java.util.logging.Level;
5import java.util.stream.Collectors;
6
7import javax.servlet.ServletException;
8import javax.servlet.http.HttpServlet;
9import javax.servlet.http.HttpServletRequest;
10import javax.servlet.http.HttpServletResponse;
11
12import com.fasterxml.jackson.databind.ObjectMapper;
13
14import geniusweb.protocol.NegoSettings;
15import tudelft.utilities.logging.ReportToLogger;
16import tudelft.utilities.logging.Reporter;
17
18/**
19 * Contains incoming connection to run a Nego. runserver/runsession with the
20 * JSON {@link NegoSettings} in the request header. After the session is
21 * started, the new Nego ID is returned. This can be used to find back the log
22 * files..
23 */
24@SuppressWarnings("serial")
25public class RunNego extends HttpServlet {
26 private final Reporter log;
27 private final static ObjectMapper jackson = new ObjectMapper();
28
29 public RunNego() {
30 this(new ReportToLogger("runserver"));
31 }
32
33 public RunNego(Reporter logger) {
34 super();
35 this.log = logger;
36 }
37
38 /**
39 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
[10]40 * response).
41 *
42 * @return the ID of the new started run. Or SC_BAD_REQUEST if the request
43 * can not be processed.
[1]44 */
45 @Override
46 protected void doGet(HttpServletRequest request,
47 HttpServletResponse response) throws ServletException, IOException {
48 String reqstring = request.getReader().lines()
49 .collect(Collectors.joining());
50 NegoSettings settings;
51 try {
52 settings = jackson.readValue(reqstring, NegoSettings.class);
53 } catch (IOException e) {
54 response.sendError(HttpServletResponse.SC_BAD_REQUEST,
55 e.getMessage());
[8]56 System.err.println("Run request failed " + reqstring);
57 e.printStackTrace(); // helpful for debugging run requests
[1]58 return;
59 }
60 log.log(Level.INFO, "request to run Nego: " + settings);
[10]61 RunningNego running = new RunningNego(settings,
[1]62 RunningNegotiationsRepo.instance(), log);
[10]63 running.start();
[4]64 // set content type to prevent some browsers
65 // trying to parse this (eg as XML)
66 response.setContentType("application/json");
[10]67 response.getWriter().append(running.getID());
[1]68 }
69
70 /**
71 * @see #doGet(HttpServletRequest, HttpServletResponse)
72 */
73 @Override
74 protected void doPost(HttpServletRequest request,
75 HttpServletResponse response) throws ServletException, IOException {
76 doGet(request, response);
77 }
78
79}
Note: See TracBrowser for help on using the repository browser.