- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 06 Aug 2009 11:30:38 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3/unicorn
In directory hutz:/tmp/cvs-serv29132/src/org/w3/unicorn
Modified Files:
Tag: dev2
Init.java Controller.java
Log Message:
an error is now displayed if unicorn is not initialized
Index: Controller.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3/unicorn/Attic/Controller.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- Controller.java 6 Aug 2009 10:13:28 -0000 1.1.2.2
+++ Controller.java 6 Aug 2009 11:30:35 -0000 1.1.2.3
@@ -14,28 +14,34 @@
private static final long serialVersionUID = 1L;
private static Logger logger;
+ private static boolean isInitialized = false;
@Override
public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- processRequest(request, response);
+ if (isInitialized)
+ processRequest(request, response);
+ else
+ response.sendError(500, "Unicorn is not initialized properly. Check logs.");
}
@Override
public final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- processRequest(request, response);
+ doGet(request, response);
}
@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- processRequest(request, response);
+ doGet(request, response);
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
logger.info("Processing request: " + request.getRequestURL());
Route route = RouteParser.getRoute(request);
- if (route.isSetUrl())
+ if (route.isSetUrl()) {
response.sendRedirect(route.getUrl());
+ logger.info("Request redirected to: " + route.getUrl());
+ }
else if (route.isSetAction()) {
RequestDispatcher dispatcher = getServletContext().getNamedDispatcher(route.getAction());
if (dispatcher == null) {
@@ -45,6 +51,7 @@
} else {
try {
dispatcher.forward(request, response);
+ logger.info("Request dispatched to: " + route.getAction());
} catch (Exception e) {
logger.error("ERROR: " + e.getMessage(), e);
response.sendError(501, "ERROR: " + e.getMessage());
@@ -61,8 +68,14 @@
try {
Init.init();
logger = Logger.getLogger("Controller");
+ isInitialized = true;
+ logger.info("Unicorn initialized properly");
} catch (Exception e) {
- // TODO Auto-generated catch block
+ try {
+ logger.error("Unicorn was not initialized properly. No request will be processed!");
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
e.printStackTrace();
}
}
Index: Init.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3/unicorn/Attic/Init.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -d -r1.1.2.2 -r1.1.2.3
--- Init.java 6 Aug 2009 10:13:28 -0000 1.1.2.2
+++ Init.java 6 Aug 2009 11:30:35 -0000 1.1.2.3
@@ -2,9 +2,13 @@
import java.io.File;
import java.net.URI;
+import java.util.List;
+
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
+import org.w3.unicorn.route.Route;
import org.w3.unicorn.route.RouteParser;
+import org.w3.unicorn.route.RoutesDocument;
import org.w3.unicorn.util.Property;
import org.w3.unicorn.util.UCNProperties;
@@ -67,10 +71,50 @@
logger.debug("Loaded properties: " + Property.getUnicornProperties());
}
- // Initialising RouteParser
- RouteParser.init();
-
+ // Checking Unicorn properties
+ String[] mandatoryProperties = {"PATH_TO_CONF_FILES","ROUTE_XML","PATH_TO_CACHE"};
+ for (String property: mandatoryProperties) {
+ if (Property.get(property) == null) {
+ String error = "\""+ property +"\" is not defined in unicorn.properties. This property is mandatory.";
+ logger.error(error);
+ throw new Exception(error);
+ }
+ }
+ // Initialising RouteParser
+ logger.debug("Initialising RouteParser");
+ File routesFile = new File(Property.get("PATH_TO_CONF_FILES", "ROUTE_XML"));
+ if (!routesFile.exists()) {
+ String error = "Route xml file could not be found: " + routesFile;
+ logger.error(error);
+ throw new Exception(error);
+ }
+ RoutesDocument routesXML = RoutesDocument.Factory.parse(routesFile);
+ List<Route> tempRouteList = routesXML.getRoutes().getRouteList();
+ for(Route route : tempRouteList) {
+ logger.debug("Route found: " + route.xmlText());
+ if (route.isSetType() && route.getType().equals("index")) {
+ logger.debug("> This route is the Index route");
+ RouteParser.setIndex(route);
+ RouteParser.getRouteList().add(route);
+ } else if (route.isSetType() && route.getType().equals("404")) {
+ logger.debug("> This route is the 404 route");
+ RouteParser.setError404(route);
+ } else {
+ RouteParser.getRouteList().add(route);
+ }
+ }
+ if (RouteParser.getIndex() == null) {
+ String error = "There is non Index route. RouteParser is not initialized properly.";
+ logger.error(error);
+ throw new Exception(error);
+ } else if (RouteParser.getError404() == null) {
+ String error = "There is non 404 route. RouteParser is not initialized properly.";
+ logger.error(error);
+ throw new Exception(error);
+ } else {
+ logger.info("Unicorn routes successfully loaded");
+ }
}
Received on Thursday, 6 August 2009 11:30:46 UTC