From: erik Date: Tue, 25 Apr 2006 19:22:22 +0000 (+0000) Subject: (no commit message) X-Git-Tag: BEFORE_MAVEN_MIGRATION~86 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=945d06753950da5bb62974c13cd5d24a3f390115;p=utils --- diff --git a/crawler/kissweb/WebRoot/WEB-INF/overview.jsp b/crawler/kissweb/WebRoot/WEB-INF/overview.jsp new file mode 100644 index 00000000..bca8cd3c --- /dev/null +++ b/crawler/kissweb/WebRoot/WEB-INF/overview.jsp @@ -0,0 +1,64 @@ + +<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + KiSS Crawler overview page + + + + + + + + + + + +

KiSS Crawler Overview

+ + + + + + + + + + + + + + + + + + +
+ Currently running: + + +
+ Last executed at: + + +
+ Last result: + + +
+ Last message: + + +
+ +
+ +
+
+ + diff --git a/crawler/kissweb/src/org/wamblee/crawler/kiss/scheduling/CrawlerScheduler.java b/crawler/kissweb/src/org/wamblee/crawler/kiss/scheduling/CrawlerScheduler.java new file mode 100644 index 00000000..e529da07 --- /dev/null +++ b/crawler/kissweb/src/org/wamblee/crawler/kiss/scheduling/CrawlerScheduler.java @@ -0,0 +1,32 @@ +/* + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wamblee.crawler.kiss.scheduling; + +/** + * + */ +public interface CrawlerScheduler { + + void initialize() throws Exception; + + boolean isCrawlerRunning() throws Exception; + + void scheduleNow() throws Exception; + + void shutdown() throws Exception; + +} diff --git a/crawler/kissweb/src/org/wamblee/crawler/kiss/servlet/CrawlerServlet.java b/crawler/kissweb/src/org/wamblee/crawler/kiss/servlet/CrawlerServlet.java new file mode 100644 index 00000000..479c60b7 --- /dev/null +++ b/crawler/kissweb/src/org/wamblee/crawler/kiss/servlet/CrawlerServlet.java @@ -0,0 +1,87 @@ +/* + * Copyright 2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wamblee.crawler.kiss.servlet; + +import java.io.IOException; +import java.util.Date; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.wamblee.crawler.kiss.scheduling.CrawlerSchedule; +import org.wamblee.crawler.kiss.scheduling.CrawlerScheduler; +import org.wamblee.general.BeanKernel; + +/** + * + */ +public class CrawlerServlet extends HttpServlet { + + /* + * (non-Javadoc) + * + * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + */ + @Override + protected void doPost(HttpServletRequest aRequest, + HttpServletResponse aResponse) throws ServletException, IOException { + + CrawlerScheduler scheduler = BeanKernel.getBeanFactory().find( + CrawlerScheduler.class); + CrawlerSchedule status = BeanKernel.getBeanFactory().find( + CrawlerSchedule.class); + + try { + if ( aRequest.getParameter("runnow") != null ) { + status.setLastExecuted(new Date(System.currentTimeMillis() - 24*3600*1000)); + scheduler.scheduleNow(); + aResponse.sendRedirect(""); + return; + } + aRequest.setAttribute("running", scheduler.isCrawlerRunning()); + aRequest.setAttribute("lastExecuted", status.getLastExecuted()); + aRequest.setAttribute("lastResult", status.getLastResult()); + aRequest.setAttribute("lastException", status.getLastException()); + String msg = ""; + Throwable e = status.getLastException(); + while ( e != null ) { + msg = msg + e.getMessage() + "
"; + e = e.getCause(); + } + aRequest.setAttribute("lastMessage", msg); + } catch (Exception e) { + throw new ServletException("Error getting status", e); + } + aRequest.getRequestDispatcher("WEB-INF/overview.jsp").forward(aRequest, + aResponse); + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + */ + @Override + protected void doGet(HttpServletRequest aRequest, + HttpServletResponse aResponse) throws ServletException, IOException { + doPost(aRequest, aResponse); + } +}