Skip to content

Instantly share code, notes, and snippets.

@maxant
Created December 25, 2014 20:40
Show Gist options
  • Save maxant/f97b5ff50085813d11c3 to your computer and use it in GitHub Desktop.
Save maxant/f97b5ff50085813d11c3 to your computer and use it in GitHub Desktop.
Servlet handling requests
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String path = req.getServletPath();
LOGGER.debug("received command: '" + path + "'");
String who = req.getParameter("userId");
String productId = req.getParameter("productId");
TradingEngineThread engine = kids.get(productId);
int quantity = Integer.parseInt(req.getParameter("quantity"));
int id = ID.getAndIncrement();
// e.g. /buy?productId=1&quantity=10&userId=ant
if (path.equals("/buy")) {
PurchaseOrder po = engine.addPurchaseOrder(who, productId, quantity, id);
resp.getWriter().write("\"id\":" + id + ", " + String.valueOf(po));
} else if (path.equals("/sell")) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment