3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.net.BindException;
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
10 import jalview.httpserver.AbstractRequestHandler;
13 * A simple handler to process (or delegate) HTTP requests on /jalview/rest
15 public class RestHandler extends AbstractRequestHandler
17 private static final String MY_PATH = "rest";
19 private static final String MY_NAME = "Rest";
22 * Singleton instance of this class
24 private static RestHandler instance = null;
27 * Returns the singleton instance of this class
30 * @throws BindException
32 public static RestHandler getInstance() throws BindException
34 synchronized (RestHandler.class)
38 instance = new RestHandler();
45 * Private constructor enforces use of singleton
47 * @throws BindException
49 private RestHandler() throws BindException
54 * We don't register the handler here - this is done as a special case in
55 * HttpServer initialisation; to do it here would invite an infinite loop of
56 * RestHandler/HttpServer constructor
61 * Handle a jalview/rest request
66 protected void processRequest(HttpServletRequest request,
67 HttpServletResponse response) throws IOException
70 * Currently just echoes the request; add helper classes as required to
73 final String queryString = request.getQueryString();
74 final String reply = "REST not yet implemented; received "
75 + request.getMethod() + ": " + request.getRequestURL()
76 + (queryString == null ? "" : "?" + queryString);
77 System.out.println(reply);
79 response.setHeader("Cache-Control", "no-cache/no-store");
80 response.setHeader("Content-type", "text/plain");
81 final PrintWriter writer = response.getWriter();
87 * Returns a display name for this service
90 public String getName()