2 * Copyright 2006 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.wamblee.crawler.kiss.servlet;
19 import java.io.IOException;
20 import java.io.OutputStream;
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServlet;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
27 import org.wamblee.crawler.kiss.main.Report;
28 import org.wamblee.crawler.kiss.notification.Notifier;
29 import org.wamblee.crawler.kiss.scheduling.CrawlerScheduler;
30 import org.wamblee.crawler.kiss.scheduling.CrawlerStatus;
31 import org.wamblee.general.BeanKernel;
36 public class CrawlerServlet extends HttpServlet {
41 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
42 * javax.servlet.http.HttpServletResponse)
45 protected void doPost(HttpServletRequest aRequest,
46 HttpServletResponse aResponse) throws ServletException, IOException {
48 CrawlerScheduler scheduler = BeanKernel.getBeanFactory().find(
49 CrawlerScheduler.class);
50 CrawlerStatus status = BeanKernel.getBeanFactory().find(
54 if (aRequest.getParameter("details") != null) {
55 Report report = status.getLastReport();
57 Notifier notifier = BeanKernel.getBeanFactory().find(Notifier.class);
58 OutputStream os = aResponse.getOutputStream();
59 os.write(notifier.asHtml(report.asXml()).getBytes());
63 if (aRequest.getParameter("runnow") != null) {
64 status.setMustExecute(true);
65 scheduler.scheduleNow();
66 aResponse.sendRedirect("");
69 aRequest.setAttribute("running", scheduler.isCrawlerRunning());
70 aRequest.setAttribute("lastExecuted", status.getLastExecuted());
71 aRequest.setAttribute("lastResult", status.getLastResult());
72 aRequest.setAttribute("lastException", status.getLastException());
73 aRequest.setAttribute("lastReport", status.getLastReport());
75 Throwable e = status.getLastException();
77 msg = msg + e.getClass().getName() + ": " + e.getMessage()
81 aRequest.setAttribute("lastMessage", msg);
82 } catch (Exception e) {
83 throw new ServletException("Error getting status", e);
85 aRequest.getRequestDispatcher("WEB-INF/overview.jsp").forward(aRequest,
92 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
93 * javax.servlet.http.HttpServletResponse)
96 protected void doGet(HttpServletRequest aRequest,
97 HttpServletResponse aResponse) throws ServletException, IOException {
98 doPost(aRequest, aResponse);