From: Joonas Lehtinen Date: Mon, 23 Jul 2007 08:20:27 +0000 (+0000) Subject: Developing gwt-adapter further X-Git-Tag: 6.7.0.beta1~6159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4c1baacd3186c5dd01dc82a06a584c7d48360232;p=vaadin-framework.git Developing gwt-adapter further svn changeset:1895/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java index 35e4c5e7c2..66bc25e610 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java @@ -33,14 +33,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.lang.reflect.Constructor; import java.net.MalformedURLException; import java.net.URL; import java.util.Collection; import java.util.Date; import java.util.Enumeration; -import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -52,8 +51,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpSessionBindingEvent; -import javax.servlet.http.HttpSessionBindingListener; import org.xml.sax.SAXException; @@ -71,13 +68,12 @@ import com.itmill.toolkit.terminal.URIHandler; import com.itmill.toolkit.ui.Window; /** - * This servlet connects IT Mill Toolkit Application to Web. This servlet - * replaces both WebAdapterServlet and AjaxAdapterServlet. + * This servlet connects IT Mill Toolkit Application to Web. * * @author IT Mill Ltd. * @version * @VERSION@ - * @since 4.0 + * @since 5.0 */ public class ApplicationServlet extends HttpServlet { @@ -132,9 +128,6 @@ public class ApplicationServlet extends HttpServlet { private static WeakHashMap licensePrintedForApplicationClass = new WeakHashMap(); - // TODO Should default or base theme be the default? - protected static final String DEFAULT_THEME = "base"; - private static final String RESOURCE_URI = "/RES/"; private static final String AJAX_UIDL_URI = "/UIDL/"; @@ -206,15 +199,32 @@ public class ApplicationServlet extends HttpServlet { "If debug parameter is given for an application, it must be 'true' or 'false'"); this.debugMode = debug; + // Gets custom class loader + String classLoaderName = getApplicationOrSystemProperty( + "ClassLoader", null); + ClassLoader classLoader; + if (classLoaderName == null) + classLoader = getClass().getClassLoader(); + else { + try { + Class classLoaderClass = getClass().getClassLoader().loadClass(classLoaderName); + Constructor c = classLoaderClass.getConstructor(new Class[] {ClassLoader.class}); + classLoader = (ClassLoader) c.newInstance(new Object[] {getClass().getClassLoader()}); + } catch (Exception e) { + Log.error("Could not find specified class loader: " + classLoaderName); + throw new ServletException(e); + } + } + // Loads the application class using the same class loader // as the servlet itself - ClassLoader loader = this.getClass().getClassLoader(); try { - this.applicationClass = loader.loadClass(applicationClassName); + this.applicationClass = classLoader.loadClass(applicationClassName); } catch (ClassNotFoundException e) { throw new ServletException("Failed to load application class: " + applicationClassName); } + } /** @@ -286,18 +296,13 @@ public class ApplicationServlet extends HttpServlet { protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // Transformer and output stream for the result - OutputStream out = response.getOutputStream(); Application application = null; try { // Gets the application application = getApplication(request); - // Creates application if it doesn't exist - if (application == null) - application = createApplication(request); - + // Sets the last application request date synchronized (applicationToLastRequestDate) { applicationToLastRequestDate.put(application, new Date()); @@ -347,31 +352,14 @@ public class ApplicationServlet extends HttpServlet { return; } - // Returns blank page, if no window found - if (window == null) { - response.setContentType("text/html"); - BufferedWriter page = new BufferedWriter( - new OutputStreamWriter(out)); - page.write(""); - page - .write("The requested window has been removed from application."); - page.write(""); - page.close(); - - return; - } - // Sets terminal type for the window, if not already set if (window.getTerminal() == null) { // TODO !!!! window.setTerminal(new WebBrowser()); } - // Finds theme - String themeName = window.getTheme() != null ? window - .getTheme() : DEFAULT_THEME; + // Finds theme name + String themeName = window.getTheme(); if (request.getParameter("theme") != null) { themeName = request.getParameter("theme"); } @@ -380,7 +368,7 @@ public class ApplicationServlet extends HttpServlet { if (handleResourceRequest(request, response, themeName)) return; - writeAjaxPage(request, response, out, + writeAjaxPage(request, response, window, themeName); } } @@ -424,10 +412,10 @@ public class ApplicationServlet extends HttpServlet { * represented by the given URL. */ private void writeAjaxPage(HttpServletRequest request, - HttpServletResponse response, OutputStream out, + HttpServletResponse response, Window window, String themeName) throws IOException, MalformedURLException { response.setContentType("text/html"); - BufferedWriter page = new BufferedWriter(new OutputStreamWriter(out)); + BufferedWriter page = new BufferedWriter(new OutputStreamWriter(response.getOutputStream())); page .write(" Allways preload layouts with the - // theme specified by the applications - String themeName = application.getTheme() != null ? application - .getTheme() - : ApplicationServlet.DEFAULT_THEME; + String themeName = window.getTheme(); + if (request.getParameter("theme") != null) { + themeName = request.getParameter("theme"); + } + if (themeName == null) themeName = "default"; + // TODO We should only precache the layouts that are not // cached already int resourceIndex = 0; diff --git a/src/com/itmill/toolkit/terminal/gwt/server/Log.java b/src/com/itmill/toolkit/terminal/gwt/server/Log.java index 27bd738c62..a9fe1e0ff4 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/Log.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/Log.java @@ -77,7 +77,7 @@ class Log { * @param message * the Message String to be logged. */ - protected static synchronized void warn(java.lang.String message) { + static synchronized void warn(java.lang.String message) { if (Log.useStdOut) System.out.println(LOG_MSG_WARN + " " + message); } @@ -88,7 +88,7 @@ class Log { * @param message * the Message String to be logged. */ - protected static synchronized void debug(java.lang.String message) { + static synchronized void debug(java.lang.String message) { if (Log.useStdOut) System.out.println(LOG_MSG_DEBUG + " " + message); } @@ -99,7 +99,7 @@ class Log { * @param message * the Message String to be logged. */ - protected static synchronized void info(java.lang.String message) { + static synchronized void info(java.lang.String message) { if (Log.useStdOut) System.out.println(LOG_MSG_INFO + " " + message); } @@ -112,8 +112,7 @@ class Log { * @param e * the Exception to be logged. */ - protected static synchronized void except(java.lang.String message, - Exception e) { + static synchronized void except(java.lang.String message, Exception e) { if (Log.useStdOut) { System.out.println(LOG_MSG_EXCEPT + " " + message); e.printStackTrace(); @@ -126,7 +125,7 @@ class Log { * @param message * the Message String to be logged. */ - protected static synchronized void error(java.lang.String message) { + static synchronized void error(java.lang.String message) { if (Log.useStdOut) System.out.println(LOG_MSG_ERROR + " " + message); }