* 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
this.mainWindow = mainWindow;
}
- public void doInit() {
+ public void doInit(URL url) {
+ this.url = url;
VaadinServiceSession.getCurrent().setErrorHandler(this);
init();
}
}
public URL getURL() {
- return VaadinServiceSession.getCurrent().getURL();
+ return url;
}
/**
package com.vaadin.server;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
}
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()) {
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;
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);
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;
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.
*/
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
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;
}
/**
*/
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;
/**
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");
*
* @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>";
}
/**
* 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>
* 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>
* 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");
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 {
*/
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
// 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;
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());
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;
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;
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);
}
import java.awt.image.BufferedImage;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
import javax.imageio.ImageIO;
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",