Skip to content

Instantly share code, notes, and snippets.

@bbq2100
Created October 2, 2014 14:38
Show Gist options
  • Save bbq2100/f7045f3a7e8294a95568 to your computer and use it in GitHub Desktop.
Save bbq2100/f7045f3a7e8294a95568 to your computer and use it in GitHub Desktop.
RESTful WS with oldfashioned HTTPServlet^^
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