Created
October 2, 2014 14:38
-
-
Save bbq2100/f7045f3a7e8294a95568 to your computer and use it in GitHub Desktop.
RESTful WS with oldfashioned HTTPServlet^^
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class RestServlet extends HttpServlet { | |
public void addConfiguration(String key, String value) { | |
response.put(key, value); | |
} | |
private Map<String, String> response = new HashMap<String, String>(); | |
public RestServlet() { | |
response.put("/autos", Arrays.asList("BMW", "Mercedes").toString()); | |
response.put("/autos/1", Arrays.asList("YEAH").toString()); | |
} | |
@Override | |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) | |
throws ServletException, IOException { | |
String requestKey = req.getRequestURI(); | |
String responseMessage = response.get(requestKey); | |
resp.getWriter().println(String.format("Autos: %s", responseMessage)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment