2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Instance;
24 import jalview.httpserver.AbstractRequestHandler;
26 import java.io.IOException;
27 import java.io.PrintWriter;
28 import java.net.BindException;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
34 * A simple handler to process (or delegate) HTTP requests on /jalview/rest.
35 * Accessed only by HttpServer.
37 public class RestHandler extends AbstractRequestHandler
39 private static final String MY_PATH = "rest";
41 private static final String MY_NAME = "Rest";
44 * Returns the singleton instance of this class
47 * @throws BindException
49 public static RestHandler getInstance() throws BindException
51 synchronized (RestHandler.class)
53 Instance j = Instance.getInstance();
54 return (j.restHandler == null ? j.restHandler = new RestHandler()
60 * Private constructor enforces use of singleton
62 * @throws BindException
64 private RestHandler() throws BindException
69 * We don't register the handler here - this is done as a special case in
70 * HttpServer initialisation; to do it here would invite an infinite loop of
71 * RestHandler/HttpServer constructor
76 * Handle a jalview/rest request
81 protected void processRequest(HttpServletRequest request,
82 HttpServletResponse response) throws IOException
85 * Currently just echoes the request; add helper classes as required to
88 final String queryString = request.getQueryString();
89 final String reply = "REST not yet implemented; received "
90 + request.getMethod() + ": " + request.getRequestURL()
91 + (queryString == null ? "" : "?" + queryString);
92 System.out.println(reply);
94 response.setHeader("Cache-Control", "no-cache/no-store");
95 response.setHeader("Content-type", "text/plain");
96 final PrintWriter writer = response.getWriter();
102 * Returns a display name for this service
105 public String getName()