From: Jani Laakso Date: Tue, 4 Dec 2007 18:13:55 +0000 (+0000) Subject: Fixed #943 (Creating new applications without altering web.xml) X-Git-Tag: 6.7.0.beta1~5290 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2bfeca0498c879c11f11a54a22ad87cccdaa78c2;p=vaadin-framework.git Fixed #943 (Creating new applications without altering web.xml) How to use * Try http://localhost:8080/myContext/run/com.itmill.toolkit.demo.Calc web.xml contains run/* servlet with applicationRunner=true parameter. This should not affect Toolkit in any way if applicationRunner is not defined. Currently it is defined only with run/* This needs review. Reason why I did this is to * skip one step more for newbies * "how to start" flash demo is simpler (included XML is enough for any new application) Side-effects * UIDL request have part of URI path after their UIDL request, see firebug svn changeset:3160/svn branch:trunk --- diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index d2efa61f31..b2bbb36184 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -11,6 +11,16 @@ IT Mill Toolkit examples + + ITMillToolkitApplicationRunner + com.itmill.toolkit.terminal.gwt.server.ApplicationServlet + + applicationRunner + true + + + + DemoTestBench com.itmill.toolkit.terminal.gwt.server.ApplicationServlet @@ -340,7 +350,12 @@ application com.itmill.toolkit.demo.WindowedDemos - + + + + ITMillToolkitApplicationRunner + /run/* + DemoTestBench diff --git a/build/package/WebContent/WEB-INF/web.xml b/build/package/WebContent/WEB-INF/web.xml index 5f6950c7ae..6b41c1198e 100644 --- a/build/package/WebContent/WEB-INF/web.xml +++ b/build/package/WebContent/WEB-INF/web.xml @@ -11,6 +11,15 @@ IT Mill Toolkit examples + + ITMillToolkitApplicationRunner + com.itmill.toolkit.terminal.gwt.server.ApplicationServlet + + applicationRunner + true + + + FeatureBrowser com.itmill.toolkit.terminal.gwt.server.ApplicationServlet @@ -237,6 +246,11 @@ + + ITMillToolkitApplicationRunner + /run/* + + FeatureBrowser /FeatureBrowser/* diff --git a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java index 529d1f4229..c7d9f8357d 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java @@ -146,6 +146,8 @@ public class ApplicationServlet extends HttpServlet { private String debugMode = ""; + private boolean applicationRunnerMode = false; + private ClassLoader classLoader; /** @@ -163,12 +165,17 @@ public class ApplicationServlet extends HttpServlet { throws javax.servlet.ServletException { super.init(servletConfig); - // Gets the application class name - String applicationClassName = servletConfig - .getInitParameter("application"); - if (applicationClassName == null) { - System.err - .println("Application not specified in servlet parameters"); + // Get applicationRunner + String applicationRunner = servletConfig + .getInitParameter("applicationRunner"); + if (applicationRunner != null) { + if ("true".equals(applicationRunner)) + applicationRunnerMode = true; + else if ("false".equals(applicationRunner)) + applicationRunnerMode = false; + else + throw new ServletException( + "If applicationRunner parameter is given for an application, it must be 'true' or 'false'"); } // Stores the application parameters into Properties object @@ -225,13 +232,23 @@ public class ApplicationServlet extends HttpServlet { // Loads the application class using the same class loader // as the servlet itself - try { - applicationClass = classLoader.loadClass(applicationClassName); - } catch (ClassNotFoundException e) { - throw new ServletException("Failed to load application class: " - + applicationClassName); + if (!applicationRunnerMode) { + // Gets the application class name + String applicationClassName = servletConfig + .getInitParameter("application"); + if (applicationClassName == null) + throw new ServletException( + "Application not specified in servlet parameters"); + try { + applicationClass = classLoader.loadClass(applicationClassName); + } catch (ClassNotFoundException e) { + throw new ServletException("Failed to load application class: " + + applicationClassName); + } + } else { + // This servlet is in application runner mode, it uses classloader + // later to create Applications based on URL } - } /** @@ -302,10 +319,19 @@ public class ApplicationServlet extends HttpServlet { protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (request.getPathInfo() != null - && request.getPathInfo().startsWith("/ITMILL/")) { - serveStaticResourcesInITMILL(request, response); - return; + if (request.getPathInfo() != null) { + if (applicationRunnerMode + && (request.getPathInfo().indexOf("/", 1) != -1)) { + String resourceUrl = request.getPathInfo().substring( + request.getPathInfo().indexOf('/', 1)); + if (resourceUrl.startsWith("/ITMILL/")) { + serveStaticResourcesInITMILL(resourceUrl, response); + return; + } + } else if (request.getPathInfo().startsWith("/ITMILL/")) { + serveStaticResourcesInITMILL(request.getPathInfo(), response); + return; + } } Application application = null; @@ -342,10 +368,25 @@ public class ApplicationServlet extends HttpServlet { // Handles AJAX UIDL requests String resourceId = request.getPathInfo(); - if (resourceId != null && resourceId.startsWith(AJAX_UIDL_URI)) { - getApplicationManager(application).handleUidlRequest(request, - response); - return; + if (resourceId != null) { + if (applicationRunnerMode) { + if (resourceId.indexOf("/", 1) != -1) { + String resourceUrl = resourceId.substring(resourceId + .indexOf('/', 1)); + if (resourceId != null + && (resourceUrl.startsWith(AJAX_UIDL_URI))) { + getApplicationManager(application) + .handleUidlRequest(request, response); + return; + } + } + } else { + if (resourceId.startsWith(AJAX_UIDL_URI)) { + getApplicationManager(application).handleUidlRequest( + request, response); + return; + } + } } // Handles the URI if the application is still running @@ -427,9 +468,8 @@ public class ApplicationServlet extends HttpServlet { * @param response * @throws IOException */ - private void serveStaticResourcesInITMILL(HttpServletRequest request, + private void serveStaticResourcesInITMILL(String filename, HttpServletResponse response) throws IOException { - String filename = request.getPathInfo(); ServletContext sc = getServletContext(); InputStream is = sc.getResourceAsStream(filename); if (is == null) { @@ -498,17 +538,28 @@ public class ApplicationServlet extends HttpServlet { + "