From bf6d1d72a3ebb804931ffc467cb60abeec8aa1ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 8 Nov 2011 16:06:01 +0200 Subject: [PATCH] Move servlet wrapper to AbstractApplicationServlet --- .../server/AbstractApplicationServlet.java | 52 ++++++++++++++++--- .../gwt/server/CommunicationManager.java | 50 +++--------------- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 865d173f4d..2bed6f4cb8 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -41,7 +41,10 @@ import com.vaadin.terminal.ParameterHandler; import com.vaadin.terminal.Terminal; import com.vaadin.terminal.ThemeResource; import com.vaadin.terminal.URIHandler; +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.terminal.WrappedResponse; import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.server.AbstractCommunicationManager.Callback; import com.vaadin.ui.Root; /** @@ -62,6 +65,40 @@ import com.vaadin.ui.Root; public abstract class AbstractApplicationServlet extends HttpServlet implements Constants { + private static class AbstractApplicationServletWrapper implements Callback { + + private final AbstractApplicationServlet servlet; + + public AbstractApplicationServletWrapper( + AbstractApplicationServlet servlet) { + this.servlet = servlet; + } + + public void criticalNotification(WrappedRequest request, + WrappedResponse response, String cap, String msg, + String details, String outOfSyncURL) throws IOException { + servlet.criticalNotification(((WrappedHttpServletRequest) request) + .getHttpServletRequest(), + ((WrappedHttpServletResponse) response) + .getHttpServletResponse(), cap, msg, details, + outOfSyncURL); + } + + public String getRequestPathInfo(WrappedRequest request) { + return servlet + .getRequestPathInfo(((WrappedHttpServletRequest) request) + .getHttpServletRequest()); + } + + public InputStream getThemeResourceAsStream(String themeName, + String resource) throws IOException { + return servlet.getServletContext().getResourceAsStream( + "/" + AbstractApplicationServlet.THEME_DIRECTORY_PATH + + themeName + "/" + resource); + } + + } + // TODO Move some (all?) of the constants to a separate interface (shared // with portlet) @@ -399,6 +436,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + AbstractApplicationServletWrapper servletWrapper = new AbstractApplicationServletWrapper( + this); RequestType requestType = getRequestType(request); if (!ensureCookiesEnabled(requestType, request, response)) { @@ -483,9 +522,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } else if (requestType == RequestType.UIDL) { // Handles AJAX UIDL requests Root root = applicationManager.getApplicationRoot(request, - this, application, null); + this, servletWrapper, application, null); applicationManager.handleUidlRequest(request, response, this, - root); + servletWrapper, root); return; } @@ -504,7 +543,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements // Finds the root within the application Root root = getApplicationRoot(request, applicationManager, - application); + servletWrapper, application); if (root == null) { throw new ServletException(ERROR_NO_WINDOW_FOUND); } @@ -2121,14 +2160,15 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * the HTTP Request. * @param application * the Application to query for root. + * @param servletWrapper * @return Root matching the given URI or null if not found. * @throws ServletException * if an exception has occurred that interferes with the * servlet's normal operation. */ protected Root getApplicationRoot(HttpServletRequest request, - CommunicationManager applicationManager, Application application) - throws ServletException { + CommunicationManager applicationManager, Callback servletWrapper, + Application application) throws ServletException { // // // Finds the window where the request is handled Root assumedRoot = null; @@ -2156,7 +2196,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements // } // return applicationManager.getApplicationRoot(request, this, - application, assumedRoot); + servletWrapper, application, assumedRoot); } /** diff --git a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java index c7eb62e8f2..02bd4ea8e3 100644 --- a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java @@ -5,7 +5,6 @@ package com.vaadin.terminal.gwt.server; import java.io.IOException; -import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -18,8 +17,6 @@ import com.vaadin.Application; import com.vaadin.terminal.Paintable; import com.vaadin.terminal.StreamVariable; import com.vaadin.terminal.VariableOwner; -import com.vaadin.terminal.WrappedRequest; -import com.vaadin.terminal.WrappedResponse; import com.vaadin.ui.Component; import com.vaadin.ui.Root; @@ -39,40 +36,6 @@ import com.vaadin.ui.Root; @SuppressWarnings("serial") public class CommunicationManager extends AbstractCommunicationManager { - private static class AbstractApplicationServletWrapper implements Callback { - - private final AbstractApplicationServlet servlet; - - public AbstractApplicationServletWrapper( - AbstractApplicationServlet servlet) { - this.servlet = servlet; - } - - public void criticalNotification(WrappedRequest request, - WrappedResponse response, String cap, String msg, - String details, String outOfSyncURL) throws IOException { - servlet.criticalNotification(((WrappedHttpServletRequest) request) - .getHttpServletRequest(), - ((WrappedHttpServletResponse) response) - .getHttpServletResponse(), cap, msg, details, - outOfSyncURL); - } - - public String getRequestPathInfo(WrappedRequest request) { - return servlet - .getRequestPathInfo(((WrappedHttpServletRequest) request) - .getHttpServletRequest()); - } - - public InputStream getThemeResourceAsStream(String themeName, - String resource) throws IOException { - return servlet.getServletContext().getResourceAsStream( - "/" + AbstractApplicationServlet.THEME_DIRECTORY_PATH - + themeName + "/" + resource); - } - - } - /** * @deprecated use {@link #CommunicationManager(Application)} instead * @param application @@ -159,6 +122,7 @@ public class CommunicationManager extends AbstractCommunicationManager { * @param request * @param response * @param applicationServlet + * @param callback * @param window * target window of the UIDL request, can be null if window not * found @@ -167,12 +131,12 @@ public class CommunicationManager extends AbstractCommunicationManager { */ public void handleUidlRequest(HttpServletRequest request, HttpServletResponse response, - AbstractApplicationServlet applicationServlet, Root root) - throws IOException, ServletException, + AbstractApplicationServlet applicationServlet, Callback callback, + Root root) throws IOException, ServletException, InvalidUIDLSecurityKeyException { doHandleUidlRequest(new WrappedHttpServletRequest(request, applicationServlet), new WrappedHttpServletResponse(response), - new AbstractApplicationServletWrapper(applicationServlet), root); + callback, root); } /** @@ -186,17 +150,17 @@ public class CommunicationManager extends AbstractCommunicationManager { * @param assumedRoot * if the window has been already resolved once, this parameter * must contain the window. + * @param callback * @return Window matching the given URI or null if not found. * @throws ServletException * if an exception has occurred that interferes with the * servlet's normal operation. */ Root getApplicationRoot(HttpServletRequest request, - AbstractApplicationServlet applicationServlet, + AbstractApplicationServlet applicationServlet, Callback callback, Application application, Root assumedRoot) throws ServletException { return doGetApplicationWindow(new WrappedHttpServletRequest(request, - applicationServlet), new AbstractApplicationServletWrapper( - applicationServlet), application, assumedRoot); + applicationServlet), callback, application, assumedRoot); } @Override -- 2.39.5