System.out.println("Request received...");
if (msg instanceof HttpRequest) {
HttpRequest req = (HttpRequest) msg;
QueryStringDecoder decoder = new QueryStringDecoder(req.getUri());
if (HttpHeaders.is100ContinueExpected(req)) {
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
}
boolean keepAlive = HttpHeaders.isKeepAlive(req);
String path = decoder.path();
if (path.equals("/hello")) {
responseAsByte = new HttpHelloWorldServerHandler().run();
} else if (path.contains("/article/")) {
responseAsByte = new HttpArticleRequestHandler().run(path.substring(path.lastIndexOf("/")+1));
contentType = "application/json";
} else if (path.equals("/articles/fetch")) {
System.out.println("in /articles/fetch");
int articleLimit = 10;
if (decoder.parameters().containsKey("q")) {
articleLimit = Integer.parseInt(decoder.parameters().get("q").get(0));
}
try {
responseAsByte = new HttpArticleFetchRequestHandler().run(articleLimit);
} catch (Exception e) {}
} else if (path.equals("/articles/list")) {
System.out.println("in /articles/list");
int articleLimit = 10;
if (decoder.parameters().containsKey("q")) {
articleLimit = Integer.parseInt(decoder.parameters().get("q").get(0));
}
if (decoder.parameters().containsKey("oio")) {
try {
responseAsByte = new OIOHttpArticleListRequestHandler().run(articleLimit);
} catch (Exception e) {}
} else {
try {
responseAsByte = new HttpArticleListRequestHandler().run(articleLimit);
} catch (Exception e) {}
}
contentType = "application/json";
} else if (decoder.path().equals("/marshaller")) {
responseAsByte = new HttpJsonMarshallHandler(jsonContent).run();
if (responseAsByte != null) {
ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, OK)).addListener(ChannelFutureListener.CLOSE);
}
else {