]> source.dussan.org Git - vaadin-framework.git/commitdiff
Remove VaadinServiceSession.getURL (#9884) 70/70/3
authorLeif Åstrand <leif@vaadin.com>
Mon, 8 Oct 2012 10:17:07 +0000 (13:17 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 8 Oct 2012 10:43:19 +0000 (10:43 +0000)
* Give an URL to LegacyApplication when initializing
* Update LoginForm to use DynamicConnectorResource instead of
RequestHandler
* Make CustomUIClassLoader work again (including previous issues not
caused by this change)
* Update some other tests to use more sensible URLs

Change-Id: I53ed5e9be3b44ed1b62f9762507b0007d53f15b7

server/src/com/vaadin/LegacyApplication.java
server/src/com/vaadin/server/LegacyApplicationUIProvider.java
server/src/com/vaadin/server/VaadinService.java
server/src/com/vaadin/server/VaadinServiceSession.java
server/src/com/vaadin/ui/LoginForm.java
server/src/com/vaadin/ui/UI.java
server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java
uitest/src/com/vaadin/tests/TestBench.java
uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java

index a7f29bf4b15118c5fa2850d44a3b96617a5ce87a..8526bc331025e0d09e1c8bc4111c02b2c5bb3c0a 100644 (file)
@@ -55,6 +55,7 @@ public abstract class LegacyApplication implements ErrorListener {
      * application is just closed without redirection.
      */
     private String logoutURL = null;
+    private URL url;
 
     /**
      * Sets the main window of this application. Setting window as a main window
@@ -80,7 +81,8 @@ public abstract class LegacyApplication implements ErrorListener {
         this.mainWindow = mainWindow;
     }
 
-    public void doInit() {
+    public void doInit(URL url) {
+        this.url = url;
         VaadinServiceSession.getCurrent().setErrorHandler(this);
         init();
     }
@@ -241,7 +243,7 @@ public abstract class LegacyApplication implements ErrorListener {
     }
 
     public URL getURL() {
-        return VaadinServiceSession.getCurrent().getURL();
+        return url;
     }
 
     /**
index c3e450fd7aebeb201bc9d9989aeafb9065037f2a..bedab3210574ce14fe04ed0b858b97407655a621 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.vaadin.server;
 
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -124,7 +126,15 @@ public abstract class LegacyApplicationUIProvider extends UIProvider {
             }
             VaadinServiceSession.getCurrent().setAttribute(
                     LegacyApplication.class, application);
-            application.doInit();
+
+            URL applicationUrl;
+            try {
+                applicationUrl = VaadinService.getCurrent().getApplicationUrl(
+                        VaadinService.getCurrentRequest());
+            } catch (MalformedURLException e) {
+                throw new RuntimeException(e);
+            }
+            application.doInit(applicationUrl);
         }
 
         if (application != null && !application.isRunning()) {
index d9c8b83ea4db94b3176a66cb67fdd7cebf83b5f4..9d78d4c107af85e2296729fdcd4756a5ab6bcbad 100644 (file)
@@ -35,7 +35,6 @@ import javax.servlet.ServletException;
 import com.vaadin.LegacyApplication;
 import com.vaadin.annotations.PreserveOnRefresh;
 import com.vaadin.event.EventRouter;
-import com.vaadin.server.VaadinServiceSession.SessionStartEvent;
 import com.vaadin.shared.ui.ui.UIConstants;
 import com.vaadin.ui.UI;
 import com.vaadin.util.CurrentInstance;
@@ -426,19 +425,11 @@ public abstract class VaadinService implements Serializable {
 
         session.storeInSession(this, request.getWrappedSession());
 
-        URL applicationUrl;
-        try {
-            applicationUrl = getApplicationUrl(request);
-        } catch (MalformedURLException e) {
-            throw new ServiceException(e);
-        }
-
         // Initial locale comes from the request
         Locale locale = request.getLocale();
         session.setLocale(locale);
-        session.start(new SessionStartEvent(applicationUrl,
-                getDeploymentConfiguration(),
-                createCommunicationManager(session)));
+        session.setConfiguration(getDeploymentConfiguration());
+        session.setCommunicationManager(createCommunicationManager(session));
 
         ServletPortletHelper.initDefaultUIProvider(session, this);
         onVaadinSessionStarted(request, session);
index 67b224df70bb8791293aadefa74e8ede1698b10b..62a11c710ab7634950e4926597e40a4f405155dc 100644 (file)
@@ -18,7 +18,6 @@ package com.vaadin.server;
 
 import java.io.Serializable;
 import java.lang.reflect.Method;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -81,79 +80,11 @@ public class VaadinServiceSession implements HttpSessionBindingListener,
 
     private final Lock lock = new ReentrantLock();
 
-    /**
-     * An event sent to {@link #start(SessionStartEvent)} when a new Application
-     * is being started.
-     * 
-     * @deprecated might be refactored or removed before 7.0.0
-     */
-    @Deprecated
-    public static class SessionStartEvent implements Serializable {
-        private final URL applicationUrl;
-
-        private final DeploymentConfiguration configuration;
-
-        private final AbstractCommunicationManager communicationManager;
-
-        /**
-         * @param applicationUrl
-         *            the URL the application should respond to.
-         * @param configuration
-         *            the deployment configuration for the session.
-         * @param communicationManager
-         *            the communication manager for the session.
-         */
-        public SessionStartEvent(URL applicationUrl,
-                DeploymentConfiguration configuration,
-                AbstractCommunicationManager communicationManager) {
-            this.applicationUrl = applicationUrl;
-            this.configuration = configuration;
-            this.communicationManager = communicationManager;
-        }
-
-        /**
-         * Gets the URL the application should respond to.
-         * 
-         * @return the URL the application should respond to or
-         *         <code>null</code> if the URL is not defined.
-         * 
-         * @see VaadinServiceSession#getURL()
-         */
-        public URL getApplicationUrl() {
-            return applicationUrl;
-        }
-
-        /**
-         * Returns the deployment configuration used by this session.
-         * 
-         * @return the deployment configuration.
-         */
-        public DeploymentConfiguration getConfiguration() {
-            return configuration;
-        }
-
-        /**
-         * Gets the communication manager for this application.
-         * 
-         * @return the communication manager for this application.
-         * 
-         * @see VaadinServiceSession#getCommunicationManager
-         */
-        public AbstractCommunicationManager getCommunicationManager() {
-            return communicationManager;
-        }
-    }
-
     /**
      * Configuration for the session.
      */
     private DeploymentConfiguration configuration;
 
-    /**
-     * The application's URL.
-     */
-    private URL applicationUrl;
-
     /**
      * Default locale of the session.
      */
@@ -285,26 +216,6 @@ public class VaadinServiceSession implements HttpSessionBindingListener,
         return communicationManager;
     }
 
-    /**
-     * Gets the URL of the application.
-     * 
-     * <p>
-     * This is the URL what can be entered to a browser window to start the
-     * application. Navigating to the application URL shows the main window (
-     * {@link #getMainWindow()}) of the application. Note that the main window
-     * can also be shown by navigating to the window url (
-     * {@link com.vaadin.ui.Window#getURL()}).
-     * </p>
-     * 
-     * @return the application's URL.
-     * 
-     * @deprecated might be refactored or removed before 7.0.0
-     */
-    @Deprecated
-    public URL getURL() {
-        return applicationUrl;
-    }
-
     /**
      * @param service
      *            TODO
@@ -354,34 +265,21 @@ public class VaadinServiceSession implements HttpSessionBindingListener,
         this.session = session;
     }
 
-    /**
-     * Starts the application on the given URL.
-     * 
-     * <p>
-     * This method is called by Vaadin framework when a user navigates to the
-     * application. After this call the application corresponds to the given URL
-     * and it will return windows when asked for them. There is no need to call
-     * this method directly.
-     * </p>
-     * 
-     * <p>
-     * Application properties are defined by servlet configuration object
-     * {@link javax.servlet.ServletConfig} and they are overridden by
-     * context-wide initialization parameters
-     * {@link javax.servlet.ServletContext}.
-     * </p>
-     * 
-     * @param event
-     *            the application start event containing details required for
-     *            starting the application.
-     * 
-     * @deprecated might be refactored or removed before 7.0.0
-     */
-    @Deprecated
-    public void start(SessionStartEvent event) {
-        applicationUrl = event.getApplicationUrl();
-        configuration = event.getConfiguration();
-        communicationManager = event.getCommunicationManager();
+    public void setCommunicationManager(
+            AbstractCommunicationManager communicationManager) {
+        if (communicationManager == null) {
+            throw new IllegalArgumentException("Can not set to null");
+        }
+        assert this.communicationManager == null : "Communication manager can only be set once";
+        this.communicationManager = communicationManager;
+    }
+
+    public void setConfiguration(DeploymentConfiguration configuration) {
+        if (configuration == null) {
+            throw new IllegalArgumentException("Can not set to null");
+        }
+        assert this.configuration == null : "Configuration can only be set once";
+        this.configuration = configuration;
     }
 
     /**
index 76cec66f275dc43ccfdd255656dacfbf4abde441..b1e47414506d189c70b316b2deb756bdc89c5ce4 100644 (file)
  */
 package com.vaadin.ui;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
-import com.vaadin.server.ConnectorResource;
-import com.vaadin.server.DownloadStream;
-import com.vaadin.server.RequestHandler;
+import com.vaadin.server.DynamicConnectorResource;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.VaadinResponse;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinService;
+import com.vaadin.server.VaadinServletService;
 import com.vaadin.shared.ApplicationConstants;
 
 /**
@@ -62,67 +59,56 @@ public class LoginForm extends CustomComponent {
 
     private Embedded iframe = new Embedded();
 
-    private ConnectorResource loginPage = new ConnectorResource() {
-        @Override
-        public String getFilename() {
-            return "login";
+    @Override
+    public boolean handleConnectorRequest(VaadinRequest request,
+            VaadinResponse response, String path) throws IOException {
+        String method = VaadinServletService.getCurrentServletRequest()
+                .getMethod();
+        if (!path.equals("login")) {
+            return super.handleConnectorRequest(request, response, path);
         }
-
-        @Override
-        public DownloadStream getStream() {
-            byte[] loginHTML = getLoginHTML();
-            DownloadStream downloadStream = new DownloadStream(
-                    new ByteArrayInputStream(loginHTML), getMIMEType(),
-                    getFilename());
-            downloadStream.setBufferSize(loginHTML.length);
-            downloadStream.setCacheTime(-1);
-            return downloadStream;
+        String responseString = null;
+        if (method.equalsIgnoreCase("post")) {
+            responseString = handleLogin(request);
+        } else {
+            responseString = getLoginHTML();
         }
 
-        @Override
-        public String getMIMEType() {
-            return "text/html; charset=utf-8";
-        }
-    };
-
-    private final RequestHandler requestHandler = new RequestHandler() {
-        @Override
-        public boolean handleRequest(VaadinServiceSession session,
-                VaadinRequest request, VaadinResponse response)
-                throws IOException {
-            String requestPathInfo = request.getRequestPathInfo();
-            if ("/loginHandler".equals(requestPathInfo)) {
-                // Ensure UI.getCurrent() works in listeners
-                UI.setCurrent(getUI());
-
-                response.setCacheTime(-1);
-                response.setContentType("text/html; charset=utf-8");
-                response.getWriter()
-                        .write("<html><body>Login form handled."
-                                + "<script type='text/javascript'>parent.parent.vaadin.forceSync();"
-                                + "</script></body></html>");
-
-                Map<String, String[]> parameters = request.getParameterMap();
-
-                HashMap<String, String> params = new HashMap<String, String>();
-                // expecting single params
-                for (Iterator<String> it = parameters.keySet().iterator(); it
-                        .hasNext();) {
-                    String key = it.next();
-                    String value = (parameters.get(key))[0];
-                    params.put(key, value);
-                }
-                LoginEvent event = new LoginEvent(LoginForm.this, params);
-                fireEvent(event);
-                return true;
-            }
+        if (responseString != null) {
+            response.setContentType("text/html; charset=utf-8");
+            response.setCacheTime(-1);
+            response.getWriter().write(responseString);
+            return true;
+        } else {
             return false;
         }
-    };
+    }
+
+    private String handleLogin(VaadinRequest request) {
+        // Ensure UI.getCurrent() works in listeners
+
+        Map<String, String[]> parameters = VaadinService.getCurrentRequest()
+                .getParameterMap();
+
+        HashMap<String, String> params = new HashMap<String, String>();
+        // expecting single params
+        for (Iterator<String> it = parameters.keySet().iterator(); it.hasNext();) {
+            String key = it.next();
+            String value = (parameters.get(key))[0];
+            params.put(key, value);
+        }
+        LoginEvent event = new LoginEvent(LoginForm.this, params);
+        fireEvent(event);
+
+        return "<html><body>Login form handled."
+                + "<script type='text/javascript'>parent.parent.vaadin.forceSync();"
+                + "</script></body></html>";
+    }
 
     public LoginForm() {
         iframe.setType(Embedded.TYPE_BROWSER);
         iframe.setSizeFull();
+        iframe.setSource(new DynamicConnectorResource(this, "login"));
         setSizeFull();
         setCompositionRoot(iframe);
         addStyleName("v-loginform");
@@ -135,67 +121,46 @@ public class LoginForm extends CustomComponent {
      * 
      * @return byte array containing login page html
      */
-    protected byte[] getLoginHTML() {
-        String appUri = getSession().getURL().toString();
-
-        try {
-            return ("<!DOCTYPE html>\n" + "<html>"
-                    + "<head><script type='text/javascript'>"
-                    + "var setTarget = function() {" + "var uri = '"
-                    + appUri
-                    + "loginHandler"
-                    + "'; var f = document.getElementById('loginf');"
-                    + "document.forms[0].action = uri;document.forms[0].username.focus();};"
-                    + ""
-                    + "var styles = window.parent.document.styleSheets;"
-                    + "for(var j = 0; j < styles.length; j++) {\n"
-                    + "if(styles[j].href) {"
-                    + "var stylesheet = document.createElement('link');\n"
-                    + "stylesheet.setAttribute('rel', 'stylesheet');\n"
-                    + "stylesheet.setAttribute('type', 'text/css');\n"
-                    + "stylesheet.setAttribute('href', styles[j].href);\n"
-                    + "document.getElementsByTagName('head')[0].appendChild(stylesheet);\n"
-                    + "}"
-                    + "}\n"
-                    + "function submitOnEnter(e) { var keycode = e.keyCode || e.which;"
-                    + " if (keycode == 13) {document.forms[0].submit();}  } \n"
-                    + "</script>"
-                    + "</head><body onload='setTarget();' style='margin:0;padding:0; background:transparent;' class=\""
-                    + ApplicationConstants.GENERATED_BODY_CLASSNAME
-                    + "\">"
-                    + "<div class='v-app v-app-loginpage' style=\"background:transparent;\">"
-                    + "<iframe name='logintarget' style='width:0;height:0;"
-                    + "border:0;margin:0;padding:0;display:block'></iframe>"
-                    + "<form id='loginf' target='logintarget' onkeypress=\"submitOnEnter(event)\" method=\"post\">"
-                    + "<div>"
-                    + usernameCaption
-                    + "</div><div >"
-                    + "<input class='v-textfield v-widget' style='display:block;' type='text' name='username'></div>"
-                    + "<div>"
-                    + passwordCaption
-                    + "</div>"
-                    + "<div><input class='v-textfield v-widget' style='display:block;' type='password' name='password'></div>"
-                    + "<div><div onclick=\"document.forms[0].submit();\" tabindex=\"0\" class=\"v-button\" role=\"button\" ><span class=\"v-button-wrap\"><span class=\"v-button-caption\">"
-                    + loginButtonCaption
-                    + "</span></span></div></div></form></div>" + "</body></html>")
-                    .getBytes("UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException("UTF-8 encoding not avalable", e);
-        }
-    }
-
-    @Override
-    public void attach() {
-        super.attach();
-        getSession().addRequestHandler(requestHandler);
-        iframe.setSource(loginPage);
-    }
-
-    @Override
-    public void detach() {
-        getSession().removeRequestHandler(requestHandler);
-
-        super.detach();
+    protected String getLoginHTML() {
+        return "<!DOCTYPE html>\n"
+                + "<html>"
+                + "<head><script type='text/javascript'>"
+                + "var setTarget = function() {"
+                + "var uri = window.location;"
+                + "var f = document.getElementById('loginf');"
+                + "document.forms[0].action = uri;document.forms[0].username.focus();};"
+                + ""
+                + "var styles = window.parent.document.styleSheets;"
+                + "for(var j = 0; j < styles.length; j++) {\n"
+                + "if(styles[j].href) {"
+                + "var stylesheet = document.createElement('link');\n"
+                + "stylesheet.setAttribute('rel', 'stylesheet');\n"
+                + "stylesheet.setAttribute('type', 'text/css');\n"
+                + "stylesheet.setAttribute('href', styles[j].href);\n"
+                + "document.getElementsByTagName('head')[0].appendChild(stylesheet);\n"
+                + "}"
+                + "}\n"
+                + "function submitOnEnter(e) { var keycode = e.keyCode || e.which;"
+                + " if (keycode == 13) {document.forms[0].submit();}  } \n"
+                + "</script>"
+                + "</head><body onload='setTarget();' style='margin:0;padding:0; background:transparent;' class=\""
+                + ApplicationConstants.GENERATED_BODY_CLASSNAME
+                + "\">"
+                + "<div class='v-app v-app-loginpage' style=\"background:transparent;\">"
+                + "<iframe name='logintarget' style='width:0;height:0;"
+                + "border:0;margin:0;padding:0;display:block'></iframe>"
+                + "<form id='loginf' target='logintarget' onkeypress=\"submitOnEnter(event)\" method=\"post\">"
+                + "<div>"
+                + usernameCaption
+                + "</div><div >"
+                + "<input class='v-textfield v-widget' style='display:block;' type='text' name='username'></div>"
+                + "<div>"
+                + passwordCaption
+                + "</div>"
+                + "<div><input class='v-textfield v-widget' style='display:block;' type='password' name='password'></div>"
+                + "<div><div onclick=\"document.forms[0].submit();\" tabindex=\"0\" class=\"v-button\" role=\"button\" ><span class=\"v-button-wrap\"><span class=\"v-button-caption\">"
+                + loginButtonCaption
+                + "</span></span></div></div></form></div>" + "</body></html>";
     }
 
     /**
index 3cacf5c497c7b13bd51a1eb1f6e07f548d6ad22b..0954bbec13a003e0454b29c0c51e36e09c2ddce9 100644 (file)
@@ -149,7 +149,7 @@ public abstract class UI extends AbstractComponentContainer implements
          * to a window. All windows can be accessed through
          * {@code http://host:port/app/win} where {@code http://host:port/app}
          * is the application URL (as returned by
-         * {@link VaadinServiceSession#getURL()} and {@code win} is the window
+         * {@link LegacyApplication#getURL()} and {@code win} is the window
          * name.
          * </p>
          * <p>
@@ -170,7 +170,7 @@ public abstract class UI extends AbstractComponentContainer implements
          * to a window. All windows can be accessed through
          * {@code http://host:port/app/win} where {@code http://host:port/app}
          * is the application URL (as returned by
-         * {@link VaadinServiceSession#getURL()} and {@code win} is the window
+         * {@link LegacyApplication#getURL()} and {@code win} is the window
          * name.
          * </p>
          * <p>
@@ -208,13 +208,13 @@ public abstract class UI extends AbstractComponentContainer implements
          *         to an application
          */
         public URL getURL() {
-            VaadinServiceSession session = getSession();
-            if (session == null) {
+            LegacyApplication application = getApplication();
+            if (application == null) {
                 return null;
             }
 
             try {
-                return new URL(session.getURL(), getName() + "/");
+                return new URL(application.getURL(), getName() + "/");
             } catch (MalformedURLException e) {
                 throw new RuntimeException(
                         "Internal problem getting window URL, please report");
index e071c0e484426a2b4d6112d76cab24b3ce863403..405d3d1931bcbfcd6b1663c688a187198d8d12e6 100644 (file)
@@ -15,7 +15,6 @@ import com.vaadin.server.UIClassSelectionEvent;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.VaadinService;
 import com.vaadin.server.VaadinServiceSession;
-import com.vaadin.server.VaadinServiceSession.SessionStartEvent;
 import com.vaadin.ui.UI;
 
 public class CustomUIClassLoader extends TestCase {
@@ -55,8 +54,7 @@ public class CustomUIClassLoader extends TestCase {
      */
     public void testWithNullClassLoader() throws Exception {
         VaadinServiceSession application = createStubApplication();
-        application.start(new SessionStartEvent(null,
-                createConfigurationMock(), null));
+        application.setConfiguration(createConfigurationMock());
 
         DefaultUIProvider uiProvider = new DefaultUIProvider();
         Class<? extends UI> uiClass = uiProvider
@@ -76,12 +74,16 @@ public class CustomUIClassLoader extends TestCase {
         // Mock a VaadinService to give the passed classloader
         VaadinService configurationMock = EasyMock
                 .createMock(VaadinService.class);
+        EasyMock.expect(configurationMock.getDeploymentConfiguration())
+                .andReturn(createConfigurationMock());
         EasyMock.expect(configurationMock.getClassLoader()).andReturn(
                 classloader);
 
         // Mock a VaadinRequest to give the mocked vaadin service
         VaadinRequest requestMock = EasyMock.createMock(VaadinRequest.class);
         EasyMock.expect(requestMock.getService()).andReturn(configurationMock);
+        EasyMock.expect(requestMock.getService()).andReturn(configurationMock);
+        EasyMock.expect(requestMock.getService()).andReturn(configurationMock);
 
         EasyMock.replay(configurationMock, requestMock);
         return requestMock;
@@ -97,13 +99,10 @@ public class CustomUIClassLoader extends TestCase {
     public void testWithClassLoader() throws Exception {
         LoggingClassLoader loggingClassLoader = new LoggingClassLoader();
 
-        VaadinServiceSession application = createStubApplication();
-        application.start(new SessionStartEvent(null,
-                createConfigurationMock(), null));
-
         DefaultUIProvider uiProvider = new DefaultUIProvider();
         Class<? extends UI> uiClass = uiProvider
-                .getUIClass(new UIClassSelectionEvent(createRequestMock(null)));
+                .getUIClass(new UIClassSelectionEvent(
+                        createRequestMock(loggingClassLoader)));
 
         assertEquals(MyUI.class, uiClass);
         assertEquals(1, loggingClassLoader.requestedClasses.size());
index 91e3afd993a07260311531951568743e7c28054d..5a76a7259c614412b11e925cb09878d5ed154aab 100644 (file)
@@ -224,7 +224,7 @@ public class TestBench extends com.vaadin.LegacyApplication implements
     private Component createTestable(Class<?> c) {
         try {
             final LegacyApplication app = (LegacyApplication) c.newInstance();
-            app.doInit();
+            app.doInit(null);
             Layout lo = (Layout) app.getMainWindow().getContent();
             lo.setParent(null);
             return lo;
index 4648529db79307771282d2f0d0b8cc0bc3928b43..e1fae91a3c9865be9cfa099505c8c5e6ef15f709 100644 (file)
@@ -5,7 +5,6 @@ import com.vaadin.server.UIClassSelectionEvent;
 import com.vaadin.server.UICreateEvent;
 import com.vaadin.server.UIProviderEvent;
 import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
 import com.vaadin.shared.ui.label.ContentMode;
 import com.vaadin.tests.components.AbstractTestUIProvider;
 import com.vaadin.ui.Label;
@@ -53,17 +52,16 @@ public class LazyInitUIs extends AbstractTestUIProvider {
                 protected void init(VaadinRequest request) {
                     addComponent(getRequestInfo("NormalUI", request));
 
+                    String location = getPage().getLocation().toString();
                     Link lazyCreateLink = new Link("Open lazyCreate UI",
-                            new ExternalResource(VaadinServiceSession
-                                    .getCurrent().getURL()
-                                    + "?lazyCreate#lazyCreate"));
+                            new ExternalResource(location.replaceFirst(
+                                    "(\\?|#|$).*", "?lazyCreate#lazyCreate")));
                     lazyCreateLink.setTargetName("_blank");
                     addComponent(lazyCreateLink);
 
                     Link lazyInitLink = new Link("Open eagerInit UI",
-                            new ExternalResource(VaadinServiceSession
-                                    .getCurrent().getURL()
-                                    + "?eagerInit#eagerInit"));
+                            new ExternalResource(location.replaceFirst(
+                                    "(\\?|#|$).*", "?eagerInit#eagerInit")));
                     lazyInitLink.setTargetName("_blank");
                     addComponent(lazyInitLink);
                 }
index 4c9ba80677c4a34931b7f2048f9112cebee2a2a6..b5057dd9c2fb41f009194dff910713ba1da6db61 100644 (file)
@@ -2,8 +2,6 @@ package com.vaadin.tests.minitutorials.v7a1;
 
 import java.awt.image.BufferedImage;
 import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
 
 import javax.imageio.ImageIO;
 
@@ -23,14 +21,8 @@ public class DynamicImageUI extends AbstractTestUI {
         getSession().addRequestHandler(new DynamicImageRequestHandler());
 
         // Create a URL that we can handle in DynamicImageRequestHandler
-        URL imageUrl;
-        try {
-            imageUrl = new URL(getSession().getURL(),
-                    DynamicImageRequestHandler.IMAGE_URL + "?text=Hello!");
-        } catch (MalformedURLException e) {
-            // This should never happen
-            throw new RuntimeException(e);
-        }
+        String imageUrl = "app://" + DynamicImageRequestHandler.IMAGE_URL
+                + "?text=Hello!";
 
         // Add an embedded using the created URL
         Embedded embedded = new Embedded("A dynamically generated image",