import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.ConverterFactory;
import com.vaadin.data.util.converter.DefaultConverterFactory;
import com.vaadin.event.EventRouter;
+import com.vaadin.server.AbstractCommunicationManager;
import com.vaadin.server.AbstractErrorMessage;
import com.vaadin.server.ApplicationConfiguration;
-import com.vaadin.server.ApplicationContext;
import com.vaadin.server.BootstrapFragmentResponse;
import com.vaadin.server.BootstrapListener;
import com.vaadin.server.BootstrapPageResponse;
import com.vaadin.server.DeploymentConfiguration;
import com.vaadin.server.GlobalResourceHandler;
import com.vaadin.server.RequestHandler;
-import com.vaadin.server.ServletApplicationContext;
import com.vaadin.server.Terminal;
import com.vaadin.server.UIProvider;
import com.vaadin.server.VaadinServlet;
import com.vaadin.server.VariableOwner;
+import com.vaadin.server.WebBrowser;
import com.vaadin.server.WrappedRequest;
import com.vaadin.server.WrappedRequest.BrowserDetails;
import com.vaadin.server.WrappedResponse;
+import com.vaadin.server.WrappedSession;
import com.vaadin.shared.ui.ui.UIConstants;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.AbstractField;
* @since 3.0
*/
@SuppressWarnings("serial")
-public class Application implements Terminal.ErrorListener, Serializable {
+public class Application implements Terminal.ErrorListener,
+ HttpSessionBindingListener, Serializable {
/**
* The name of the parameter that is by default used in e.g. web.xml to
private final ApplicationConfiguration configuration;
- private final ApplicationContext context;
+ private final AbstractCommunicationManager communicationManager;
/**
* @param applicationUrl
* the URL the application should respond to.
* @param configuration
* the application configuration for the application.
- * @param context
- * the context application will be running in.
+ * @param communicationManager
+ * the communication manager for the application.
*/
public ApplicationStartEvent(URL applicationUrl,
ApplicationConfiguration configuration,
- ApplicationContext context) {
+ AbstractCommunicationManager communicationManager) {
this.applicationUrl = applicationUrl;
this.configuration = configuration;
- this.context = context;
+ this.communicationManager = communicationManager;
}
/**
}
/**
- * Gets the context application will be running in.
+ * Gets the communication manager for this application.
*
- * @return the context application will be running in.
+ * @return the communication manager for this application.
*
- * @see Application#getContext()
+ * @see Application#getCommunicationManager
*/
- public ApplicationContext getContext() {
- return context;
+ public AbstractCommunicationManager getCommunicationManager() {
+ return communicationManager;
}
}
private final static Logger logger = Logger.getLogger(Application.class
.getName());
- /**
- * Application context the application is running in.
- */
- private ApplicationContext context;
-
/**
* Configuration for the application.
*/
private GlobalResourceHandler globalResourceHandler;
+ protected WebBrowser browser = new WebBrowser();
+
+ private AbstractCommunicationManager communicationManager;
+
+ private long totalSessionTime = 0;
+
+ private long lastRequestTime = -1;
+
+ private transient WrappedSession session;
+
+ /**
+ * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
+ */
+ @Override
+ public void valueBound(HttpSessionBindingEvent arg0) {
+ // We are not interested in bindings
+ }
+
+ /**
+ * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)
+ */
+ @Override
+ public void valueUnbound(HttpSessionBindingEvent event) {
+ // If we are going to be unbound from the session, the session must be
+ // closing
+ close();
+ }
+
+ /**
+ * Get the web browser associated with this application context.
+ *
+ * Because application context is related to the http session and server
+ * maintains one session per browser-instance, each context has exactly one
+ * web browser associated with it.
+ *
+ * @return
+ */
+ public WebBrowser getBrowser() {
+ return browser;
+ }
+
+ /**
+ * @return The total time spent servicing requests in this session.
+ */
+ public long getTotalSessionTime() {
+ return totalSessionTime;
+ }
+
+ /**
+ * Sets the time spent servicing the last request in the session and updates
+ * the total time spent servicing requests in this session.
+ *
+ * @param time
+ * the time spent in the last request.
+ */
+ public void setLastRequestTime(long time) {
+ lastRequestTime = time;
+ totalSessionTime += time;
+ }
+
+ /**
+ * @return the time spent servicing the last request in this session.
+ */
+ public long getLastRequestTime() {
+ return lastRequestTime;
+ }
+
+ /**
+ * Gets the session to which this application context is currently
+ * associated.
+ *
+ * @return the wrapped session for this context
+ */
+ public WrappedSession getSession() {
+ return session;
+ }
+
+ public AbstractCommunicationManager getApplicationManager() {
+ return communicationManager;
+ }
+
/**
* Gets the URL of the application.
*
}
}
+ public static Application getForSession(WrappedSession session) {
+ Object attribute = session.getAttribute(Application.class.getName());
+ if (attribute instanceof Application) {
+ Application application = (Application) attribute;
+ application.session = session;
+ return application;
+ }
+
+ return null;
+ }
+
+ public void removeFromSession() {
+ assert (getForSession(session) == this);
+
+ session.setAttribute(Application.class.getName(), null);
+ }
+
+ public void storeInSession(WrappedSession session) {
+ session.setAttribute(Application.class.getName(), this);
+ this.session = session;
+ }
+
/**
* Starts the application on the given URL.
*
public void start(ApplicationStartEvent event) {
applicationUrl = event.getApplicationUrl();
configuration = event.getConfiguration();
- context = event.getContext();
- init();
+ communicationManager = event.getCommunicationManager();
applicationIsRunning = true;
}
* Tests if the application is running or if it has been finished.
*
* <p>
- * Application starts running when its
- * {@link #start(URL, Properties, ApplicationContext)} method has been
- * called and stops when the {@link #close()} is called.
+ * Application starts running when its {@link #start(ApplicationStartEvent)}
+ * method has been called and stops when the {@link #close()} is called.
* </p>
*
* @return <code>true</code> if the application is running,
return applicationIsRunning;
}
- /**
- * <p>
- * Main initializer of the application. The <code>init</code> method is
- * called by the framework when the application is started, and it should
- * perform whatever initialization operations the application needs.
- * </p>
- */
- public void init() {
- // Default implementation does nothing
- }
-
/**
* Gets the configuration for this application
*
getLogger().log(Level.SEVERE, "Terminal error:", t);
}
- /**
- * Gets the application context.
- * <p>
- * The application context is the environment where the application is
- * running in. The actual implementation class of may contains quite a lot
- * more functionality than defined in the {@link ApplicationContext}
- * interface.
- * </p>
- * <p>
- * By default, when you are deploying your application to a servlet
- * container, the implementation class is {@link ServletApplicationContext}
- * - you can safely cast to this class and use the methods from there. When
- * you are deploying your application as a portlet, context implementation
- * is {@link PortletApplicationContext}.
- * </p>
- *
- * @return the application context.
- */
- public ApplicationContext getContext() {
- return context;
- }
-
/**
* Gets the application error handler.
*
* timeout never occurs.
*/
protected int getUidlRequestTimeout() {
- return configuration.isIdleUICleanupEnabled() ? getContext()
- .getSession().getMaxInactiveInterval() : -1;
+ return configuration.isIdleUICleanupEnabled() ? getSession()
+ .getMaxInactiveInterval() : -1;
}
/**
import java.util.regex.Pattern;
import com.vaadin.server.AbstractUIProvider;
-import com.vaadin.server.ApplicationContext;
-import com.vaadin.server.WrappedRequest;
import com.vaadin.server.Terminal.ErrorEvent;
import com.vaadin.server.Terminal.ErrorListener;
+import com.vaadin.server.WrappedRequest;
import com.vaadin.ui.UI;
-import com.vaadin.ui.UI.LegacyWindow;
/**
- * A special application designed to help migrating applications from Vaadin
- * 6 to Vaadin 7. The legacy application supports setting a main window,
- * adding additional browser level windows and defining the theme for the
- * entire application.
+ * A special application designed to help migrating applications from Vaadin 6
+ * to Vaadin 7. The legacy application supports setting a main window, adding
+ * additional browser level windows and defining the theme for the entire
+ * application.
*
- * @deprecated This class is only intended to ease migration and should not
- * be used for new projects.
+ * @deprecated This class is only intended to ease migration and should not be
+ * used for new projects.
*
* @since 7.0
*/
@Deprecated
-public abstract class LegacyApplication extends AbstractUIProvider
- implements ErrorListener {
+public abstract class LegacyApplication extends AbstractUIProvider implements
+ ErrorListener {
/**
* Ignore initial / and then get everything up to the next /
*/
private Map<String, UI.LegacyWindow> legacyUINames = new HashMap<String, UI.LegacyWindow>();
/**
- * Sets the main window of this application. Setting window as a main
- * window of this application also adds the window to this application.
+ * Sets the main window of this application. Setting window as a main window
+ * of this application also adds the window to this application.
*
* @param mainWindow
* the UI to set as the default window
*/
public void setMainWindow(UI.LegacyWindow mainWindow) {
if (this.mainWindow != null) {
- throw new IllegalStateException(
- "mainWindow has already been set");
+ throw new IllegalStateException("mainWindow has already been set");
}
if (mainWindow.getApplication() == null) {
mainWindow.setApplication(Application.getCurrent());
}
@Override
- public UI createInstance(Application application,
- Class<? extends UI> type, WrappedRequest request) {
+ public UI createInstance(Application application, Class<? extends UI> type,
+ WrappedRequest request) {
return getUIInstance(request);
}
}
/**
- * This implementation simulates the way of finding a window for a
- * request by extracting a window name from the requested path and
- * passes that name to {@link #getWindow(String)}.
+ * This implementation simulates the way of finding a window for a request
+ * by extracting a window name from the requested path and passes that name
+ * to {@link #getWindow(String)}.
* <p>
* {@inheritDoc}
*/
/**
* Gets the application's theme. The application's theme is the default
- * theme used by all the uIs for which a theme is not explicitly
- * defined. If the application theme is not explicitly set,
- * <code>null</code> is returned.
+ * theme used by all the uIs for which a theme is not explicitly defined. If
+ * the application theme is not explicitly set, <code>null</code> is
+ * returned.
*
* @return the name of the application's theme.
*/
/**
* <p>
- * Gets a UI by name. Returns <code>null</code> if the application is
- * not running or it does not contain a window corresponding to the
- * name.
+ * Gets a UI by name. Returns <code>null</code> if the application is not
+ * running or it does not contain a window corresponding to the name.
* </p>
*
* @param name
* the name of the requested window
- * @return a UI corresponding to the name, or <code>null</code> to use
- * the default window
+ * @return a UI corresponding to the name, or <code>null</code> to use the
+ * default window
*/
public UI.LegacyWindow getWindow(String name) {
return legacyUINames.get(name);
private int namelessUIIndex = 0;
/**
- * Adds a new browser level window to this application. Please note that
- * UI doesn't have a name that is used in the URL - to add a named
- * window you should instead use {@link #addWindow(UI, String)}
+ * Adds a new browser level window to this application. Please note that UI
+ * doesn't have a name that is used in the URL - to add a named window you
+ * should instead use {@link #addWindow(UI, String)}
*
* @param uI
* the UI window to add to the application
}
/**
- * Removes the specified window from the application. This also removes
- * all name mappings for the window (see {@link #addWindow(UI, String)
- * and #getWindowName(UI)}.
+ * Removes the specified window from the application. This also removes all
+ * name mappings for the window (see {@link #addWindow(UI, String) and
+ * #getWindowName(UI)}.
*
* <p>
- * Note that removing window from the application does not close the
- * browser window - the window is only removed from the server-side.
+ * Note that removing window from the application does not close the browser
+ * window - the window is only removed from the server-side.
* </p>
*
* @param uI
* the UI to remove
*/
public void removeWindow(UI.LegacyWindow uI) {
- for (Entry<String, UI.LegacyWindow> entry : legacyUINames
- .entrySet()) {
+ for (Entry<String, UI.LegacyWindow> entry : legacyUINames.entrySet()) {
if (entry.getValue() == uI) {
legacyUINames.remove(entry.getKey());
}
Application.getCurrent().terminalError(event);
}
- public ApplicationContext getContext() {
- return Application.getCurrent().getContext();
+ public Application getContext() {
+ return Application.getCurrent();
}
protected void close() {
* response.
*/
private void writePerformanceData(final PrintWriter outWriter) {
- ApplicationContext ctx = application.getContext();
outWriter.write(String.format(", \"timings\":[%d, %d]",
- ctx.getTotalSessionTime(), ctx.getLastRequestTime()));
+ application.getTotalSessionTime(),
+ application.getLastRequestTime()));
}
private void legacyPaint(PaintTarget paintTarget,
+++ /dev/null
-/*
- * Copyright 2011 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.server;
-
-import java.io.Serializable;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionBindingListener;
-
-import com.vaadin.Application;
-
-/**
- * <code>ApplicationContext</code> provides information about the running
- * context of the application. Each context is shared by all applications that
- * are open for one user. In a web-environment this corresponds to a
- * HttpSession.
- * <p>
- * Base class for web application contexts (including portlet contexts) that
- * handles the common tasks.
- *
- * @author Vaadin Ltd.
- * @since 3.1
- */
-public abstract class ApplicationContext implements HttpSessionBindingListener,
- Serializable {
-
- private Application application;
-
- protected WebBrowser browser = new WebBrowser();
-
- private AbstractCommunicationManager communicationManager;
-
- private long totalSessionTime = 0;
-
- private long lastRequestTime = -1;
-
- private transient WrappedSession session;
-
- /**
- * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
- */
- @Override
- public void valueBound(HttpSessionBindingEvent arg0) {
- // We are not interested in bindings
- }
-
- /**
- * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)
- */
- @Override
- public void valueUnbound(HttpSessionBindingEvent event) {
- // If we are going to be unbound from the session, the session must be
- // closing
- removeApplication();
- }
-
- /**
- * Get the web browser associated with this application context.
- *
- * Because application context is related to the http session and server
- * maintains one session per browser-instance, each context has exactly one
- * web browser associated with it.
- *
- * @return
- */
- public WebBrowser getBrowser() {
- return browser;
- }
-
- /**
- * Returns the applications in this context.
- *
- * Each application context contains the application for one user.
- *
- * @return The application of this context, or <code>null</code> if there is
- * no application
- */
- public Application getApplication() {
- return application;
- }
-
- public void removeApplication() {
- if (application == null) {
- return;
- }
- try {
- application.close();
- } catch (Exception e) {
- // This should never happen but is possible with rare
- // configurations (e.g. robustness tests). If you have one
- // thread doing HTTP socket write and another thread trying to
- // remove same application here. Possible if you got e.g. session
- // lifetime 1 min but socket write may take longer than 1 min.
- // FIXME: Handle exception
- getLogger().log(Level.SEVERE,
- "Could not close application, leaking memory.", e);
- } finally {
- application = null;
- communicationManager = null;
- }
- }
-
- /**
- * @return The total time spent servicing requests in this session.
- */
- public long getTotalSessionTime() {
- return totalSessionTime;
- }
-
- /**
- * Sets the time spent servicing the last request in the session and updates
- * the total time spent servicing requests in this session.
- *
- * @param time
- * the time spent in the last request.
- */
- public void setLastRequestTime(long time) {
- lastRequestTime = time;
- totalSessionTime += time;
- }
-
- /**
- * @return the time spent servicing the last request in this session.
- */
- public long getLastRequestTime() {
- return lastRequestTime;
- }
-
- private Logger getLogger() {
- return Logger.getLogger(ApplicationContext.class.getName());
- }
-
- /**
- * Gets the session to which this application context is currently
- * associated.
- *
- * @return the wrapped session for this context
- */
- public WrappedSession getSession() {
- return session;
- }
-
- /**
- * Sets the session to which this application context is currently
- * associated.
- *
- * @param session
- * the wrapped session for this context
- */
- public void setSession(WrappedSession session) {
- this.session = session;
- }
-
- public AbstractCommunicationManager getApplicationManager() {
- return communicationManager;
- }
-
- public void setApplication(Application application,
- AbstractCommunicationManager communicationManager) {
- if (this.application != null) {
- removeApplication();
- }
- this.application = application;
- this.communicationManager = communicationManager;
- }
-
-}
\ No newline at end of file
@Override
public WebBrowser getWebBrowser() {
- ApplicationContext context = Application.getCurrent()
- .getContext();
- return context.getBrowser();
+ return Application.getCurrent().getBrowser();
}
};
}
protected InputStream getThemeResourceAsStream(UI uI, String themeName,
String resource) {
ServletApplicationContext context = (ServletApplicationContext) uI
- .getApplication().getContext();
+ .getApplication();
ServletContext servletContext = context.getHttpSession()
.getServletContext();
return servletContext.getResourceAsStream("/"
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.google.apphosting.api.DeadlineExceededException;
+import com.vaadin.Application;
/**
* ApplicationServlet to be used when deploying to Google App Engine, in
}
// de-serialize or create application context, store in session
- ApplicationContext ctx = getApplicationContext(request, memcache);
+ Application ctx = getApplicationContext(request, memcache);
super.service(request, response);
}
}
- protected ApplicationContext getApplicationContext(
- HttpServletRequest request, MemcacheService memcache) {
+ protected Application getApplicationContext(HttpServletRequest request,
+ MemcacheService memcache) {
HttpSession session = request.getSession();
String id = AC_BASE + session.getId();
byte[] serializedAC = (byte[]) memcache.get(id);
ObjectInputStream ois;
try {
ois = new ObjectInputStream(bais);
- ApplicationContext applicationContext = (ApplicationContext) ois
- .readObject();
- session.setAttribute(ServletApplicationContext.class.getName(),
- applicationContext);
+ Application applicationContext = (Application) ois.readObject();
+ applicationContext.storeInSession(new WrappedHttpSession(
+ session));
} catch (IOException e) {
getLogger().log(
Level.WARNING,
}
@Override
- protected Application createApplication(PortletRequest request)
- throws PortletException {
- Application application = super.createApplication(request);
+ protected PortletApplicationContext2 createApplication(
+ PortletRequest request) throws PortletException {
+ PortletApplicationContext2 application = super
+ .createApplication(request);
// Must set current before running init()
Application.setCurrent(application);
}
@Override
- protected Application createApplication(HttpServletRequest request)
- throws ServletException {
- Application application = super.createApplication(request);
+ protected ServletApplicationContext createApplication(
+ HttpServletRequest request) throws ServletException {
+ ServletApplicationContext application = super
+ .createApplication(request);
// Must set current before running init()
Application.setCurrent(application);
}
public WebBrowser getWebBrowser() {
- return uI.getApplication().getContext().getBrowser();
+ return uI.getApplication().getBrowser();
}
public void setBrowserWindowSize(int width, int height) {
import javax.servlet.http.HttpSessionBindingListener;
import javax.xml.namespace.QName;
+import com.vaadin.Application;
import com.vaadin.ui.UI;
import com.vaadin.util.CurrentInstance;
* @author peholmst
*/
@SuppressWarnings("serial")
-public class PortletApplicationContext2 extends ApplicationContext {
+public class PortletApplicationContext2 extends Application {
private final Set<PortletListener> portletListeners = new LinkedHashSet<PortletListener>();
private final Map<String, String> sharedParameterActionNameMap = new HashMap<String, String>();
private final Map<String, String> sharedParameterActionValueMap = new HashMap<String, String>();
- public static PortletApplicationContext2 getApplicationContext(
- PortletSession session) {
- Object cxattr = session.getAttribute(PortletApplicationContext2.class
- .getName());
- PortletApplicationContext2 cx = null;
- // can be false also e.g. if old context comes from another
- // classloader when using
- // <private-session-attributes>false</private-session-attributes>
- // and redeploying the portlet - see #7461
- if (cxattr instanceof PortletApplicationContext2) {
- cx = (PortletApplicationContext2) cxattr;
- }
- if (cx == null) {
- cx = new PortletApplicationContext2();
- session.setAttribute(PortletApplicationContext2.class.getName(), cx);
- }
- cx.setSession(new WrappedPortletSession(session));
- return cx;
- }
-
public PortletSession getPortletSession() {
WrappedSession wrappedSession = getSession();
PortletSession session = ((WrappedPortletSession) wrappedSession)
protected InputStream getThemeResourceAsStream(UI uI, String themeName,
String resource) {
PortletApplicationContext2 context = (PortletApplicationContext2) uI
- .getApplication().getContext();
+ .getApplication();
PortletContext portletContext = context.getPortletSession()
.getPortletContext();
return portletContext.getResourceAsStream("/"
import java.io.Serializable;
+import com.vaadin.Application;
/**
* Times the handling of requests and stores the information as an attribute in
*
* @param context
*/
- public void stop(ApplicationContext context) {
+ public void stop(Application context) {
// Measure and store the total handling time. This data can be
// used in TestBench 3 tests.
long time = (System.nanoTime() - requestStartTime) / 1000000;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
+import com.vaadin.Application;
import com.vaadin.util.CurrentInstance;
/**
* @since 3.1
*/
@SuppressWarnings("serial")
-public class ServletApplicationContext extends ApplicationContext {
+public class ServletApplicationContext extends Application {
private transient boolean reinitializingSession = false;
- /**
- * Creates a new Web Application Context.
- *
- */
- protected ServletApplicationContext() {
-
- }
-
@Override
public void valueUnbound(HttpSessionBindingEvent event) {
if (!reinitializingSession) {
* contents. The purpose of this is to introduce a new session key in order
* to avoid session fixation attacks.
*/
- @SuppressWarnings("unchecked")
public void reinitializeSession() {
HttpSession oldSession = getHttpSession();
}
// Update the "current session" variable
- setSession(new WrappedHttpSession(newSession));
+ storeInSession(new WrappedHttpSession(newSession));
}
/**
return ((WrappedHttpSession) session).getHttpSession();
}
- /**
- * Gets the application context for an HttpSession.
- *
- * @param session
- * the HTTP session.
- * @return the application context for HttpSession.
- */
- static public ServletApplicationContext getApplicationContext(
- HttpSession session) {
- ServletApplicationContext cx = (ServletApplicationContext) session
- .getAttribute(ServletApplicationContext.class.getName());
- if (cx == null) {
- cx = new ServletApplicationContext();
- session.setAttribute(ServletApplicationContext.class.getName(), cx);
- }
- cx.setSession(new WrappedHttpSession(session));
- return cx;
- }
}
* Get or create an application context and an application
* manager for the session
*/
- PortletApplicationContext2 applicationContext = getApplicationContext(request
- .getPortletSession());
+ PortletApplicationContext2 applicationContext = (PortletApplicationContext2) application;
PortletCommunicationManager applicationManager = (PortletCommunicationManager) applicationContext
.getApplicationManager();
applicationContext.getBrowser().updateRequestDetails(
wrappedRequest);
- /* Start the newly created application */
- startApplication(request, application, applicationContext);
applicationRunning = true;
/* Notify listeners */
CurrentInstance.clearAll();
- PortletSession session = request.getPortletSession(false);
- if (session != null) {
- requestTimer.stop(getApplicationContext(session));
+ if (application != null) {
+ requestTimer.stop(application);
}
}
}
&& (request.getParameter(URL_PARAMETER_REPAINT_ALL).equals("1"));
}
- private void startApplication(PortletRequest request,
- Application application, PortletApplicationContext2 context)
- throws PortletException, MalformedURLException {
- if (!application.isRunning()) {
- Locale locale = request.getLocale();
- application.setLocale(locale);
- // No application URL when running inside a portlet
- application.start(new ApplicationStartEvent(null,
- getDeploymentConfiguration().getApplicationConfiguration(),
- context));
- addonContext.fireApplicationStarted(application);
- }
- }
-
private void endApplication(PortletRequest request,
PortletResponse response, Application application)
throws IOException {
- final PortletSession session = request.getPortletSession();
- if (session != null) {
- getApplicationContext(session).removeApplication();
- }
+ application.removeFromSession();
// Do not send any redirects when running inside a portlet.
}
}
application.close();
- if (session != null) {
- PortletApplicationContext2 context = getApplicationContext(session);
- context.removeApplication();
- }
+ application.removeFromSession();
}
private Application createAndRegisterApplication(PortletRequest request)
throw new PortletException(e);
}
- final PortletApplicationContext2 context = getApplicationContext(request
- .getPortletSession());
- context.setApplication(newApplication, new PortletCommunicationManager(
- newApplication));
+ newApplication.storeInSession(new WrappedPortletSession(request
+ .getPortletSession()));
+
+ Locale locale = request.getLocale();
+ newApplication.setLocale(locale);
+ // No application URL when running inside a portlet
+ newApplication.start(new ApplicationStartEvent(null,
+ getDeploymentConfiguration().getApplicationConfiguration(),
+ new PortletCommunicationManager(newApplication)));
+ addonContext.fireApplicationStarted(newApplication);
+
return newApplication;
}
- protected Application createApplication(PortletRequest request)
- throws PortletException {
- Application application = new Application();
+ protected PortletApplicationContext2 createApplication(
+ PortletRequest request) throws PortletException {
+ PortletApplicationContext2 application = new PortletApplicationContext2();
try {
ServletPortletHelper.initDefaultUIProvider(application,
throw new SessionExpiredException();
}
- PortletApplicationContext2 context = getApplicationContext(session);
- Application application = context.getApplication();
+ Application application = Application
+ .getForSession(new WrappedPortletSession(session));
if (application == null) {
return null;
}
- if (application.isRunning()) {
- return application;
+ if (!application.isRunning()) {
+ application.removeFromSession();
+ return null;
}
- // application found but not running
- context.removeApplication();
- return null;
+ return application;
}
private void handleServiceException(WrappedPortletRequest request,
outWriter.close();
}
- /**
- *
- * Gets the application context for a PortletSession. If no context is
- * currently stored in a session a new context is created and stored in the
- * session.
- *
- * @param portletSession
- * the portlet session.
- * @return the application context for the session.
- */
- protected PortletApplicationContext2 getApplicationContext(
- PortletSession portletSession) {
- return PortletApplicationContext2.getApplicationContext(portletSession);
- }
-
private static final Logger getLogger() {
return Logger.getLogger(VaadinPortlet.class.getName());
}
* Get or create a WebApplicationContext and an ApplicationManager
* for the session
*/
- ServletApplicationContext webApplicationContext = getApplicationContext(request
- .getSession());
+ ServletApplicationContext webApplicationContext = (ServletApplicationContext) application;
CommunicationManager applicationManager = (CommunicationManager) webApplicationContext
.getApplicationManager();
/* Update browser information from the request */
webApplicationContext.getBrowser().updateRequestDetails(request);
- // Start the application if it's newly created
- startApplication(request, application, webApplicationContext);
applicationRunning = true;
/* Handle the request */
CurrentInstance.clearAll();
- HttpSession session = request.getSession(false);
- if (session != null) {
- requestTimer.stop(getApplicationContext(session));
+ if (application != null) {
+ requestTimer.stop(application);
}
}
}
}
private Application createAndRegisterApplication(HttpServletRequest request)
- throws ServletException {
+ throws ServletException, MalformedURLException {
Application newApplication = createApplication(request);
try {
throw new ServletException(e);
}
- final ServletApplicationContext context = getApplicationContext(request
- .getSession());
- context.setApplication(newApplication,
- createCommunicationManager(newApplication));
+ newApplication.storeInSession(new WrappedHttpSession(request
+ .getSession()));
+
+ final URL applicationUrl = getApplicationUrl(request);
+
+ // Initial locale comes from the request
+ Locale locale = request.getLocale();
+ newApplication.setLocale(locale);
+ newApplication.start(new ApplicationStartEvent(applicationUrl,
+ getDeploymentConfiguration().getApplicationConfiguration(),
+ createCommunicationManager(newApplication)));
+
+ addonContext.fireApplicationStarted(newApplication);
return newApplication;
}
* @throws ServletException
* @throws MalformedURLException
*/
- protected Application createApplication(HttpServletRequest request)
- throws ServletException {
- Application newApplication = new Application();
+ protected ServletApplicationContext createApplication(
+ HttpServletRequest request) throws ServletException {
+ ServletApplicationContext newApplication = new ServletApplicationContext();
try {
ServletPortletHelper.initDefaultUIProvider(newApplication,
log("Invalid security key received from " + request.getRemoteHost());
}
- /**
- * Starts the application if it is not already running.
- *
- * @param request
- * @param application
- * @param webApplicationContext
- * @throws ServletException
- * @throws MalformedURLException
- */
- private void startApplication(HttpServletRequest request,
- Application application,
- ServletApplicationContext webApplicationContext)
- throws ServletException, MalformedURLException {
-
- if (!application.isRunning()) {
- // Create application
- final URL applicationUrl = getApplicationUrl(request);
-
- // Initial locale comes from the request
- Locale locale = request.getLocale();
- application.setLocale(locale);
- application.start(new ApplicationStartEvent(applicationUrl,
- getDeploymentConfiguration().getApplicationConfiguration(),
- webApplicationContext));
- addonContext.fireApplicationStarted(application);
- }
- }
-
/**
* Check if this is a request for a static resource and, if it is, serve the
* resource to the client.
throw new SessionExpiredException();
}
- ServletApplicationContext context = getApplicationContext(session);
-
- Application sessionApplication = context.getApplication();
+ Application sessionApplication = getApplicationContext(session);
if (sessionApplication == null) {
return null;
}
- if (sessionApplication.isRunning()) {
- // Found a running application
- return sessionApplication;
+ if (!sessionApplication.isRunning()) {
+ sessionApplication.removeFromSession();
+ return null;
}
- // Application has stopped, so remove it before creating a new
- // application
- getApplicationContext(session).removeApplication();
- // Existing application not found
- return null;
+ return sessionApplication;
}
/**
final HttpSession session = request.getSession();
if (session != null) {
- getApplicationContext(session).removeApplication();
+ application.removeFromSession();
}
response.sendRedirect(response.encodeRedirectURL(logoutUrl));
application.close();
if (session != null) {
- ServletApplicationContext context = getApplicationContext(session);
- context.removeApplication();
+ application.removeFromSession();
}
}
- /**
- *
- * Gets the application context from an HttpSession. If no context is
- * currently stored in a session a new context is created and stored in the
- * session.
- *
- * @param session
- * the HTTP session.
- * @return the application context for HttpSession.
- */
- protected ServletApplicationContext getApplicationContext(
- HttpSession session) {
- /*
- * TODO the ApplicationContext.getApplicationContext() should be removed
- * and logic moved here. Now overriding context type is possible, but
- * the whole creation logic should be here. MT 1101
- */
- return ServletApplicationContext.getApplicationContext(session);
+ protected Application getApplicationContext(final HttpSession session) {
+ Application sessionApplication = Application
+ .getForSession(new WrappedHttpSession(session));
+ return sessionApplication;
}
public class RequestError implements Terminal.ErrorEvent, Serializable {
@Override
public WebBrowser getWebBrowser() {
- ApplicationContext context = Application.getCurrent()
- .getContext();
- return context.getBrowser();
+ return Application.getCurrent().getBrowser();
}
};
}
@Override
public WebBrowser getWebBrowser() {
PortletApplicationContext2 context = (PortletApplicationContext2) Application
- .getCurrent().getContext();
+ .getCurrent();
return context.getBrowser();
}
};
import junit.framework.TestCase;
-import com.vaadin.Application;
import com.vaadin.server.ClassResource;
import com.vaadin.ui.Embedded;
public class TestMimeTypes extends TestCase {
public void testEmbeddedPDF() {
- Application app = new Application() {
-
- @Override
- public void init() {
- // TODO Auto-generated method stub
-
- }
- };
Embedded e = new Embedded("A pdf", new ClassResource("file.pddf"));
assertEquals("Invalid mimetype", "application/octet-stream",
e.getMimeType());
}
private CommunicationManager createCommunicationManager() {
- return new CommunicationManager(new Application() {
- @Override
- public void init() {
- // TODO Auto-generated method stub
- }
- });
+ return new CommunicationManager(new Application());
}
}
import com.vaadin.server.AbstractUIProvider;
import com.vaadin.server.ApplicationConfiguration;
import com.vaadin.server.LegacyVaadinServlet;
+import com.vaadin.server.ServletApplicationContext;
import com.vaadin.server.UIProvider;
import com.vaadin.server.WrappedHttpServletRequest;
import com.vaadin.server.WrappedRequest;
}
@Override
- protected Application createApplication(HttpServletRequest request)
- throws ServletException {
+ protected ServletApplicationContext createApplication(
+ HttpServletRequest request) throws ServletException {
try {
final Class<?> classToRun = getClassToRun();
if (UI.class.isAssignableFrom(classToRun)) {
- Application application = new Application();
+ ServletApplicationContext application = new ServletApplicationContext();
application.addUIProvider(new AbstractUIProvider() {
@Override
} else if (LegacyApplication.class.isAssignableFrom(classToRun)) {
return super.createApplication(request);
} else if (UIProvider.class.isAssignableFrom(classToRun)) {
- Application application = new Application();
+ ServletApplicationContext application = new ServletApplicationContext();
application
.addUIProvider((UIProvider) classToRun.newInstance());
return application;
package com.vaadin.tests;
-import com.vaadin.server.ApplicationContext;
import com.vaadin.server.WebBrowser;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Label;
@Override
protected void setup() {
- ApplicationContext context = getContext();
- WebBrowser browser = context.getBrowser();
+ WebBrowser browser = getBrowser();
addComponent(new Label(browser.getBrowserApplication()));
addComponent(new Label("Touch device? "
+ (browser.isTouchDevice() ? "YES" : "No")));
protected void setup() {
Label applications = new Label("Applications in session: <br/>",
ContentMode.XHTML);
- if (getContext().getApplication() != null) {
+ if (getContext() != null) {
applications.setValue(applications.getValue() + "App: "
- + getContext().getApplication() + "<br/>");
+ + getContext() + "<br/>");
}
applications.setValue(applications.getValue() + "<br/><br/>");
package com.vaadin.tests.components;
+import com.vaadin.Application;
import com.vaadin.LegacyApplication;
-import com.vaadin.server.ApplicationContext;
import com.vaadin.server.WebBrowser;
public abstract class AbstractTestCase extends LegacyApplication {
protected abstract Integer getTicketNumber();
protected WebBrowser getBrowser() {
- ApplicationContext context = getContext();
- WebBrowser webBrowser = context.getBrowser();
+ WebBrowser webBrowser = Application.getCurrent().getBrowser();
return webBrowser;
}
package com.vaadin.tests.components;
-import com.vaadin.Application;
-import com.vaadin.server.ApplicationContext;
import com.vaadin.server.WebBrowser;
import com.vaadin.server.WrappedRequest;
import com.vaadin.shared.ui.label.ContentMode;
protected abstract Integer getTicketNumber();
protected WebBrowser getBrowser() {
- ApplicationContext context = Application.getCurrent().getContext();
- ApplicationContext webContext = context;
- return webContext.getBrowser();
+ return getApplication().getBrowser();
}
}
import com.vaadin.Application;
import com.vaadin.server.AbstractUIProvider;
-import com.vaadin.server.ApplicationContext;
import com.vaadin.server.WebBrowser;
public abstract class AbstractTestUIProvider extends AbstractUIProvider {
protected abstract Integer getTicketNumber();
protected WebBrowser getBrowser() {
- ApplicationContext context = Application.getCurrent().getContext();
- WebBrowser webBrowser = context.getBrowser();
+ WebBrowser webBrowser = Application.getCurrent().getBrowser();
return webBrowser;
}
}