Author: natalia Date: Wed Mar 12 18:20:52 2008 New Revision: 636596 URL: http://svn.apache.org/viewvc?rev=636596&view=rev Log: Changes for compatibility with different web containers. Logic for determining the type of request (XML-RPC, Web DAV, WevAdmin) refined
Modified: xml/xindice/trunk/config/web.xml xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java Modified: xml/xindice/trunk/config/web.xml URL: http://svn.apache.org/viewvc/xml/xindice/trunk/config/web.xml?rev=636596&r1=636595&r2=636596&view=diff ============================================================================== --- xml/xindice/trunk/config/web.xml (original) +++ xml/xindice/trunk/config/web.xml Wed Mar 12 18:20:52 2008 @@ -63,7 +63,7 @@ <servlet-mapping> <servlet-name>xindice</servlet-name> - <url-pattern>/</url-pattern> + <url-pattern>/*</url-pattern> </servlet-mapping> <!-- 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?rev=636596&r1=636595&r2=636596&view=diff ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/server/XindiceServlet.java Wed Mar 12 18:20:52 2008 @@ -312,8 +312,10 @@ * @exception ServletException if a servlet error occurs */ public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + request.setCharacterEncoding("utf-8"); + // get requested information - String path = request.getServletPath(); + String path = getPath(request); String method = request.getMethod(); // xmlrpc requests do not have path (always '/') and are always POST @@ -326,9 +328,13 @@ return; } + // get viewer parameter (missing if DAV request) + String viewer = request.getParameter("viewer"); + String requestURI = request.getRequestURI(); + // empty path - redirect to initial page - if (path.length() == 0) { - String redirect = request.getContextPath() + request.getServletPath() + "/?viewer=default"; + if (path.length() == 0 && viewer == null && method.equalsIgnoreCase("GET")) { + String redirect = requestURI + "/?viewer=default"; response.sendRedirect(redirect); return; } @@ -342,18 +348,15 @@ 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"))) { + if (viewer == null && !(target.getName() == null && 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); + response.sendError(WebdavStatus.SC_NOT_IMPLEMENTED); return; } @@ -364,45 +367,70 @@ // HTML requests are all the rest Collection col = target.getCollection(); String resource = target.getName(); - if (col == null) { + if (viewer == null) { + viewer = "default"; + } + + if (target.isRoot()) { // redirect if path is not '/' - if (!path.equals("/")) { - String redirect = request.getContextPath() + request.getServletPath() + "/?viewer=" + viewer; + if (!path.endsWith("/")) { + String redirect = requestURI + "/?viewer=" + viewer; response.sendRedirect(redirect); return; } HtmlDatabaseViewer v = webAdmin.getDatabaseViewer(viewer); if (v == null) { - response.setStatus(WebdavStatus.SC_NOT_IMPLEMENTED); + response.sendError(WebdavStatus.SC_NOT_IMPLEMENTED); return; } v.execute(request, response); + + } else if (col == null) { + response.sendError(WebdavStatus.SC_NOT_FOUND); + } else if (resource == null) { // redirect if path does not end with '/' if (!path.endsWith("/")) { - String redirect = request.getContextPath() + request.getServletPath() + path + "/?viewer=" + viewer; + String redirect = requestURI + "/?viewer=" + viewer; response.sendRedirect(redirect); return; } HtmlCollectionViewer v = webAdmin.getCollectionViewer(viewer); if (v == null) { - response.setStatus(WebdavStatus.SC_NOT_IMPLEMENTED); + response.sendError(WebdavStatus.SC_NOT_IMPLEMENTED, "No action defined for this viewer"); return; } v.execute(request, response, col); + } else { HtmlResourceViewer v = webAdmin.getResourceViewer(viewer); if (v == null) { - response.setStatus(WebdavStatus.SC_NOT_IMPLEMENTED); + response.sendError(WebdavStatus.SC_NOT_IMPLEMENTED, "No action defined for this viewer"); return; } v.execute(request, response, col, resource); } + } + + private String getPath(HttpServletRequest request) { + StringBuffer pathBuf = new StringBuffer(request.getServletPath()); + String pathInfo = request.getPathInfo(); + if (pathInfo != null) { + pathBuf.append(pathInfo); + } + + // workaround for web containers incorrectly returning empty pathInfo for path '/' + int len = pathBuf.length(); + if (request.getRequestURI().endsWith("/") && (len == 0 || pathBuf.charAt(len - 1) != '/')) { + pathBuf.append("/"); + } + + return pathBuf.toString(); } }