removed useless import
[pnews.git] / war / src / main / java / pnews / servlet / Pnews.java
index 845abbb..dcb86ef 100644 (file)
@@ -54,6 +54,7 @@ public class Pnews extends HttpServlet {
 
         private static void redirect(HttpServletRequest rq, HttpServletResponse rp) {
                 String redirectURL;
+                Article a;
 
                 LOG.entering(Pnews.class.getName(), "redirect");
 
@@ -63,6 +64,12 @@ public class Pnews extends HttpServlet {
                         LOG.info("Request redirection to " + redirectURL);
 
                         if (redirectURL != null) {
+                                a = ArticleStore.singleton.get(redirectURL);
+                                if (a != null)
+                                        a.readCount.incrementAndGet();
+                                else
+                                        LOG.severe("Cannot find the article " + redirectURL);
+                                
                                 rp.setHeader("Location", redirectURL);
                                 rp.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
                         } else {
@@ -79,6 +86,14 @@ public class Pnews extends HttpServlet {
                 LOG.exiting(Pnews.class.getName(), "redirect");
         }
 
+        private void writeStats(HttpServletResponse rp) throws IOException {
+                rp.setContentType("text/html;charset=utf-8");
+                rp.setCharacterEncoding("utf8-8");
+
+                rp.getWriter().write("" + ArticleStore.singleton);
+        }
+
+        
         private void writeArticles(Category cat, HttpServletResponse rp) {
                 String html;
                 List<Article> articles;
@@ -87,8 +102,9 @@ public class Pnews extends HttpServlet {
                         articles = provider.getArticles(cat);
                         if (articles != null) {
                                 html = HTML.toHTML(articles, cat);
-                                rp.setContentType("text/html");
+                                rp.setContentType("text/html;charset=utf-8");
                                 rp.getWriter().write(html);
+                                rp.setCharacterEncoding("utf8-8");
                         } else {
                                 LOG.severe("writeArticles cannot retrieve any articles");
                                 html = HTML.toHTML(new ArrayList<Article>(), cat);
@@ -117,8 +133,10 @@ public class Pnews extends HttpServlet {
                 String path;
                 InputStream in;
 
-                LOG.info("doGet " + req.getRequestURI());
-
+                RequesterLog.singleton.writeRequest(req);
+              
+                LOG.info("doGet " + req.getRemoteAddr().toString() + " " + req.getRequestURI() + " " + req.getQueryString());
+                                
                 path = req.getPathInfo();
 
                 if (path.equals("/redirect")) {
@@ -146,14 +164,20 @@ public class Pnews extends HttpServlet {
                         return ;
                 }
 
-                for (Category cat: Category.values()) {
-                        if (path.equals('/' + cat.getId())) {
-                                writeArticles(cat, resp);
+                try {
+                
+                        if (path.equals("/stats")) {
+                                writeStats(resp);
                                 return ;
                         }
-                }
-
-                try {
+                
+                        for (Category cat: Category.values()) {
+                                if (path.equals('/' + cat.getId())) {
+                                        writeArticles(cat, resp);
+                                        return ;
+                                }
+                        }
+                
                         resp.getWriter().write("Not found " + req.getPathInfo());
                         resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
                 } catch (IOException e) {