Created
December 25, 2014 20:40
-
-
Save maxant/f97b5ff50085813d11c3 to your computer and use it in GitHub Desktop.
Servlet handling requests
This file contains 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
@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