Author: vgritsenko
Date: Wed Jun 27 21:39:52 2007
New Revision: 551444
URL: http://svn.apache.org/viewvc?view=rev&rev=551444
Log:
<action dev="VG" type="remove">
Remove 'Ugly Browser', replaced by WebAdmin.
</action>
Removed:
xml/xindice/trunk/java/src/org/apache/xindice/server/UglyBrowser.java
xml/xindice/trunk/java/src/org/apache/xindice/webadmin/WebAdminServlet.java
Modified:
xml/xindice/trunk/config/web.xml
xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java
xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Get.java
xml/xindice/trunk/status.xml
Modified: xml/xindice/trunk/config/web.xml
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/config/web.xml?view=diff&rev=551444&r1=551443&r2=551444
==============================================================================
--- xml/xindice/trunk/config/web.xml (original)
+++ xml/xindice/trunk/config/web.xml Wed Jun 27 21:39:52 2007
@@ -49,12 +49,6 @@
<param-value>WEB-INF/config/system.xml</param-value>
</init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
-
- <servlet>
- <servlet-name>webadmin</servlet-name>
- <servlet-class>org.apache.xindice.webadmin.WebAdminServlet</servlet-class>
<init-param>
<param-name>webadmin.configuration</param-name>
<param-value>WEB-INF/config/webadmin.xml</param-value>
@@ -63,13 +57,9 @@
<param-name>mimetable.configuration</param-name>
<param-value>WEB-INF/config/MimeTypes.xml</param-value>
</init-param>
+
<load-on-startup>1</load-on-startup>
</servlet>
-
- <servlet-mapping>
- <servlet-name>webadmin</servlet-name>
- <url-pattern>/dav/*</url-pattern>
- </servlet-mapping>
<servlet-mapping>
<servlet-name>xindice</servlet-name>
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java?view=diff&rev=551444&r1=551443&r2=551444
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java
Wed Jun 27 21:39:52 2007
@@ -21,10 +21,22 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.DBException;
import org.apache.xindice.core.Database;
import org.apache.xindice.server.rpc.RPCMessageInterface;
import org.apache.xindice.util.Configuration;
import org.apache.xindice.util.ConfigurationException;
+import org.apache.xindice.webadmin.Location;
+import org.apache.xindice.webadmin.WebAdminManager;
+import org.apache.xindice.webadmin.viewer.HtmlDatabaseViewer;
+import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer;
+import org.apache.xindice.webadmin.viewer.HtmlResourceViewer;
+import org.apache.xindice.webadmin.util.MimeTable;
+import org.apache.xindice.webadmin.webdav.DAVRequest;
+import org.apache.xindice.webadmin.webdav.DAVResponse;
+import org.apache.xindice.webadmin.webdav.WebdavStatus;
+import org.apache.xindice.webadmin.webdav.components.DAVComponent;
import org.apache.xindice.xml.dom.DOMParser;
import org.apache.xmlrpc.XmlRpc;
import org.apache.xmlrpc.XmlRpcServer;
@@ -59,48 +71,18 @@
private static final Log log = LogFactory.getLog(XindiceServlet.class);
private static final String DEFAULT_XMLRPC_DRIVER = "xerces";
- protected XmlRpcServer xmlrpcServer;
+ private static final String WEBADMIN_CONFIGURATION =
"webadmin.configuration";
+ private static final String MIMETABLE_CONFIGURATION =
"mimetable.configuration";
- public void destroy() {
- // When the servlet engine goes down we need to close the database
instance.
- // By the time destroy() is called, no more client requests can come
in,
- // so no need to worry about multithreading.
- String[] databases = Database.listDatabases();
- for (int i = 0; i < databases.length; i++) {
- String name = databases[i];
- try {
- Database.getDatabase(name).close();
- log.info("Database '" + name + "' successfully closed");
- } catch (Exception e) {
- log.error("Error closing database '" + name + "'", e);
- }
- }
- }
+ protected XmlRpcServer xmlrpcServer;
+ protected WebAdminManager webAdmin;
- /**
- * Delegate GET requests to the UglyBrowser.
- */
- public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
- UglyBrowser.doGet(request, response);
- }
-
- /**
- * Sends an XML query to the server and writes the output back. Currenlty
- * only XML-RPC query is supported.
- */
- public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
- byte[] result = xmlrpcServer.execute(request.getInputStream());
- response.setContentType("text/xml");
- response.setContentLength(result.length);
- OutputStream output = response.getOutputStream();
- output.write(result);
- output.flush();
- }
/**
* Initializes database
*/
public void init(ServletConfig servletConfig) throws ServletException {
+ super.init(servletConfig);
Configuration configuration = loadConfiguration(servletConfig);
@@ -212,6 +194,22 @@
destroy();
throw new ServletException("Error while handling the
configuration", e);
}
+
+ try {
+ String path =
servletConfig.getInitParameter(WEBADMIN_CONFIGURATION);
+ Document doc = loadFile(path, servletConfig);
+ webAdmin = new WebAdminManager(doc.getDocumentElement());
+ } catch(Exception e) {
+ throw new ServletException("Could not process WebAdmin
configuration", e);
+ }
+
+ try {
+ String path =
servletConfig.getInitParameter(MIMETABLE_CONFIGURATION);
+ Document doc = loadFile(path, servletConfig);
+ MimeTable.addMimeConfig(doc);
+ } catch(Exception e) {
+ log.error("Could not process Mime Table configuration", e);
+ }
}
/**
@@ -267,4 +265,155 @@
throw new ConfigurationException("Failed to load configuration.",
e);
}
}
+
+ private Document loadFile(String path, ServletConfig config) throws
Exception {
+ InputStream inputStream = null;
+
+ try {
+ if (path.startsWith("/")) { // Absolute file path
+ log.debug("Loading configuration from filesystem path " +
path);
+ inputStream = new FileInputStream(path);
+ } else {
+ // Relative (to the context) path
+ log.debug("Loading configuration from context path " + path);
+ ServletContext context = config.getServletContext();
+ inputStream = context.getResourceAsStream("/" + path);
+ }
+
+ Document configuration = null;
+ if (inputStream != null) {
+ configuration = DOMParser.toDocument(inputStream);
+ }
+
+ return configuration;
+ } finally {
+ try {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ } catch (IOException ignored) {
+ // ignore
+ }
+ }
+ }
+
+ public void destroy() {
+ // When the servlet engine goes down we need to close the database
instance.
+ // By the time destroy() is called, no more client requests can come
in,
+ // so no need to worry about multithreading.
+ String[] databases = Database.listDatabases();
+ for (int i = 0; i < databases.length; i++) {
+ String name = databases[i];
+ try {
+ Database.getDatabase(name).close();
+ log.info("Database '" + name + "' successfully closed");
+ } catch (Exception e) {
+ log.error("Error closing database '" + name + "'", e);
+ }
+ }
+ }
+
+ /**
+ * Process request. Determine type of a request and delegate for processing
+ * either to XML-RPC server, WebDAV, or WebAdmin.
+ *
+ * @param request a HttpServletRequest instance
+ * @param response a HttpServletResponse instance
+ * @exception IOException if an IO error occurs
+ * @exception ServletException if a servlet error occurs
+ */
+ public void service(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
+ // get requested information
+ String path = request.getServletPath();
+ String method = request.getMethod();
+
+ // xmlrpc requests do not have path (always '/') and are always POST
+ if ("/".equals(path) && method.equalsIgnoreCase("POST")) {
+ byte[] result = xmlrpcServer.execute(request.getInputStream());
+ response.setContentType("text/xml");
+ response.setContentLength(result.length);
+ OutputStream output = response.getOutputStream();
+ output.write(result);
+ return;
+ }
+
+ // empty path - redirect to initial page
+ if (path.length() == 0) {
+ String redirect = request.getContextPath() +
request.getServletPath() + "/?viewer=default";
+ response.sendRedirect(redirect);
+ return;
+ }
+
+ // get request target
+ Location target;
+ try {
+ target = new Location(path);
+ } catch (DBException e) {
+ log.error("Unable to process request '" + path + "'", e);
+ throw new ServletException(e);
+ }
+
+ // get viewer parameter (missing if DAV request)
+ String viewer = request.getParameter("viewer");
+
+ // WebDAV requests do not have viewer parameter, nor can not GET a
collection
+ if (viewer == null && !(path.endsWith("/") &&
method.equalsIgnoreCase("GET"))) {
+ DAVComponent m = webAdmin.getMethod(method);
+ if (m == null) {
+ // method is not supported
+ if (log.isInfoEnabled()) {
+ log.info("Method " + method + " is not supported.");
+ }
+ response.setStatus(WebdavStatus.SC_NOT_IMPLEMENTED);
+ return;
+ }
+
+ m.execute(new DAVRequest(request), new DAVResponse(response),
target);
+ return;
+ }
+
+ // HTML requests are all the rest
+ Collection col = target.getCollection();
+ String resource = target.getName();
+ if (col == null) {
+ // redirect if path is not '/'
+ if (!path.equals("/")) {
+ String redirect = request.getContextPath() +
request.getServletPath() + "/?viewer=" + viewer;
+ response.sendRedirect(redirect);
+ return;
+ }
+
+ HtmlDatabaseViewer v = webAdmin.getDatabaseViewer(viewer);
+ if (v == null) {
+ response.setStatus(WebdavStatus.SC_NOT_IMPLEMENTED);
+ return;
+ }
+
+ v.execute(request, response);
+ } else if (resource == null) {
+ // redirect if path does not end with '/'
+ if (!path.endsWith("/")) {
+ String redirect = request.getContextPath() +
request.getServletPath() + path + "/?viewer=" + viewer;
+ response.sendRedirect(redirect);
+ return;
+ }
+
+ HtmlCollectionViewer v = webAdmin.getCollectionViewer(viewer);
+ if (v == null) {
+ response.setStatus(WebdavStatus.SC_NOT_IMPLEMENTED);
+ return;
+ }
+
+ v.execute(request, response, col);
+ } else {
+ HtmlResourceViewer v = webAdmin.getResourceViewer(viewer);
+ if (v == null) {
+ response.setStatus(WebdavStatus.SC_NOT_IMPLEMENTED);
+ return;
+ }
+
+ v.execute(request, response, col, resource);
+ }
+ }
+
}
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Get.java
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Get.java?view=diff&rev=551444&r1=551443&r2=551444
==============================================================================
---
xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Get.java
(original)
+++
xml/xindice/trunk/java/src/org/apache/xindice/webadmin/webdav/components/Get.java
Wed Jun 27 21:39:52 2007
@@ -51,27 +51,7 @@
public void execute(DAVRequest req, DAVResponse res, Location target)
throws ServletException, IOException {
if (target.getName() == null) {
- // test if viewer is already specified
- String viewer = req.getParameter("viewer");
- if (viewer != null && viewer.length() != 0) {
- res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
- }
-
- if (log.isDebugEnabled()) {
- log.debug("WEBDAV Get redirected to HtmlViewer");
- }
-
- // redirect if path does not end with /
- String reqPath = req.getPath();
- if (reqPath == null || !reqPath.endsWith("/")) {
- if (reqPath == null) {
- reqPath = "";
- }
- String redirect = req.getContextPath() + reqPath +
"/?viewer=default";
- res.sendRedirect(redirect);
- } else {
- res.sendRedirect("?viewer=default");
- }
+ res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
} else {
Collection col = target.getCollection();
Modified: xml/xindice/trunk/status.xml
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/status.xml?view=diff&rev=551444&r1=551443&r2=551444
==============================================================================
--- xml/xindice/trunk/status.xml (original)
+++ xml/xindice/trunk/status.xml Wed Jun 27 21:39:52 2007
@@ -113,6 +113,9 @@
<changes>
<release version="1.2" date="unreleased">
+ <action dev="VG" type="remove">
+ Remove 'Ugly Browser', replaced by WebAdmin.
+ </action>
<action dev="VG" type="update" fixes-bug="42684" due-to="Natalia
Shilenkova">
Use Java NIO to lock database on startup.
</action>