import com.vaadin.server.Terminal;
import com.vaadin.server.UIProvider;
import com.vaadin.server.VariableOwner;
-import com.vaadin.server.WebApplicationContext;
+import com.vaadin.server.ServletApplicationContext;
import com.vaadin.server.WrappedRequest;
import com.vaadin.server.WrappedRequest.BrowserDetails;
import com.vaadin.server.WrappedResponse;
* </p>
* <p>
* By default, when you are deploying your application to a servlet
- * container, the implementation class is {@link WebApplicationContext} -
+ * 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}.
* Get or create a WebApplicationContext and an ApplicationManager
* for the session
*/
- WebApplicationContext webApplicationContext = getApplicationContext(request
+ ServletApplicationContext webApplicationContext = getApplicationContext(request
.getSession());
CommunicationManager applicationManager = webApplicationContext
.getApplicationManager(application, this);
// Notifies transaction end
try {
if (transactionStarted) {
- ((WebApplicationContext) application.getContext())
+ ((ServletApplicationContext) application.getContext())
.endTransaction(application, request);
}
throws ServletException, MalformedURLException {
Application newApplication = getNewApplication(request);
- final WebApplicationContext context = getApplicationContext(request
+ final ServletApplicationContext context = getApplicationContext(request
.getSession());
context.addApplication(newApplication);
* @throws MalformedURLException
*/
private void startApplication(HttpServletRequest request,
- Application application, WebApplicationContext webApplicationContext)
+ Application application, ServletApplicationContext webApplicationContext)
throws ServletException, MalformedURLException {
if (!application.isRunning()) {
throw new SessionExpiredException();
}
- WebApplicationContext context = getApplicationContext(session);
+ ServletApplicationContext context = getApplicationContext(session);
// Gets application list for the session.
final Collection<Application> applications = context.getApplications();
application.close();
if (session != null) {
- WebApplicationContext context = getApplicationContext(session);
+ ServletApplicationContext context = getApplicationContext(session);
context.removeApplication(application);
}
}
* the HTTP session.
* @return the application context for HttpSession.
*/
- protected WebApplicationContext getApplicationContext(HttpSession session) {
+ 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 WebApplicationContext.getApplicationContext(session);
+ return ServletApplicationContext.getApplicationContext(session);
}
public class RequestError implements Terminal.ErrorEvent, Serializable {
* mananger implementation.
*
* @deprecated Instead of overriding this method, override
- * {@link WebApplicationContext} implementation via
+ * {@link ServletApplicationContext} implementation via
* {@link AbstractApplicationServlet#getApplicationContext(HttpSession)}
* method and in that customized implementation return your
* CommunicationManager in
- * {@link WebApplicationContext#getApplicationManager(Application, AbstractApplicationServlet)}
+ * {@link ServletApplicationContext#getApplicationManager(Application, AbstractApplicationServlet)}
* method.
*
* @param application
@Override
public WebBrowser getWebBrowser() {
- WebApplicationContext context = (WebApplicationContext) Application
- .getCurrent().getContext();
+ ApplicationContext context = Application.getCurrent()
+ .getContext();
return context.getBrowser();
}
};
@Override
protected InputStream getThemeResourceAsStream(UI uI, String themeName,
String resource) {
- WebApplicationContext context = (WebApplicationContext) uI
+ ServletApplicationContext context = (ServletApplicationContext) uI
.getApplication().getContext();
ServletContext servletContext = context.getHttpSession()
.getServletContext();
ois = new ObjectInputStream(bais);
ApplicationContext applicationContext = (ApplicationContext) ois
.readObject();
- session.setAttribute(WebApplicationContext.class.getName(),
+ session.setAttribute(ServletApplicationContext.class.getName(),
applicationContext);
} catch (IOException e) {
getLogger().log(
private void cleanSession(HttpServletRequest request) {
HttpSession session = request.getSession(false);
if (session != null) {
- session.removeAttribute(WebApplicationContext.class.getName());
+ session.removeAttribute(ServletApplicationContext.class.getName());
}
}
}
public WebBrowser getWebBrowser() {
- return ((WebApplicationContext) uI.getApplication().getContext())
- .getBrowser();
+ return uI.getApplication().getContext().getBrowser();
}
public void setBrowserWindowSize(int width, int height) {
--- /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.File;
+import java.util.Enumeration;
+import java.util.HashMap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
+import com.vaadin.Application;
+
+/**
+ * Web application context for Vaadin applications.
+ *
+ * This is automatically added as a {@link HttpSessionBindingListener} when
+ * added to a {@link HttpSession}.
+ *
+ * @author Vaadin Ltd.
+ * @since 3.1
+ */
+@SuppressWarnings("serial")
+public class ServletApplicationContext extends ApplicationContext {
+
+ protected transient HttpSession session;
+ private transient boolean reinitializingSession = false;
+
+ /**
+ * Stores a reference to the currentRequest. Null it not inside a request.
+ */
+ private transient Object currentRequest = null;
+
+ /**
+ * Creates a new Web Application Context.
+ *
+ */
+ protected ServletApplicationContext() {
+
+ }
+
+ @Override
+ protected void startTransaction(Application application, Object request) {
+ currentRequest = request;
+ super.startTransaction(application, request);
+ }
+
+ @Override
+ protected void endTransaction(Application application, Object request) {
+ super.endTransaction(application, request);
+ currentRequest = null;
+ }
+
+ @Override
+ public void valueUnbound(HttpSessionBindingEvent event) {
+ if (!reinitializingSession) {
+ // Avoid closing the application if we are only reinitializing the
+ // session. Closing the application would cause the state to be lost
+ // and a new application to be created, which is not what we want.
+ super.valueUnbound(event);
+ }
+ }
+
+ /**
+ * Discards the current session and creates a new session with the same
+ * 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();
+
+ // Stores all attributes (security key, reference to this context
+ // instance) so they can be added to the new session
+ HashMap<String, Object> attrs = new HashMap<String, Object>();
+ for (Enumeration<String> e = oldSession.getAttributeNames(); e
+ .hasMoreElements();) {
+ String name = e.nextElement();
+ attrs.put(name, oldSession.getAttribute(name));
+ }
+
+ // Invalidate the current session, set flag to avoid call to
+ // valueUnbound
+ reinitializingSession = true;
+ oldSession.invalidate();
+ reinitializingSession = false;
+
+ // Create a new session
+ HttpSession newSession = ((HttpServletRequest) currentRequest)
+ .getSession();
+
+ // Restores all attributes (security key, reference to this context
+ // instance)
+ for (String name : attrs.keySet()) {
+ newSession.setAttribute(name, attrs.get(name));
+ }
+
+ // Update the "current session" variable
+ session = newSession;
+ }
+
+ /**
+ * Gets the application context base directory.
+ *
+ * @see com.vaadin.server.ApplicationContext#getBaseDirectory()
+ */
+ @Override
+ public File getBaseDirectory() {
+ final String realPath = ApplicationServlet.getResourcePath(
+ session.getServletContext(), "/");
+ if (realPath == null) {
+ return null;
+ }
+ return new File(realPath);
+ }
+
+ /**
+ * Gets the http-session application is running in.
+ *
+ * @return HttpSession this application context resides in.
+ */
+ public HttpSession getHttpSession() {
+ return session;
+ }
+
+ /**
+ * 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);
+ }
+ if (cx.session == null) {
+ cx.session = session;
+ }
+ return cx;
+ }
+
+ protected void addApplication(Application application) {
+ applications.add(application);
+ }
+
+ /**
+ * Gets communication manager for an application.
+ *
+ * If this application has not been running before, a new manager is
+ * created.
+ *
+ * @param application
+ * @return CommunicationManager
+ */
+ public CommunicationManager getApplicationManager(Application application,
+ AbstractApplicationServlet servlet) {
+ CommunicationManager mgr = (CommunicationManager) applicationToAjaxAppMgrMap
+ .get(application);
+
+ if (mgr == null) {
+ // Creates new manager
+ mgr = servlet.createCommunicationManager(application);
+ applicationToAjaxAppMgrMap.put(application, mgr);
+ }
+ return mgr;
+ }
+
+ @Override
+ public int getMaxInactiveInterval() {
+ return getHttpSession().getMaxInactiveInterval();
+ }
+}
+++ /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.File;
-import java.util.Enumeration;
-import java.util.HashMap;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionBindingListener;
-
-import com.vaadin.Application;
-
-/**
- * Web application context for Vaadin applications.
- *
- * This is automatically added as a {@link HttpSessionBindingListener} when
- * added to a {@link HttpSession}.
- *
- * @author Vaadin Ltd.
- * @since 3.1
- */
-@SuppressWarnings("serial")
-public class WebApplicationContext extends ApplicationContext {
-
- protected transient HttpSession session;
- private transient boolean reinitializingSession = false;
-
- /**
- * Stores a reference to the currentRequest. Null it not inside a request.
- */
- private transient Object currentRequest = null;
-
- /**
- * Creates a new Web Application Context.
- *
- */
- protected WebApplicationContext() {
-
- }
-
- @Override
- protected void startTransaction(Application application, Object request) {
- currentRequest = request;
- super.startTransaction(application, request);
- }
-
- @Override
- protected void endTransaction(Application application, Object request) {
- super.endTransaction(application, request);
- currentRequest = null;
- }
-
- @Override
- public void valueUnbound(HttpSessionBindingEvent event) {
- if (!reinitializingSession) {
- // Avoid closing the application if we are only reinitializing the
- // session. Closing the application would cause the state to be lost
- // and a new application to be created, which is not what we want.
- super.valueUnbound(event);
- }
- }
-
- /**
- * Discards the current session and creates a new session with the same
- * 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();
-
- // Stores all attributes (security key, reference to this context
- // instance) so they can be added to the new session
- HashMap<String, Object> attrs = new HashMap<String, Object>();
- for (Enumeration<String> e = oldSession.getAttributeNames(); e
- .hasMoreElements();) {
- String name = e.nextElement();
- attrs.put(name, oldSession.getAttribute(name));
- }
-
- // Invalidate the current session, set flag to avoid call to
- // valueUnbound
- reinitializingSession = true;
- oldSession.invalidate();
- reinitializingSession = false;
-
- // Create a new session
- HttpSession newSession = ((HttpServletRequest) currentRequest)
- .getSession();
-
- // Restores all attributes (security key, reference to this context
- // instance)
- for (String name : attrs.keySet()) {
- newSession.setAttribute(name, attrs.get(name));
- }
-
- // Update the "current session" variable
- session = newSession;
- }
-
- /**
- * Gets the application context base directory.
- *
- * @see com.vaadin.server.ApplicationContext#getBaseDirectory()
- */
- @Override
- public File getBaseDirectory() {
- final String realPath = ApplicationServlet.getResourcePath(
- session.getServletContext(), "/");
- if (realPath == null) {
- return null;
- }
- return new File(realPath);
- }
-
- /**
- * Gets the http-session application is running in.
- *
- * @return HttpSession this application context resides in.
- */
- public HttpSession getHttpSession() {
- return session;
- }
-
- /**
- * Gets the application context for an HttpSession.
- *
- * @param session
- * the HTTP session.
- * @return the application context for HttpSession.
- */
- static public WebApplicationContext getApplicationContext(
- HttpSession session) {
- WebApplicationContext cx = (WebApplicationContext) session
- .getAttribute(WebApplicationContext.class.getName());
- if (cx == null) {
- cx = new WebApplicationContext();
- session.setAttribute(WebApplicationContext.class.getName(), cx);
- }
- if (cx.session == null) {
- cx.session = session;
- }
- return cx;
- }
-
- protected void addApplication(Application application) {
- applications.add(application);
- }
-
- /**
- * Gets communication manager for an application.
- *
- * If this application has not been running before, a new manager is
- * created.
- *
- * @param application
- * @return CommunicationManager
- */
- public CommunicationManager getApplicationManager(Application application,
- AbstractApplicationServlet servlet) {
- CommunicationManager mgr = (CommunicationManager) applicationToAjaxAppMgrMap
- .get(application);
-
- if (mgr == null) {
- // Creates new manager
- mgr = servlet.createCommunicationManager(application);
- applicationToAjaxAppMgrMap.put(application, mgr);
- }
- return mgr;
- }
-
- @Override
- public int getMaxInactiveInterval() {
- return getHttpSession().getMaxInactiveInterval();
- }
-}
@Override
public WebBrowser getWebBrowser() {
- WebApplicationContext context = (WebApplicationContext) Application
- .getCurrent().getContext();
+ ApplicationContext context = Application.getCurrent()
+ .getContext();
return context.getBrowser();
}
};
import com.vaadin.Application.ApplicationStartEvent;
import com.vaadin.server.ApplicationContext;
import com.vaadin.server.DeploymentConfiguration;
-import com.vaadin.server.WebApplicationContext;
+import com.vaadin.server.ServletApplicationContext;
public class TransactionListenersConcurrency extends TestCase {
final List<Throwable> exceptions = new ArrayList<Throwable>();
HttpSession session = createSession();
- final WebApplicationContext context = WebApplicationContext
+ final ServletApplicationContext context = ServletApplicationContext
.getApplicationContext(session);
List<Thread> threads = new ArrayList<Thread>();
private static HttpSession createSession() {
HttpSession session = createMock(HttpSession.class);
EasyMock.expect(
- session.getAttribute(WebApplicationContext.class.getName()))
+ session.getAttribute(ServletApplicationContext.class.getName()))
.andReturn(null).anyTimes();
session.setAttribute(
- EasyMock.eq(WebApplicationContext.class.getName()),
+ EasyMock.eq(ServletApplicationContext.class.getName()),
EasyMock.anyObject());
EasyMock.replay(session);
package com.vaadin.tests;
-import com.vaadin.server.WebApplicationContext;
+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() {
- WebApplicationContext context = (WebApplicationContext) getContext();
+ ApplicationContext context = getContext();
WebBrowser browser = context.getBrowser();
addComponent(new Label(browser.getBrowserApplication()));
addComponent(new Label("Touch device? "
package com.vaadin.tests.application;
import com.vaadin.Application;
-import com.vaadin.server.WebApplicationContext;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
protected void setup() {
Label applications = new Label("Applications in session: <br/>",
ContentMode.XHTML);
- for (Application a : ((WebApplicationContext) getContext())
- .getApplications()) {
+ for (Application a : getContext().getApplications()) {
applications.setValue(applications.getValue() + "App: " + a
+ "<br/>");
}
package com.vaadin.tests.applicationcontext;
-import com.vaadin.server.WebApplicationContext;
+import com.vaadin.server.ServletApplicationContext;
import com.vaadin.tests.components.AbstractTestCase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button;
loginButton.addListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
- WebApplicationContext context = ((WebApplicationContext) getContext());
+ ServletApplicationContext context = ((ServletApplicationContext) getContext());
String oldSessionId = context.getHttpSession().getId();
context.reinitializeSession();
}
protected String getSessionId() {
- return ((WebApplicationContext) getContext()).getHttpSession().getId();
+ return ((ServletApplicationContext) getContext()).getHttpSession().getId();
}
@Override
import java.io.FileInputStream;
import com.vaadin.Application;
-import com.vaadin.server.WebApplicationContext;
+import com.vaadin.server.ServletApplicationContext;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
try {
cl1 = new CustomLayout(new ByteArrayInputStream(s.getBytes()));
layout.addComponent(cl1);
- WebApplicationContext wc = ((WebApplicationContext) getContext());
+ ServletApplicationContext wc = ((ServletApplicationContext) getContext());
layout.addComponent(new Button("Disable/Enable",
new ClickListener() {