import java.io.Serializable;
import java.util.Locale;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
public class ConverterUtil implements Serializable {
* Finds a converter that can convert from the given presentation type to
* the given model type and back. Uses the given application to find a
* {@link ConverterFactory} or, if application is null, uses the
- * {@link VaadinServiceSession#getCurrent()}.
+ * {@link VaadinSession#getCurrent()}.
*
* @param <PRESENTATIONTYPE>
* The presentation type
*/
public static <PRESENTATIONTYPE, MODELTYPE> Converter<PRESENTATIONTYPE, MODELTYPE> getConverter(
Class<PRESENTATIONTYPE> presentationType,
- Class<MODELTYPE> modelType, VaadinServiceSession session) {
+ Class<MODELTYPE> modelType, VaadinSession session) {
Converter<PRESENTATIONTYPE, MODELTYPE> converter = null;
if (session == null) {
- session = VaadinServiceSession.getCurrent();
+ session = VaadinSession.getCurrent();
}
if (session != null) {
import java.util.Date;
import java.util.logging.Logger;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
/**
* Default implementation of {@link ConverterFactory}. Provides converters for
* standard types like {@link String}, {@link Double} and {@link Date}. </p>
* <p>
* Custom converters can be provided by extending this class and using
- * {@link VaadinServiceSession#setConverterFactory(ConverterFactory)}.
+ * {@link VaadinSession#setConverterFactory(ConverterFactory)}.
* </p>
*
* @author Vaadin Ltd
}
/**
- * Finds the {@link VaadinServiceSession} to which this connector belongs.
- * If the connector has not been attached, <code>null</code> is returned.
+ * Finds the {@link VaadinSession} to which this connector belongs. If the
+ * connector has not been attached, <code>null</code> is returned.
*
* @return The connector's session, or <code>null</code> if not attached
*/
- protected VaadinServiceSession getSession() {
+ protected VaadinSession getSession() {
UI uI = getUI();
if (uI == null) {
return null;
/**
* The session this communication manager is used for
*/
- private final VaadinServiceSession session;
+ private final VaadinSession session;
private List<String> locales;
*
* @param session
*/
- public AbstractCommunicationManager(VaadinServiceSession session) {
+ public AbstractCommunicationManager(VaadinSession session) {
this.session = session;
session.addRequestHandler(getBootstrapHandler());
session.addRequestHandler(UNSUPPORTED_BROWSER_HANDLER);
requireLocale(session.getLocale().toString());
}
- protected VaadinServiceSession getSession() {
+ protected VaadinSession getSession() {
return session;
}
"StreamVariable for the post not found");
}
- final VaadinServiceSession session = getSession();
+ final VaadinSession session = getSession();
OutputStream out = null;
int totalBytes = 0;
* Internally process a UIDL request from the client.
*
* This method calls
- * {@link #handleVariables(VaadinRequest, VaadinResponse, Callback, VaadinServiceSession, UI)}
+ * {@link #handleVariables(VaadinRequest, VaadinResponse, Callback, VaadinSession, UI)}
* to process any changes to variables by the client and then repaints
* affected components using {@link #paintAfterVariableChanges()}.
*
}
sb.append("\nConnector hierarchy:\n");
- VaadinServiceSession session2 = connector.getUI().getSession();
+ VaadinSession session2 = connector.getUI().getSession();
sb.append(session2.getClass().getName());
sb.append("(");
sb.append(session2.getClass().getSimpleName());
final PrintWriter outWriter, UI ui, boolean analyzeLayouts)
throws PaintException, JSONException {
ArrayList<ClientConnector> dirtyVisibleConnectors = new ArrayList<ClientConnector>();
- VaadinServiceSession session = ui.getSession();
+ VaadinSession session = ui.getSession();
// Paints components
ConnectorTracker uiConnectorTracker = ui.getConnectorTracker();
getLogger().log(Level.FINE, "* Creating response to client");
* @param session
* @return false if the XSRF is turned off, true otherwise
*/
- public boolean isXSRFEnabled(VaadinServiceSession session) {
+ public boolean isXSRFEnabled(VaadinSession session) {
return session.getConfiguration().isXsrfProtectionEnabled();
}
* @return true if successful, false if there was an inconsistency
*/
private boolean handleVariables(VaadinRequest request,
- VaadinResponse response, Callback callback,
- VaadinServiceSession session, UI uI) throws IOException,
- InvalidUIDLSecurityKeyException, JSONException {
+ VaadinResponse response, Callback callback, VaadinSession session,
+ UI uI) throws IOException, InvalidUIDLSecurityKeyException,
+ JSONException {
boolean success = true;
String changes = getRequestPayload(request);
* @param m
* map from variable names to values
*/
- private void handleChangeVariablesError(VaadinServiceSession session,
+ private void handleChangeVariablesError(VaadinSession session,
Component owner, Throwable t, Map<String, Object> m) {
boolean handled = false;
ChangeVariablesErrorEvent errorEvent = new ChangeVariablesErrorEvent(
* @throws IOException
* if a handler throws an exception
*
- * @see VaadinServiceSession#addRequestHandler(RequestHandler)
+ * @see VaadinSession#addRequestHandler(RequestHandler)
* @see RequestHandler
*
* @since 7.0
}
public void handleBrowserDetailsRequest(VaadinRequest request,
- VaadinResponse response, VaadinServiceSession session)
- throws IOException {
+ VaadinResponse response, VaadinSession session) throws IOException {
session.getLock().lock();
}
}
- private UI getBrowserDetailsUI(VaadinRequest request,
- VaadinServiceSession session) {
+ private UI getBrowserDetailsUI(VaadinRequest request, VaadinSession session) {
VaadinService vaadinService = request.getService();
List<UIProvider> uiProviders = session.getUIProviders();
* @throws IOException
* @throws InvalidUIDLSecurityKeyException
*/
- public void handleFileUpload(VaadinServiceSession session,
- VaadinRequest request, VaadinResponse response) throws IOException,
+ public void handleFileUpload(VaadinSession session, VaadinRequest request,
+ VaadinResponse response) throws IOException,
InvalidUIDLSecurityKeyException {
/*
* @throws IOException
*/
public void handleHeartbeatRequest(VaadinRequest request,
- VaadinResponse response, VaadinServiceSession session)
- throws IOException {
+ VaadinResponse response, VaadinSession session) throws IOException {
UI ui = null;
try {
int uiId = Integer.parseInt(request
* Shorthand for adding a bootstrap listener that will be added to every new
* service session.
*
- * @see VaadinServiceSession#addBootstrapListener(BootstrapListener)
+ * @see VaadinSession#addBootstrapListener(BootstrapListener)
*
* @param listener
* the bootstrap listener that should be added to all new
* Crate a new bootstrap fragment response.
*
* @see BootstrapResponse#BootstrapResponse(BootstrapHandler, VaadinRequest,
- * VaadinServiceSession, Class)
+ * VaadinSession, Class)
*
* @param handler
* the bootstrap handler that is firing the event
* the UI provider for the bootstrap
*/
public BootstrapFragmentResponse(BootstrapHandler handler,
- VaadinRequest request, VaadinServiceSession session,
+ VaadinRequest request, VaadinSession session,
Class<? extends UI> uiClass, List<Node> fragmentNodes,
UIProvider uiProvider) {
super(handler, request, session, uiClass, uiProvider);
return bootstrapResponse.getRequest();
}
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return bootstrapResponse.getSession();
}
}
@Override
- public boolean handleRequest(VaadinServiceSession session,
- VaadinRequest request, VaadinResponse response) throws IOException {
+ public boolean handleRequest(VaadinSession session, VaadinRequest request,
+ VaadinResponse response) throws IOException {
try {
List<UIProvider> uiProviders = session.getUIProviders();
protected JSONObject getApplicationParameters(BootstrapContext context)
throws JSONException, PaintException {
VaadinRequest request = context.getRequest();
- VaadinServiceSession session = context.getSession();
+ VaadinSession session = context.getSession();
VaadinService vaadinService = request.getService();
JSONObject appConfig = new JSONObject();
* Crate a new bootstrap page response.
*
* @see BootstrapResponse#BootstrapResponse(BootstrapHandler, VaadinRequest,
- * VaadinServiceSession, Class)
+ * VaadinSession, Class)
*
* @param handler
* the bootstrap handler that is firing the event
* the UI provider for the bootstrap
*/
public BootstrapPageResponse(BootstrapHandler handler,
- VaadinRequest request, VaadinServiceSession session,
+ VaadinRequest request, VaadinSession session,
Class<? extends UI> uiClass, Document document,
Map<String, Object> headers, UIProvider uiProvider) {
super(handler, request, session, uiClass, uiProvider);
*/
public abstract class BootstrapResponse extends EventObject {
private final VaadinRequest request;
- private final VaadinServiceSession session;
+ private final VaadinSession session;
private final Class<? extends UI> uiClass;
private final UIProvider uiProvider;
* the UI provider for the bootstrap
*/
public BootstrapResponse(BootstrapHandler handler, VaadinRequest request,
- VaadinServiceSession session, Class<? extends UI> uiClass,
+ VaadinSession session, Class<? extends UI> uiClass,
UIProvider uiProvider) {
super(handler);
this.request = request;
*
* @return the Vaadin service session
*/
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return session;
}
*
* @param session
*/
- public CommunicationManager(VaadinServiceSession session) {
+ public CommunicationManager(VaadinSession session) {
super(session);
}
}
@Override
- public boolean handleRequest(VaadinServiceSession session,
- VaadinRequest request, VaadinResponse response) throws IOException {
+ public boolean handleRequest(VaadinSession session, VaadinRequest request,
+ VaadinResponse response) throws IOException {
String requestPath = request.getRequestPathInfo();
if (requestPath == null) {
return false;
}
UI.setCurrent(ui);
- VaadinServiceSession.setCurrent(ui.getSession());
+ VaadinSession.setCurrent(ui.getSession());
ClientConnector connector = ui.getConnectorTracker().getConnector(
cid);
import java.util.Properties;
import java.util.logging.Logger;
-
/**
* The default implementation of {@link DeploymentConfiguration} based on a base
* class for resolving system properties and a set of init parameters.
Object uiClassNameObj = request
.getService()
.getDeploymentConfiguration()
- .getApplicationOrSystemProperty(
- VaadinServiceSession.UI_PARAMETER, null);
+ .getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER,
+ null);
if (uiClassNameObj instanceof String) {
String uiClassName = uiClassNameObj.toString();
return ds;
} catch (final FileNotFoundException e) {
// Log the exception using the application error handler
- VaadinServiceSession.getCurrent().getErrorHandler()
+ VaadinSession.getCurrent().getErrorHandler()
.terminalError(new ErrorEvent() {
@Override
}
// de-serialize or create application context, store in session
- VaadinServiceSession ctx = getApplicationContext(request, memcache);
+ VaadinSession ctx = getApplicationContext(request, memcache);
super.service(request, response);
}
}
- protected VaadinServiceSession getApplicationContext(
- HttpServletRequest request, MemcacheService memcache)
- throws ServletException {
+ protected VaadinSession getApplicationContext(HttpServletRequest request,
+ MemcacheService memcache) throws ServletException {
HttpSession session = request.getSession();
String id = AC_BASE + session.getId();
byte[] serializedAC = (byte[]) memcache.get(id);
ObjectInputStream ois;
try {
ois = new ObjectInputStream(bais);
- VaadinServiceSession applicationContext = (VaadinServiceSession) ois
+ VaadinSession applicationContext = (VaadinSession) ois
.readObject();
applicationContext.storeInSession(getService(),
new WrappedHttpSession(session));
if (wrappedSession == null) {
return;
}
- VaadinServiceSession serviceSession = VaadinServiceSession
- .getForSession(getService(), wrappedSession);
+ VaadinSession serviceSession = VaadinSession.getForSession(
+ getService(), wrappedSession);
if (serviceSession == null) {
return;
}
"");
@Override
- public boolean handleRequest(VaadinServiceSession session,
- VaadinRequest request, VaadinResponse response) throws IOException {
+ public boolean handleRequest(VaadinSession session, VaadinRequest request,
+ VaadinResponse response) throws IOException {
String pathInfo = request.getRequestPathInfo();
if (pathInfo == null) {
return false;
public void doInit(URL url) {
this.url = url;
- VaadinServiceSession.getCurrent().setErrorHandler(this);
+ VaadinSession.getCurrent().setErrorHandler(this);
init();
}
* Sets the application's theme.
* <p>
* Note that this theme can be overridden for a specific UI with
- * {@link VaadinServiceSession#getThemeForUI(UI)}. Setting theme to be
+ * {@link VaadinSession#getThemeForUI(UI)}. Setting theme to be
* <code>null</code> selects the default theme. For the available theme
* names, see the contents of the VAADIN/themes directory.
* </p>
uI.setApplication(this);
legacyUINames.put(uI.getName(), uI);
- uI.setSession(VaadinServiceSession.getCurrent());
+ uI.setSession(VaadinSession.getCurrent());
}
/**
DefaultErrorListener.doDefault(event);
}
- public VaadinServiceSession getContext() {
- return VaadinServiceSession.getCurrent();
+ public VaadinSession getContext() {
+ return VaadinSession.getCurrent();
}
public void close() {
}
private LegacyApplication getApplication() {
- LegacyApplication application = VaadinServiceSession.getCurrent()
+ LegacyApplication application = VaadinSession.getCurrent()
.getAttribute(LegacyApplication.class);
if (application == null) {
application = createApplication();
if (application == null) {
return null;
}
- VaadinServiceSession.getCurrent().setAttribute(
- LegacyApplication.class, application);
+ VaadinSession.getCurrent().setAttribute(LegacyApplication.class,
+ application);
URL applicationUrl;
try {
}
if (application != null && !application.isRunning()) {
- VaadinServiceSession.getCurrent().setAttribute(
- LegacyApplication.class, null);
+ VaadinSession.getCurrent().setAttribute(LegacyApplication.class,
+ null);
// Run again without a current application
return getApplication();
}
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
-
public class LegacyVaadinPortlet extends VaadinPortlet {
private static final LegacyApplicationUIProvider provider = new LegacyApplicationUIProvider() {
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
-
public class LegacyVaadinServlet extends VaadinServlet {
private static final UIProvider provider = new LegacyApplicationUIProvider() {
}
private void onVaadinSessionStarted(VaadinRequest request,
- VaadinServiceSession session) throws ServletException {
+ VaadinSession session) throws ServletException {
session.addUIProvider(provider);
}
@SuppressWarnings("serial")
public class PortletCommunicationManager extends AbstractCommunicationManager {
- public PortletCommunicationManager(VaadinServiceSession session) {
+ public PortletCommunicationManager(VaadinSession session) {
super(session);
}
protected BootstrapHandler createBootstrapHandler() {
return new BootstrapHandler() {
@Override
- public boolean handleRequest(VaadinServiceSession session,
+ public boolean handleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response)
throws IOException {
PortletRequest portletRequest = ((VaadinPortletRequest) request)
/**
* Handler for producing a response to non-UIDL requests. Handlers can be added
* to service sessions using
- * {@link VaadinServiceSession#addRequestHandler(RequestHandler)}
+ * {@link VaadinSession#addRequestHandler(RequestHandler)}
*/
public interface RequestHandler extends Serializable {
* handlers should be called, otherwise false
* @throws IOException
*/
- boolean handleRequest(VaadinServiceSession session, VaadinRequest request,
+ boolean handleRequest(VaadinSession session, VaadinRequest request,
VaadinResponse response) throws IOException;
}
*
* @param context
*/
- public void stop(VaadinServiceSession context) {
+ public void stop(VaadinSession context) {
// Measure and store the total handling time. This data can be
// used in TestBench 3 tests.
long time = (System.nanoTime() - requestStartTime) / 1000000;
private static void verifyUIClass(String className, ClassLoader classLoader)
throws ServiceException {
if (className == null) {
- throw new ServiceException(VaadinServiceSession.UI_PARAMETER
+ throw new ServiceException(VaadinSession.UI_PARAMETER
+ " init parameter not defined");
}
ApplicationConstants.HEARTBEAT_REQUEST_PATH);
}
- public static void initDefaultUIProvider(VaadinServiceSession session,
+ public static void initDefaultUIProvider(VaadinSession session,
VaadinService vaadinService) throws ServiceException {
String uiProperty = vaadinService.getDeploymentConfiguration()
- .getApplicationOrSystemProperty(
- VaadinServiceSession.UI_PARAMETER, null);
+ .getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER,
+ null);
// Add provider for UI parameter first to give it lower priority
// (providers are FILO)
}
}
- public static void checkUiProviders(VaadinServiceSession session,
+ public static void checkUiProviders(VaadinSession session,
VaadinService vaadinService) throws ServiceException {
if (session.getUIProviders().isEmpty()) {
throw new ServiceException(
"No UIProvider has been added and there is no \""
- + VaadinServiceSession.UI_PARAMETER
- + "\" init parameter.");
+ + VaadinSession.UI_PARAMETER + "\" init parameter.");
}
}
* <li>The passed component (or UI) if not null</li>
* <li>{@link UI#getCurrent()} if defined</li>
* <li>The passed session if not null</li>
- * <li>{@link VaadinServiceSession#getCurrent()} if defined</li>
+ * <li>{@link VaadinSession#getCurrent()} if defined</li>
* <li>The passed request if not null</li>
* <li>{@link VaadinService#getCurrentRequest()} if defined</li>
* <li>{@link Locale#getDefault()}</li>
* </ol>
*/
- static Locale findLocale(Component component, VaadinServiceSession session,
+ static Locale findLocale(Component component, VaadinSession session,
VaadinRequest request) {
if (component == null) {
component = UI.getCurrent();
}
if (session == null) {
- session = VaadinServiceSession.getCurrent();
+ session = VaadinSession.getCurrent();
}
if (session != null) {
Locale locale = session.getLocale();
*/
public class SessionDestroyEvent extends EventObject {
- private final VaadinServiceSession session;
+ private final VaadinSession session;
/**
* Creates a new event.
* @param session
* the Vaadin service session that is no longer used
*/
- public SessionDestroyEvent(VaadinService service,
- VaadinServiceSession session) {
+ public SessionDestroyEvent(VaadinService service, VaadinSession session) {
super(service);
this.session = session;
}
*
* @return the Vaadin service session
*/
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return session;
}
*/
public class SessionInitEvent extends EventObject {
- private final VaadinServiceSession session;
+ private final VaadinSession session;
private final VaadinRequest request;
/**
* @param request
* the request that triggered the initialization
*/
- public SessionInitEvent(VaadinService service,
- VaadinServiceSession session, VaadinRequest request) {
+ public SessionInitEvent(VaadinService service, VaadinSession session,
+ VaadinRequest request) {
super(service);
this.session = session;
this.request = request;
*
* @return the Vaadin service session
*/
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return session;
}
* the streaming ended before the end of the input. The streaming may fail
* due an interruption by {@link } or due an other unknown exception in
* communication. In the latter case the exception is also passed to
- * {@link VaadinServiceSession#terminalError(com.vaadin.server.Terminal.ErrorEvent)}
+ * {@link VaadinSession#terminalError(com.vaadin.server.Terminal.ErrorEvent)}
* .
*/
public interface StreamingErrorEvent extends StreamingEvent {
* Contains the system messages used to notify the user about various critical
* situations that can occur.
* <p>
- * Customize by overriding the static
- * {@link VaadinServiceSession#getSystemMessages()} and returning
- * {@link CustomizedSystemMessages}.
+ * Customize by overriding the static {@link VaadinSession#getSystemMessages()}
+ * and returning {@link CustomizedSystemMessages}.
* </p>
* <p>
* The defaults defined in this class are:
* piece of information guaranteed to be available, but in most cases some
* or all of {@link VaadinService#getCurrent()},
* {@link VaadinService#getCurrentRequest()},
- * {@link VaadinServiceSession#getCurrent()} and {@link UI#getCurrent()} can
- * also be used to find more information to help the decision.
+ * {@link VaadinSession#getCurrent()} and {@link UI#getCurrent()} can also
+ * be used to find more information to help the decision.
*
* @param locale
* the desired locale of the system messages
public static final String FORCE_LOAD_COOKIE = "vaadinforceload=1";
@Override
- public boolean handleRequest(VaadinServiceSession session,
- VaadinRequest request, VaadinResponse response) throws IOException {
+ public boolean handleRequest(VaadinSession session, VaadinRequest request,
+ VaadinResponse response) throws IOException {
// Check if the browser is supported
// If Chrome Frame is available we'll assume it's ok
protected void writeBrowserTooOldPage(VaadinRequest request,
VaadinResponse response) throws IOException {
Writer page = response.getWriter();
- WebBrowser b = VaadinServiceSession.getCurrent().getBrowser();
+ WebBrowser b = VaadinSession.getCurrent().getBrowser();
page.write("<html><body><h1>I'm sorry, but your browser is not supported</h1>"
+ "<p>The version ("
*/
private void handleOtherRequest(VaadinPortletRequest request,
VaadinResponse response, RequestType requestType,
- VaadinServiceSession vaadinSession,
+ VaadinSession vaadinSession,
PortletCommunicationManager communicationManager)
throws PortletException, IOException, MalformedURLException {
if (requestType == RequestType.APP || requestType == RequestType.RENDER) {
}
private void handleServiceException(VaadinPortletRequest request,
- VaadinPortletResponse response, VaadinServiceSession vaadinSession,
+ VaadinPortletResponse response, VaadinSession vaadinSession,
Throwable e) throws IOException, PortletException {
// TODO Check that this error handler is working when running inside a
// portlet
@Override
protected AbstractCommunicationManager createCommunicationManager(
- VaadinServiceSession session) {
+ VaadinSession session) {
return new PortletCommunicationManager(session);
}
}
@Override
- protected VaadinServiceSession createVaadinSession(VaadinRequest request)
+ protected VaadinSession createVaadinSession(VaadinRequest request)
throws ServiceException {
return new VaadinPortletSession(this);
}
}
@Override
- public String getMainDivId(VaadinServiceSession session,
- VaadinRequest request, Class<? extends UI> uiClass) {
+ public String getMainDivId(VaadinSession session, VaadinRequest request,
+ Class<? extends UI> uiClass) {
PortletRequest portletRequest = ((VaadinPortletRequest) request)
.getPortletRequest();
/*
*/
@Deprecated
@SuppressWarnings("serial")
-public class VaadinPortletSession extends VaadinServiceSession {
+public class VaadinPortletSession extends VaadinSession {
private final Set<PortletListener> portletListeners = new LinkedHashSet<PortletListener>();
SESSION_DESTROY_METHOD);
}
- public void fireSessionDestroy(VaadinServiceSession vaadinSession) {
+ public void fireSessionDestroy(VaadinSession vaadinSession) {
// Ignore if the session is being moved to a different backing session
if (vaadinSession.getAttribute(REINITIALIZING_SESSION_MARKER) == Boolean.TRUE) {
return;
* @param request
* the request to get a vaadin service session for.
*
- * @see VaadinServiceSession
+ * @see VaadinSession
*
* @return the vaadin service session for the request, or <code>null</code>
* if no session is found and this is a request for which a new
* session shouldn't be created.
*/
- public VaadinServiceSession findVaadinSession(VaadinRequest request)
+ public VaadinSession findVaadinSession(VaadinRequest request)
throws ServiceException, SessionExpiredException {
- VaadinServiceSession vaadinSession = findOrCreateVaadinSession(request);
+ VaadinSession vaadinSession = findOrCreateVaadinSession(request);
if (vaadinSession == null) {
return null;
}
- VaadinServiceSession.setCurrent(vaadinSession);
- request.setAttribute(VaadinServiceSession.class.getName(),
- vaadinSession);
+ VaadinSession.setCurrent(vaadinSession);
+ request.setAttribute(VaadinSession.class.getName(), vaadinSession);
return vaadinSession;
}
- private VaadinServiceSession findOrCreateVaadinSession(VaadinRequest request)
+ private VaadinSession findOrCreateVaadinSession(VaadinRequest request)
throws SessionExpiredException, ServiceException {
boolean requestCanCreateSession = requestCanCreateSession(request);
/* Find an existing session for this request. */
- VaadinServiceSession session = getExistingSession(request,
+ VaadinSession session = getExistingSession(request,
requestCanCreateSession);
if (session != null) {
}
- private VaadinServiceSession createAndRegisterSession(VaadinRequest request)
+ private VaadinSession createAndRegisterSession(VaadinRequest request)
throws ServiceException {
- VaadinServiceSession session = createVaadinSession(request);
+ VaadinSession session = createVaadinSession(request);
- VaadinServiceSession.setCurrent(session);
+ VaadinSession.setCurrent(session);
session.storeInSession(this, request.getWrappedSession());
* @return a new communication manager
*/
protected abstract AbstractCommunicationManager createCommunicationManager(
- VaadinServiceSession session);
+ VaadinSession session);
/**
* Creates a new Vaadin service session.
* @throws ServletException
* @throws MalformedURLException
*/
- protected VaadinServiceSession createVaadinSession(VaadinRequest request)
+ protected VaadinSession createVaadinSession(VaadinRequest request)
throws ServiceException {
- return new VaadinServiceSession(this);
+ return new VaadinSession(this);
}
private void onVaadinSessionStarted(VaadinRequest request,
- VaadinServiceSession session) throws ServiceException {
+ VaadinSession session) throws ServiceException {
eventRouter.fireEvent(new SessionInitEvent(this, session, request));
ServletPortletHelper.checkUiProviders(session, this);
}
- private void closeSession(VaadinServiceSession vaadinSession,
+ private void closeSession(VaadinSession vaadinSession,
WrappedSession session) {
if (vaadinSession == null) {
return;
}
}
- protected VaadinServiceSession getExistingSession(VaadinRequest request,
+ protected VaadinSession getExistingSession(VaadinRequest request,
boolean allowSessionCreation) throws SessionExpiredException {
// Ensures that the session is still valid
throw new SessionExpiredException();
}
- VaadinServiceSession vaadinSession = VaadinServiceSession
+ VaadinSession vaadinSession = VaadinSession
.getForSession(this, session);
if (vaadinSession == null) {
*
*/
public UI findUI(VaadinRequest request) {
- VaadinServiceSession session = VaadinServiceSession.getForSession(this,
+ VaadinSession session = VaadinSession.getForSession(this,
request.getWrappedSession());
// Get UI id from the request
HashMap<String, Object> attrs = new HashMap<String, Object>();
for (String name : oldSession.getAttributeNames()) {
Object value = oldSession.getAttribute(name);
- if (value instanceof VaadinServiceSession) {
+ if (value instanceof VaadinSession) {
// set flag to avoid cleanup
- VaadinServiceSession serviceSession = (VaadinServiceSession) value;
+ VaadinSession serviceSession = (VaadinSession) value;
serviceSession.setAttribute(REINITIALIZING_SESSION_MARKER,
Boolean.TRUE);
}
newSession.setAttribute(name, value);
// Ensure VaadinServiceSession knows where it's stored
- if (value instanceof VaadinServiceSession) {
- VaadinServiceSession serviceSession = (VaadinServiceSession) value;
+ if (value instanceof VaadinSession) {
+ VaadinSession serviceSession = (VaadinSession) value;
serviceSession.storeInSession(serviceSession.getService(),
newSession);
serviceSession
*
* @return the id to use in the DOM
*/
- public abstract String getMainDivId(VaadinServiceSession session,
+ public abstract String getMainDivId(VaadinSession session,
VaadinRequest request, Class<? extends UI> uiClass);
/**
* @param session
* the session to close
*/
- public void closeSession(VaadinServiceSession session) {
+ public void closeSession(VaadinSession session) {
session.removeFromSession(this);
}
}
+++ /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.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-import java.util.logging.Logger;
-
-import javax.portlet.PortletSession;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionBindingListener;
-
-import com.vaadin.annotations.PreserveOnRefresh;
-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.ui.AbstractField;
-import com.vaadin.ui.Table;
-import com.vaadin.ui.UI;
-import com.vaadin.util.CurrentInstance;
-import com.vaadin.util.ReflectTools;
-
-/**
- * Contains everything that Vaadin needs to store for a specific user. This is
- * typically stored in a {@link HttpSession} or {@link PortletSession}, but
- * others storage mechanisms might also be used.
- * <p>
- * Everything inside a {@link VaadinServiceSession} should be serializable to
- * ensure compatibility with schemes using serialization for persisting the
- * session data.
- *
- * @author Vaadin Ltd
- * @since 7.0.0
- */
-@SuppressWarnings("serial")
-public class VaadinServiceSession implements HttpSessionBindingListener,
- Serializable {
-
- /**
- * The name of the parameter that is by default used in e.g. web.xml to
- * define the name of the default {@link UI} class.
- */
- public static final String UI_PARAMETER = "UI";
-
- private static final Method BOOTSTRAP_FRAGMENT_METHOD = ReflectTools
- .findMethod(BootstrapListener.class, "modifyBootstrapFragment",
- BootstrapFragmentResponse.class);
- private static final Method BOOTSTRAP_PAGE_METHOD = ReflectTools
- .findMethod(BootstrapListener.class, "modifyBootstrapPage",
- BootstrapPageResponse.class);
-
- private final Lock lock = new ReentrantLock();
-
- /**
- * Configuration for the session.
- */
- private DeploymentConfiguration configuration;
-
- /**
- * Default locale of the session.
- */
- private Locale locale;
-
- /**
- * Session wide error handler which is used by default if an error is left
- * unhandled.
- */
- private Terminal.ErrorListener errorHandler = new DefaultErrorListener();
-
- /**
- * The converter factory that is used to provide default converters for the
- * session.
- */
- private ConverterFactory converterFactory = new DefaultConverterFactory();
-
- private LinkedList<RequestHandler> requestHandlers = new LinkedList<RequestHandler>();
-
- private int nextUIId = 0;
- private Map<Integer, UI> uIs = new HashMap<Integer, UI>();
-
- private final Map<String, Integer> retainOnRefreshUIs = new HashMap<String, Integer>();
-
- private final EventRouter eventRouter = new EventRouter();
-
- private GlobalResourceHandler globalResourceHandler;
-
- protected WebBrowser browser = new WebBrowser();
-
- private AbstractCommunicationManager communicationManager;
-
- private long totalSessionTime = 0;
-
- private long lastRequestTime = -1;
-
- private transient WrappedSession session;
-
- private final Map<String, Object> attributes = new HashMap<String, Object>();
-
- private LinkedList<UIProvider> uiProviders = new LinkedList<UIProvider>();
-
- private VaadinService service;
-
- /**
- * Create a new service session tied to a Vaadin service
- *
- * @param service
- * the Vaadin service for the new session
- */
- public VaadinServiceSession(VaadinService service) {
- this.service = service;
- }
-
- /**
- * @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
- // Notify the service
- service.fireSessionDestroy(this);
- session = null;
- }
-
- /**
- * Get the web browser associated with this session.
- *
- * @return
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- 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 underlying session to which this service session is currently
- * associated.
- *
- * @return the wrapped session for this context
- */
- public WrappedSession getSession() {
- return session;
- }
-
- /**
- * @return
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- public AbstractCommunicationManager getCommunicationManager() {
- return communicationManager;
- }
-
- /**
- * @param service
- * TODO
- * @param underlyingSession
- * @return
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- public static VaadinServiceSession getForSession(VaadinService service,
- WrappedSession underlyingSession) {
- Object attribute = underlyingSession
- .getAttribute(VaadinServiceSession.class.getName() + "."
- + service.getServiceName());
- if (attribute instanceof VaadinServiceSession) {
- VaadinServiceSession vaadinSession = (VaadinServiceSession) attribute;
- vaadinSession.session = underlyingSession;
- return vaadinSession;
- }
-
- return null;
- }
-
- /**
- *
- * @param service
- * TODO
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- public void removeFromSession(VaadinService service) {
- assert (getForSession(service, session) == this);
-
- session.setAttribute(VaadinServiceSession.class.getName() + "."
- + service.getServiceName(), null);
- }
-
- /**
- * @param session
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- public void storeInSession(VaadinService service, WrappedSession session) {
- session.setAttribute(VaadinServiceSession.class.getName() + "."
- + service.getServiceName(), this);
- this.session = session;
- }
-
- 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;
- }
-
- /**
- * Gets the configuration for this session
- *
- * @return the deployment configuration
- */
- public DeploymentConfiguration getConfiguration() {
- return configuration;
- }
-
- /**
- * Gets the default locale for this session.
- *
- * By default this is the preferred locale of the user using the session. In
- * most cases it is read from the browser defaults.
- *
- * @return the locale of this session.
- */
- public Locale getLocale() {
- if (locale != null) {
- return locale;
- }
- return Locale.getDefault();
- }
-
- /**
- * Sets the default locale for this session.
- *
- * By default this is the preferred locale of the user using the
- * application. In most cases it is read from the browser defaults.
- *
- * @param locale
- * the Locale object.
- *
- */
- public void setLocale(Locale locale) {
- this.locale = locale;
- }
-
- /**
- * Gets the session's error handler.
- *
- * @return the current error handler
- */
- public Terminal.ErrorListener getErrorHandler() {
- return errorHandler;
- }
-
- /**
- * Sets the session error handler.
- *
- * @param errorHandler
- */
- public void setErrorHandler(Terminal.ErrorListener errorHandler) {
- this.errorHandler = errorHandler;
- }
-
- /**
- * Gets the {@link ConverterFactory} used to locate a suitable
- * {@link Converter} for fields in the session.
- *
- * See {@link #setConverterFactory(ConverterFactory)} for more details
- *
- * @return The converter factory used in the session
- */
- public ConverterFactory getConverterFactory() {
- return converterFactory;
- }
-
- /**
- * Sets the {@link ConverterFactory} used to locate a suitable
- * {@link Converter} for fields in the session.
- * <p>
- * The {@link ConverterFactory} is used to find a suitable converter when
- * binding data to a UI component and the data type does not match the UI
- * component type, e.g. binding a Double to a TextField (which is based on a
- * String).
- * </p>
- * <p>
- * The {@link Converter} for an individual field can be overridden using
- * {@link AbstractField#setConverter(Converter)} and for individual property
- * ids in a {@link Table} using
- * {@link Table#setConverter(Object, Converter)}.
- * </p>
- * <p>
- * The converter factory must never be set to null.
- *
- * @param converterFactory
- * The converter factory used in the session
- */
- public void setConverterFactory(ConverterFactory converterFactory) {
- this.converterFactory = converterFactory;
- }
-
- /**
- * Application error is an error message defined on the application level.
- *
- * When an error occurs on the application level, this error message4 type
- * should be used. This indicates that the problem is caused by the
- * application - not by the user.
- */
- public class ApplicationError implements Terminal.ErrorEvent {
- private final Throwable throwable;
-
- public ApplicationError(Throwable throwable) {
- this.throwable = throwable;
- }
-
- @Override
- public Throwable getThrowable() {
- return throwable;
- }
-
- }
-
- /**
- * Adds a request handler to this session. Request handlers can be added to
- * provide responses to requests that are not handled by the default
- * functionality of the framework.
- * <p>
- * Handlers are called in reverse order of addition, so the most recently
- * added handler will be called first.
- * </p>
- *
- * @param handler
- * the request handler to add
- *
- * @see #removeRequestHandler(RequestHandler)
- *
- * @since 7.0
- */
- public void addRequestHandler(RequestHandler handler) {
- requestHandlers.addFirst(handler);
- }
-
- /**
- * Removes a request handler from the session.
- *
- * @param handler
- * the request handler to remove
- *
- * @since 7.0
- */
- public void removeRequestHandler(RequestHandler handler) {
- requestHandlers.remove(handler);
- }
-
- /**
- * Gets the request handlers that are registered to the session. The
- * iteration order of the returned collection is the same as the order in
- * which the request handlers will be invoked when a request is handled.
- *
- * @return a collection of request handlers, with the iteration order
- * according to the order they would be invoked
- *
- * @see #addRequestHandler(RequestHandler)
- * @see #removeRequestHandler(RequestHandler)
- *
- * @since 7.0
- */
- public Collection<RequestHandler> getRequestHandlers() {
- return Collections.unmodifiableCollection(requestHandlers);
- }
-
- /**
- * Gets the currently used session. The current session is automatically
- * defined when processing requests to the server and in threads started at
- * a point when the current session is defined (see
- * {@link InheritableThreadLocal}). In other cases, (e.g. from background
- * threads started in some other way), the current session is not
- * automatically defined.
- *
- * @return the current session instance if available, otherwise
- * <code>null</code>
- *
- * @see #setCurrent(VaadinServiceSession)
- *
- * @since 7.0
- */
- public static VaadinServiceSession getCurrent() {
- return CurrentInstance.get(VaadinServiceSession.class);
- }
-
- /**
- * Sets the thread local for the current session. This method is used by the
- * framework to set the current session whenever a new request is processed
- * and it is cleared when the request has been processed.
- * <p>
- * The application developer can also use this method to define the current
- * session outside the normal request handling and treads started from
- * request handling threads, e.g. when initiating custom background threads.
- * </p>
- *
- * @param session
- *
- * @see #getCurrent()
- * @see ThreadLocal
- *
- * @since 7.0
- */
- public static void setCurrent(VaadinServiceSession session) {
- CurrentInstance.setInheritable(VaadinServiceSession.class, session);
- }
-
- /**
- * Gets all the UIs of this session. This includes UIs that have been
- * requested but not yet initialized. UIs that receive no heartbeat requests
- * from the client are eventually removed from the session.
- *
- * @return a collection of UIs belonging to this application
- *
- * @since 7.0
- */
- public Collection<UI> getUIs() {
- return Collections.unmodifiableCollection(uIs.values());
- }
-
- private int connectorIdSequence = 0;
-
- /**
- * Generate an id for the given Connector. Connectors must not call this
- * method more than once, the first time they need an id.
- *
- * @param connector
- * A connector that has not yet been assigned an id.
- * @return A new id for the connector
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- public String createConnectorId(ClientConnector connector) {
- return String.valueOf(connectorIdSequence++);
- }
-
- private static final Logger getLogger() {
- return Logger.getLogger(VaadinServiceSession.class.getName());
- }
-
- /**
- * Returns a UI with the given id.
- * <p>
- * This is meant for framework internal use.
- * </p>
- *
- * @param uiId
- * The UI id
- * @return The UI with the given id or null if not found
- */
- public UI getUIById(int uiId) {
- return uIs.get(uiId);
- }
-
- /**
- * Adds a listener that will be invoked when the bootstrap HTML is about to
- * be generated. This can be used to modify the contents of the HTML that
- * loads the Vaadin application in the browser and the HTTP headers that are
- * included in the response serving the HTML.
- *
- * @see BootstrapListener#modifyBootstrapFragment(BootstrapFragmentResponse)
- * @see BootstrapListener#modifyBootstrapPage(BootstrapPageResponse)
- *
- * @param listener
- * the bootstrap listener to add
- */
- public void addBootstrapListener(BootstrapListener listener) {
- eventRouter.addListener(BootstrapFragmentResponse.class, listener,
- BOOTSTRAP_FRAGMENT_METHOD);
- eventRouter.addListener(BootstrapPageResponse.class, listener,
- BOOTSTRAP_PAGE_METHOD);
- }
-
- /**
- * Remove a bootstrap listener that was previously added.
- *
- * @see #addBootstrapListener(BootstrapListener)
- *
- * @param listener
- * the bootstrap listener to remove
- */
- public void removeBootstrapListener(BootstrapListener listener) {
- eventRouter.removeListener(BootstrapFragmentResponse.class, listener,
- BOOTSTRAP_FRAGMENT_METHOD);
- eventRouter.removeListener(BootstrapPageResponse.class, listener,
- BOOTSTRAP_PAGE_METHOD);
- }
-
- /**
- * Fires a bootstrap event to all registered listeners. There are currently
- * two supported events, both inheriting from {@link BootstrapResponse}:
- * {@link BootstrapFragmentResponse} and {@link BootstrapPageResponse}.
- *
- * @param response
- * the bootstrap response event for which listeners should be
- * fired
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- public void modifyBootstrapResponse(BootstrapResponse response) {
- eventRouter.fireEvent(response);
- }
-
- /**
- * Removes all those UIs from the session for which {@link #isUIAlive}
- * returns false. Cleanup events are fired for the removed UIs.
- * <p>
- * Called by the framework at the end of every request.
- *
- * @see UI.CleanupEvent
- * @see UI.CleanupListener
- * @see #isUIAlive(UI)
- *
- * @since 7.0.0
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- public void cleanupInactiveUIs() {
- for (UI ui : new ArrayList<UI>(uIs.values())) {
- if (!isUIAlive(ui)) {
- cleanupUI(ui);
- getLogger().fine(
- "Closed UI #" + ui.getUIId() + " due to inactivity");
- }
- }
- }
-
- /**
- * Called by the framework to remove an UI instance because it has been
- * inactive.
- *
- * @param ui
- * the UI to remove
- *
- * @deprecated Method is declared as public only to support
- * {@link LegacyApplication#close()} and will be removed when
- * LegacyApplciation support is removed.
- */
- @Deprecated
- public void cleanupUI(UI ui) {
- Integer id = Integer.valueOf(ui.getUIId());
- uIs.remove(id);
- retainOnRefreshUIs.values().remove(id);
- ui.fireCleanupEvent();
- }
-
- /**
- * Returns the number of seconds that must pass without a valid heartbeat or
- * UIDL request being received from a UI before that UI is removed from the
- * application. This is a lower bound; it might take longer to close an
- * inactive UI. Returns a negative number if heartbeat is disabled and
- * timeout never occurs.
- *
- * @see #getUidlRequestTimeout()
- * @see #cleanupInactiveUIs()
- * @see DeploymentConfiguration#getHeartbeatInterval()
- *
- * @since 7.0.0
- *
- * @return The heartbeat timeout in seconds or a negative number if timeout
- * never occurs.
- */
- protected int getHeartbeatTimeout() {
- // Permit three missed heartbeats before closing the UI
- return (int) (configuration.getHeartbeatInterval() * (3.1));
- }
-
- /**
- * Returns the number of seconds that must pass without a valid UIDL request
- * being received from a UI before the UI is removed from the session, even
- * though heartbeat requests are received. This is a lower bound; it might
- * take longer to close an inactive UI. Returns a negative number if
- * <p>
- * This timeout only has effect if cleanup of inactive UIs is enabled;
- * otherwise heartbeat requests are enough to extend UI lifetime
- * indefinitely.
- *
- * @see DeploymentConfiguration#isIdleUICleanupEnabled()
- * @see #getHeartbeatTimeout()
- * @see #cleanupInactiveUIs()
- *
- * @since 7.0.0
- *
- * @return The UIDL request timeout in seconds, or a negative number if
- * timeout never occurs.
- */
- protected int getUidlRequestTimeout() {
- return configuration.isIdleUICleanupEnabled() ? getSession()
- .getMaxInactiveInterval() : -1;
- }
-
- /**
- * Returns whether the given UI is alive (the client-side actively
- * communicates with the server) or whether it can be removed from the
- * session and eventually collected.
- *
- * @since 7.0.0
- *
- * @deprecated Might be refactored or removed before 7.0.0
- *
- * @param ui
- * The UI whose status to check
- * @return true if the UI is alive, false if it could be removed.
- *
- * @deprecated might be refactored or removed before 7.0.0
- */
- @Deprecated
- protected boolean isUIAlive(UI ui) {
- long now = System.currentTimeMillis();
- if (getHeartbeatTimeout() >= 0
- && now - ui.getLastHeartbeatTime() > 1000 * getHeartbeatTimeout()) {
- return false;
- }
- if (getUidlRequestTimeout() >= 0
- && now - ui.getLastUidlRequestTime() > 1000 * getUidlRequestTimeout()) {
- return false;
- }
- return true;
- }
-
- /**
- * Gets this session's global resource handler that takes care of serving
- * connector resources that are not served by any single connector because
- * e.g. because they are served with strong caching or because of legacy
- * reasons.
- *
- * @param createOnDemand
- * <code>true</code> if a resource handler should be initialized
- * if there is no handler associated with this application.
- * </code>false</code> if </code>null</code> should be returned
- * if there is no registered handler.
- * @return this session's global resource handler, or <code>null</code> if
- * there is no handler and the createOnDemand parameter is
- * <code>false</code>.
- *
- * @since 7.0.0
- */
- public GlobalResourceHandler getGlobalResourceHandler(boolean createOnDemand) {
- if (globalResourceHandler == null && createOnDemand) {
- globalResourceHandler = new GlobalResourceHandler();
- addRequestHandler(globalResourceHandler);
- }
-
- return globalResourceHandler;
- }
-
- /**
- * Gets the lock that should be used to synchronize usage of data inside
- * this session.
- *
- * @return the lock that should be used for synchronization
- */
- public Lock getLock() {
- return lock;
- }
-
- /**
- * Stores a value in this service session. This can be used to associate
- * data with the current user so that it can be retrieved at a later point
- * from some other part of the application. Setting the value to
- * <code>null</code> clears the stored value.
- *
- * @see #getAttribute(String)
- *
- * @param name
- * the name to associate the value with, can not be
- * <code>null</code>
- * @param value
- * the value to associate with the name, or <code>null</code> to
- * remove a previous association.
- */
- public void setAttribute(String name, Object value) {
- if (name == null) {
- throw new IllegalArgumentException("name can not be null");
- }
- if (value != null) {
- attributes.put(name, value);
- } else {
- attributes.remove(name);
- }
- }
-
- /**
- * Stores a value in this service session. This can be used to associate
- * data with the current user so that it can be retrieved at a later point
- * from some other part of the application. Setting the value to
- * <code>null</code> clears the stored value.
- * <p>
- * The fully qualified name of the type is used as the name when storing the
- * value. The outcome of calling this method is thus the same as if calling<br />
- * <br />
- * <code>setAttribute(type.getName(), value);</code>
- *
- * @see #getAttribute(Class)
- * @see #setAttribute(String, Object)
- *
- * @param type
- * the type that the stored value represents, can not be null
- * @param value
- * the value to associate with the type, or <code>null</code> to
- * remove a previous association.
- */
- public <T> void setAttribute(Class<T> type, T value) {
- if (type == null) {
- throw new IllegalArgumentException("type can not be null");
- }
- if (value != null && !type.isInstance(value)) {
- throw new IllegalArgumentException("value of type "
- + type.getName() + " expected but got "
- + value.getClass().getName());
- }
- setAttribute(type.getName(), value);
- }
-
- /**
- * Gets a stored attribute value. If a value has been stored for the
- * session, that value is returned. If no value is stored for the name,
- * <code>null</code> is returned.
- *
- * @see #setAttribute(String, Object)
- *
- * @param name
- * the name of the value to get, can not be <code>null</code>.
- * @return the value, or <code>null</code> if no value has been stored or if
- * it has been set to null.
- */
- public Object getAttribute(String name) {
- if (name == null) {
- throw new IllegalArgumentException("name can not be null");
- }
- return attributes.get(name);
- }
-
- /**
- * Gets a stored attribute value. If a value has been stored for the
- * session, that value is returned. If no value is stored for the name,
- * <code>null</code> is returned.
- * <p>
- * The fully qualified name of the type is used as the name when getting the
- * value. The outcome of calling this method is thus the same as if calling<br />
- * <br />
- * <code>getAttribute(type.getName());</code>
- *
- * @see #setAttribute(Class, Object)
- * @see #getAttribute(String)
- *
- * @param type
- * the type of the value to get, can not be <code>null</code>.
- * @return the value, or <code>null</code> if no value has been stored or if
- * it has been set to null.
- */
- public <T> T getAttribute(Class<T> type) {
- if (type == null) {
- throw new IllegalArgumentException("type can not be null");
- }
- Object value = getAttribute(type.getName());
- if (value == null) {
- return null;
- } else {
- return type.cast(value);
- }
- }
-
- /**
- * Creates a new unique id for a UI.
- *
- * @return a unique UI id
- */
- public int getNextUIid() {
- return nextUIId++;
- }
-
- /**
- * Gets the mapping from <code>window.name</code> to UI id for UIs that are
- * should be retained on refresh.
- *
- * @see VaadinService#preserveUIOnRefresh(VaadinRequest, UI, UIProvider)
- * @see PreserveOnRefresh
- *
- * @return the mapping between window names and UI ids for this session.
- */
- public Map<String, Integer> getPreserveOnRefreshUIs() {
- return retainOnRefreshUIs;
- }
-
- /**
- * Adds an initialized UI to this session.
- *
- * @param ui
- * the initialized UI to add.
- */
- public void addUI(UI ui) {
- if (ui.getUIId() == -1) {
- throw new IllegalArgumentException(
- "Can not add an UI that has not been initialized.");
- }
- if (ui.getSession() != this) {
- throw new IllegalArgumentException(
- "The UI belongs to a different session");
- }
-
- uIs.put(Integer.valueOf(ui.getUIId()), ui);
- }
-
- /**
- * Adds a UI provider to this session.
- *
- * @param uiProvider
- * the UI provider that should be added
- */
- public void addUIProvider(UIProvider uiProvider) {
- uiProviders.addFirst(uiProvider);
- }
-
- /**
- * Removes a UI provider association from this session.
- *
- * @param uiProvider
- * the UI provider that should be removed
- */
- public void removeUIProvider(UIProvider uiProvider) {
- uiProviders.remove(uiProvider);
- }
-
- /**
- * Gets the UI providers configured for this session.
- *
- * @return an unmodifiable list of UI providers
- */
- public List<UIProvider> getUIProviders() {
- return Collections.unmodifiableList(uiProviders);
- }
-
- public VaadinService getService() {
- return service;
- }
-
- /**
- * Closes this session and discards all associated UI state. After the
- * session has been discarded, any UIs that have been left open will give an
- * Out of sync error ({@link SystemMessages#getOutOfSyncCaption()}) error
- * and a new session will be created for serving new UIs.
- * <p>
- * To avoid causing out of sync errors, you should typically redirect to
- * some other page using {@link Page#setLocation(String)} to make the
- * browser unload the invalidated UI.
- * <p>
- * This method is just a shorthand to
- * {@link VaadinService#closeSession(VaadinServiceSession)}
- *
- * @see VaadinService#closeSession(VaadinServiceSession)
- *
- */
- public void close() {
- getService().closeSession(this);
- }
-
-}
return;
}
- VaadinServiceSession vaadinSession = null;
+ VaadinSession vaadinSession = null;
try {
// If a duplicate "close application" URL is received for an
}
private void handleServiceException(VaadinServletRequest request,
- VaadinServletResponse response, VaadinServiceSession vaadinSession,
+ VaadinServletResponse response, VaadinSession vaadinSession,
Throwable e) throws IOException, ServletException {
// if this was an UIDL request, response UIDL back to client
if (getRequestType(request) == RequestType.UIDL) {
@Override
protected AbstractCommunicationManager createCommunicationManager(
- VaadinServiceSession session) {
+ VaadinSession session) {
return new CommunicationManager(session);
}
}
@Override
- public String getMainDivId(VaadinServiceSession session,
- VaadinRequest request, Class<? extends UI> uiClass) {
+ public String getMainDivId(VaadinSession session, VaadinRequest request,
+ Class<? extends UI> uiClass) {
String appId = null;
try {
URL appUrl = getServlet().getApplicationUrl(
--- /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.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.logging.Logger;
+
+import javax.portlet.PortletSession;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
+import com.vaadin.annotations.PreserveOnRefresh;
+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.ui.AbstractField;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.UI;
+import com.vaadin.util.CurrentInstance;
+import com.vaadin.util.ReflectTools;
+
+/**
+ * Contains everything that Vaadin needs to store for a specific user. This is
+ * typically stored in a {@link HttpSession} or {@link PortletSession}, but
+ * others storage mechanisms might also be used.
+ * <p>
+ * Everything inside a {@link VaadinSession} should be serializable to ensure
+ * compatibility with schemes using serialization for persisting the session
+ * data.
+ *
+ * @author Vaadin Ltd
+ * @since 7.0.0
+ */
+@SuppressWarnings("serial")
+public class VaadinSession implements HttpSessionBindingListener, Serializable {
+
+ /**
+ * The name of the parameter that is by default used in e.g. web.xml to
+ * define the name of the default {@link UI} class.
+ */
+ public static final String UI_PARAMETER = "UI";
+
+ private static final Method BOOTSTRAP_FRAGMENT_METHOD = ReflectTools
+ .findMethod(BootstrapListener.class, "modifyBootstrapFragment",
+ BootstrapFragmentResponse.class);
+ private static final Method BOOTSTRAP_PAGE_METHOD = ReflectTools
+ .findMethod(BootstrapListener.class, "modifyBootstrapPage",
+ BootstrapPageResponse.class);
+
+ private final Lock lock = new ReentrantLock();
+
+ /**
+ * Configuration for the session.
+ */
+ private DeploymentConfiguration configuration;
+
+ /**
+ * Default locale of the session.
+ */
+ private Locale locale;
+
+ /**
+ * Session wide error handler which is used by default if an error is left
+ * unhandled.
+ */
+ private Terminal.ErrorListener errorHandler = new DefaultErrorListener();
+
+ /**
+ * The converter factory that is used to provide default converters for the
+ * session.
+ */
+ private ConverterFactory converterFactory = new DefaultConverterFactory();
+
+ private LinkedList<RequestHandler> requestHandlers = new LinkedList<RequestHandler>();
+
+ private int nextUIId = 0;
+ private Map<Integer, UI> uIs = new HashMap<Integer, UI>();
+
+ private final Map<String, Integer> retainOnRefreshUIs = new HashMap<String, Integer>();
+
+ private final EventRouter eventRouter = new EventRouter();
+
+ private GlobalResourceHandler globalResourceHandler;
+
+ protected WebBrowser browser = new WebBrowser();
+
+ private AbstractCommunicationManager communicationManager;
+
+ private long totalSessionTime = 0;
+
+ private long lastRequestTime = -1;
+
+ private transient WrappedSession session;
+
+ private final Map<String, Object> attributes = new HashMap<String, Object>();
+
+ private LinkedList<UIProvider> uiProviders = new LinkedList<UIProvider>();
+
+ private VaadinService service;
+
+ /**
+ * Create a new service session tied to a Vaadin service
+ *
+ * @param service
+ * the Vaadin service for the new session
+ */
+ public VaadinSession(VaadinService service) {
+ this.service = service;
+ }
+
+ /**
+ * @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
+ // Notify the service
+ service.fireSessionDestroy(this);
+ session = null;
+ }
+
+ /**
+ * Get the web browser associated with this session.
+ *
+ * @return
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ 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 underlying session to which this service session is currently
+ * associated.
+ *
+ * @return the wrapped session for this context
+ */
+ public WrappedSession getSession() {
+ return session;
+ }
+
+ /**
+ * @return
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ public AbstractCommunicationManager getCommunicationManager() {
+ return communicationManager;
+ }
+
+ /**
+ * @param service
+ * TODO
+ * @param underlyingSession
+ * @return
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ public static VaadinSession getForSession(VaadinService service,
+ WrappedSession underlyingSession) {
+ Object attribute = underlyingSession.getAttribute(VaadinSession.class
+ .getName() + "." + service.getServiceName());
+ if (attribute instanceof VaadinSession) {
+ VaadinSession vaadinSession = (VaadinSession) attribute;
+ vaadinSession.session = underlyingSession;
+ return vaadinSession;
+ }
+
+ return null;
+ }
+
+ /**
+ *
+ * @param service
+ * TODO
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ public void removeFromSession(VaadinService service) {
+ assert (getForSession(service, session) == this);
+
+ session.setAttribute(
+ VaadinSession.class.getName() + "." + service.getServiceName(),
+ null);
+ }
+
+ /**
+ * @param session
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ public void storeInSession(VaadinService service, WrappedSession session) {
+ session.setAttribute(
+ VaadinSession.class.getName() + "." + service.getServiceName(),
+ this);
+ this.session = session;
+ }
+
+ 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;
+ }
+
+ /**
+ * Gets the configuration for this session
+ *
+ * @return the deployment configuration
+ */
+ public DeploymentConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * Gets the default locale for this session.
+ *
+ * By default this is the preferred locale of the user using the session. In
+ * most cases it is read from the browser defaults.
+ *
+ * @return the locale of this session.
+ */
+ public Locale getLocale() {
+ if (locale != null) {
+ return locale;
+ }
+ return Locale.getDefault();
+ }
+
+ /**
+ * Sets the default locale for this session.
+ *
+ * By default this is the preferred locale of the user using the
+ * application. In most cases it is read from the browser defaults.
+ *
+ * @param locale
+ * the Locale object.
+ *
+ */
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+ /**
+ * Gets the session's error handler.
+ *
+ * @return the current error handler
+ */
+ public Terminal.ErrorListener getErrorHandler() {
+ return errorHandler;
+ }
+
+ /**
+ * Sets the session error handler.
+ *
+ * @param errorHandler
+ */
+ public void setErrorHandler(Terminal.ErrorListener errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ /**
+ * Gets the {@link ConverterFactory} used to locate a suitable
+ * {@link Converter} for fields in the session.
+ *
+ * See {@link #setConverterFactory(ConverterFactory)} for more details
+ *
+ * @return The converter factory used in the session
+ */
+ public ConverterFactory getConverterFactory() {
+ return converterFactory;
+ }
+
+ /**
+ * Sets the {@link ConverterFactory} used to locate a suitable
+ * {@link Converter} for fields in the session.
+ * <p>
+ * The {@link ConverterFactory} is used to find a suitable converter when
+ * binding data to a UI component and the data type does not match the UI
+ * component type, e.g. binding a Double to a TextField (which is based on a
+ * String).
+ * </p>
+ * <p>
+ * The {@link Converter} for an individual field can be overridden using
+ * {@link AbstractField#setConverter(Converter)} and for individual property
+ * ids in a {@link Table} using
+ * {@link Table#setConverter(Object, Converter)}.
+ * </p>
+ * <p>
+ * The converter factory must never be set to null.
+ *
+ * @param converterFactory
+ * The converter factory used in the session
+ */
+ public void setConverterFactory(ConverterFactory converterFactory) {
+ this.converterFactory = converterFactory;
+ }
+
+ /**
+ * Application error is an error message defined on the application level.
+ *
+ * When an error occurs on the application level, this error message4 type
+ * should be used. This indicates that the problem is caused by the
+ * application - not by the user.
+ */
+ public class ApplicationError implements Terminal.ErrorEvent {
+ private final Throwable throwable;
+
+ public ApplicationError(Throwable throwable) {
+ this.throwable = throwable;
+ }
+
+ @Override
+ public Throwable getThrowable() {
+ return throwable;
+ }
+
+ }
+
+ /**
+ * Adds a request handler to this session. Request handlers can be added to
+ * provide responses to requests that are not handled by the default
+ * functionality of the framework.
+ * <p>
+ * Handlers are called in reverse order of addition, so the most recently
+ * added handler will be called first.
+ * </p>
+ *
+ * @param handler
+ * the request handler to add
+ *
+ * @see #removeRequestHandler(RequestHandler)
+ *
+ * @since 7.0
+ */
+ public void addRequestHandler(RequestHandler handler) {
+ requestHandlers.addFirst(handler);
+ }
+
+ /**
+ * Removes a request handler from the session.
+ *
+ * @param handler
+ * the request handler to remove
+ *
+ * @since 7.0
+ */
+ public void removeRequestHandler(RequestHandler handler) {
+ requestHandlers.remove(handler);
+ }
+
+ /**
+ * Gets the request handlers that are registered to the session. The
+ * iteration order of the returned collection is the same as the order in
+ * which the request handlers will be invoked when a request is handled.
+ *
+ * @return a collection of request handlers, with the iteration order
+ * according to the order they would be invoked
+ *
+ * @see #addRequestHandler(RequestHandler)
+ * @see #removeRequestHandler(RequestHandler)
+ *
+ * @since 7.0
+ */
+ public Collection<RequestHandler> getRequestHandlers() {
+ return Collections.unmodifiableCollection(requestHandlers);
+ }
+
+ /**
+ * Gets the currently used session. The current session is automatically
+ * defined when processing requests to the server and in threads started at
+ * a point when the current session is defined (see
+ * {@link InheritableThreadLocal}). In other cases, (e.g. from background
+ * threads started in some other way), the current session is not
+ * automatically defined.
+ *
+ * @return the current session instance if available, otherwise
+ * <code>null</code>
+ *
+ * @see #setCurrent(VaadinSession)
+ *
+ * @since 7.0
+ */
+ public static VaadinSession getCurrent() {
+ return CurrentInstance.get(VaadinSession.class);
+ }
+
+ /**
+ * Sets the thread local for the current session. This method is used by the
+ * framework to set the current session whenever a new request is processed
+ * and it is cleared when the request has been processed.
+ * <p>
+ * The application developer can also use this method to define the current
+ * session outside the normal request handling and treads started from
+ * request handling threads, e.g. when initiating custom background threads.
+ * </p>
+ *
+ * @param session
+ *
+ * @see #getCurrent()
+ * @see ThreadLocal
+ *
+ * @since 7.0
+ */
+ public static void setCurrent(VaadinSession session) {
+ CurrentInstance.setInheritable(VaadinSession.class, session);
+ }
+
+ /**
+ * Gets all the UIs of this session. This includes UIs that have been
+ * requested but not yet initialized. UIs that receive no heartbeat requests
+ * from the client are eventually removed from the session.
+ *
+ * @return a collection of UIs belonging to this application
+ *
+ * @since 7.0
+ */
+ public Collection<UI> getUIs() {
+ return Collections.unmodifiableCollection(uIs.values());
+ }
+
+ private int connectorIdSequence = 0;
+
+ /**
+ * Generate an id for the given Connector. Connectors must not call this
+ * method more than once, the first time they need an id.
+ *
+ * @param connector
+ * A connector that has not yet been assigned an id.
+ * @return A new id for the connector
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ public String createConnectorId(ClientConnector connector) {
+ return String.valueOf(connectorIdSequence++);
+ }
+
+ private static final Logger getLogger() {
+ return Logger.getLogger(VaadinSession.class.getName());
+ }
+
+ /**
+ * Returns a UI with the given id.
+ * <p>
+ * This is meant for framework internal use.
+ * </p>
+ *
+ * @param uiId
+ * The UI id
+ * @return The UI with the given id or null if not found
+ */
+ public UI getUIById(int uiId) {
+ return uIs.get(uiId);
+ }
+
+ /**
+ * Adds a listener that will be invoked when the bootstrap HTML is about to
+ * be generated. This can be used to modify the contents of the HTML that
+ * loads the Vaadin application in the browser and the HTTP headers that are
+ * included in the response serving the HTML.
+ *
+ * @see BootstrapListener#modifyBootstrapFragment(BootstrapFragmentResponse)
+ * @see BootstrapListener#modifyBootstrapPage(BootstrapPageResponse)
+ *
+ * @param listener
+ * the bootstrap listener to add
+ */
+ public void addBootstrapListener(BootstrapListener listener) {
+ eventRouter.addListener(BootstrapFragmentResponse.class, listener,
+ BOOTSTRAP_FRAGMENT_METHOD);
+ eventRouter.addListener(BootstrapPageResponse.class, listener,
+ BOOTSTRAP_PAGE_METHOD);
+ }
+
+ /**
+ * Remove a bootstrap listener that was previously added.
+ *
+ * @see #addBootstrapListener(BootstrapListener)
+ *
+ * @param listener
+ * the bootstrap listener to remove
+ */
+ public void removeBootstrapListener(BootstrapListener listener) {
+ eventRouter.removeListener(BootstrapFragmentResponse.class, listener,
+ BOOTSTRAP_FRAGMENT_METHOD);
+ eventRouter.removeListener(BootstrapPageResponse.class, listener,
+ BOOTSTRAP_PAGE_METHOD);
+ }
+
+ /**
+ * Fires a bootstrap event to all registered listeners. There are currently
+ * two supported events, both inheriting from {@link BootstrapResponse}:
+ * {@link BootstrapFragmentResponse} and {@link BootstrapPageResponse}.
+ *
+ * @param response
+ * the bootstrap response event for which listeners should be
+ * fired
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ public void modifyBootstrapResponse(BootstrapResponse response) {
+ eventRouter.fireEvent(response);
+ }
+
+ /**
+ * Removes all those UIs from the session for which {@link #isUIAlive}
+ * returns false. Cleanup events are fired for the removed UIs.
+ * <p>
+ * Called by the framework at the end of every request.
+ *
+ * @see UI.CleanupEvent
+ * @see UI.CleanupListener
+ * @see #isUIAlive(UI)
+ *
+ * @since 7.0.0
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ public void cleanupInactiveUIs() {
+ for (UI ui : new ArrayList<UI>(uIs.values())) {
+ if (!isUIAlive(ui)) {
+ cleanupUI(ui);
+ getLogger().fine(
+ "Closed UI #" + ui.getUIId() + " due to inactivity");
+ }
+ }
+ }
+
+ /**
+ * Called by the framework to remove an UI instance because it has been
+ * inactive.
+ *
+ * @param ui
+ * the UI to remove
+ *
+ * @deprecated Method is declared as public only to support
+ * {@link LegacyApplication#close()} and will be removed when
+ * LegacyApplciation support is removed.
+ */
+ @Deprecated
+ public void cleanupUI(UI ui) {
+ Integer id = Integer.valueOf(ui.getUIId());
+ uIs.remove(id);
+ retainOnRefreshUIs.values().remove(id);
+ ui.fireCleanupEvent();
+ }
+
+ /**
+ * Returns the number of seconds that must pass without a valid heartbeat or
+ * UIDL request being received from a UI before that UI is removed from the
+ * application. This is a lower bound; it might take longer to close an
+ * inactive UI. Returns a negative number if heartbeat is disabled and
+ * timeout never occurs.
+ *
+ * @see #getUidlRequestTimeout()
+ * @see #cleanupInactiveUIs()
+ * @see DeploymentConfiguration#getHeartbeatInterval()
+ *
+ * @since 7.0.0
+ *
+ * @return The heartbeat timeout in seconds or a negative number if timeout
+ * never occurs.
+ */
+ protected int getHeartbeatTimeout() {
+ // Permit three missed heartbeats before closing the UI
+ return (int) (configuration.getHeartbeatInterval() * (3.1));
+ }
+
+ /**
+ * Returns the number of seconds that must pass without a valid UIDL request
+ * being received from a UI before the UI is removed from the session, even
+ * though heartbeat requests are received. This is a lower bound; it might
+ * take longer to close an inactive UI. Returns a negative number if
+ * <p>
+ * This timeout only has effect if cleanup of inactive UIs is enabled;
+ * otherwise heartbeat requests are enough to extend UI lifetime
+ * indefinitely.
+ *
+ * @see DeploymentConfiguration#isIdleUICleanupEnabled()
+ * @see #getHeartbeatTimeout()
+ * @see #cleanupInactiveUIs()
+ *
+ * @since 7.0.0
+ *
+ * @return The UIDL request timeout in seconds, or a negative number if
+ * timeout never occurs.
+ */
+ protected int getUidlRequestTimeout() {
+ return configuration.isIdleUICleanupEnabled() ? getSession()
+ .getMaxInactiveInterval() : -1;
+ }
+
+ /**
+ * Returns whether the given UI is alive (the client-side actively
+ * communicates with the server) or whether it can be removed from the
+ * session and eventually collected.
+ *
+ * @since 7.0.0
+ *
+ * @deprecated Might be refactored or removed before 7.0.0
+ *
+ * @param ui
+ * The UI whose status to check
+ * @return true if the UI is alive, false if it could be removed.
+ *
+ * @deprecated might be refactored or removed before 7.0.0
+ */
+ @Deprecated
+ protected boolean isUIAlive(UI ui) {
+ long now = System.currentTimeMillis();
+ if (getHeartbeatTimeout() >= 0
+ && now - ui.getLastHeartbeatTime() > 1000 * getHeartbeatTimeout()) {
+ return false;
+ }
+ if (getUidlRequestTimeout() >= 0
+ && now - ui.getLastUidlRequestTime() > 1000 * getUidlRequestTimeout()) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Gets this session's global resource handler that takes care of serving
+ * connector resources that are not served by any single connector because
+ * e.g. because they are served with strong caching or because of legacy
+ * reasons.
+ *
+ * @param createOnDemand
+ * <code>true</code> if a resource handler should be initialized
+ * if there is no handler associated with this application.
+ * </code>false</code> if </code>null</code> should be returned
+ * if there is no registered handler.
+ * @return this session's global resource handler, or <code>null</code> if
+ * there is no handler and the createOnDemand parameter is
+ * <code>false</code>.
+ *
+ * @since 7.0.0
+ */
+ public GlobalResourceHandler getGlobalResourceHandler(boolean createOnDemand) {
+ if (globalResourceHandler == null && createOnDemand) {
+ globalResourceHandler = new GlobalResourceHandler();
+ addRequestHandler(globalResourceHandler);
+ }
+
+ return globalResourceHandler;
+ }
+
+ /**
+ * Gets the lock that should be used to synchronize usage of data inside
+ * this session.
+ *
+ * @return the lock that should be used for synchronization
+ */
+ public Lock getLock() {
+ return lock;
+ }
+
+ /**
+ * Stores a value in this service session. This can be used to associate
+ * data with the current user so that it can be retrieved at a later point
+ * from some other part of the application. Setting the value to
+ * <code>null</code> clears the stored value.
+ *
+ * @see #getAttribute(String)
+ *
+ * @param name
+ * the name to associate the value with, can not be
+ * <code>null</code>
+ * @param value
+ * the value to associate with the name, or <code>null</code> to
+ * remove a previous association.
+ */
+ public void setAttribute(String name, Object value) {
+ if (name == null) {
+ throw new IllegalArgumentException("name can not be null");
+ }
+ if (value != null) {
+ attributes.put(name, value);
+ } else {
+ attributes.remove(name);
+ }
+ }
+
+ /**
+ * Stores a value in this service session. This can be used to associate
+ * data with the current user so that it can be retrieved at a later point
+ * from some other part of the application. Setting the value to
+ * <code>null</code> clears the stored value.
+ * <p>
+ * The fully qualified name of the type is used as the name when storing the
+ * value. The outcome of calling this method is thus the same as if calling<br />
+ * <br />
+ * <code>setAttribute(type.getName(), value);</code>
+ *
+ * @see #getAttribute(Class)
+ * @see #setAttribute(String, Object)
+ *
+ * @param type
+ * the type that the stored value represents, can not be null
+ * @param value
+ * the value to associate with the type, or <code>null</code> to
+ * remove a previous association.
+ */
+ public <T> void setAttribute(Class<T> type, T value) {
+ if (type == null) {
+ throw new IllegalArgumentException("type can not be null");
+ }
+ if (value != null && !type.isInstance(value)) {
+ throw new IllegalArgumentException("value of type "
+ + type.getName() + " expected but got "
+ + value.getClass().getName());
+ }
+ setAttribute(type.getName(), value);
+ }
+
+ /**
+ * Gets a stored attribute value. If a value has been stored for the
+ * session, that value is returned. If no value is stored for the name,
+ * <code>null</code> is returned.
+ *
+ * @see #setAttribute(String, Object)
+ *
+ * @param name
+ * the name of the value to get, can not be <code>null</code>.
+ * @return the value, or <code>null</code> if no value has been stored or if
+ * it has been set to null.
+ */
+ public Object getAttribute(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("name can not be null");
+ }
+ return attributes.get(name);
+ }
+
+ /**
+ * Gets a stored attribute value. If a value has been stored for the
+ * session, that value is returned. If no value is stored for the name,
+ * <code>null</code> is returned.
+ * <p>
+ * The fully qualified name of the type is used as the name when getting the
+ * value. The outcome of calling this method is thus the same as if calling<br />
+ * <br />
+ * <code>getAttribute(type.getName());</code>
+ *
+ * @see #setAttribute(Class, Object)
+ * @see #getAttribute(String)
+ *
+ * @param type
+ * the type of the value to get, can not be <code>null</code>.
+ * @return the value, or <code>null</code> if no value has been stored or if
+ * it has been set to null.
+ */
+ public <T> T getAttribute(Class<T> type) {
+ if (type == null) {
+ throw new IllegalArgumentException("type can not be null");
+ }
+ Object value = getAttribute(type.getName());
+ if (value == null) {
+ return null;
+ } else {
+ return type.cast(value);
+ }
+ }
+
+ /**
+ * Creates a new unique id for a UI.
+ *
+ * @return a unique UI id
+ */
+ public int getNextUIid() {
+ return nextUIId++;
+ }
+
+ /**
+ * Gets the mapping from <code>window.name</code> to UI id for UIs that are
+ * should be retained on refresh.
+ *
+ * @see VaadinService#preserveUIOnRefresh(VaadinRequest, UI, UIProvider)
+ * @see PreserveOnRefresh
+ *
+ * @return the mapping between window names and UI ids for this session.
+ */
+ public Map<String, Integer> getPreserveOnRefreshUIs() {
+ return retainOnRefreshUIs;
+ }
+
+ /**
+ * Adds an initialized UI to this session.
+ *
+ * @param ui
+ * the initialized UI to add.
+ */
+ public void addUI(UI ui) {
+ if (ui.getUIId() == -1) {
+ throw new IllegalArgumentException(
+ "Can not add an UI that has not been initialized.");
+ }
+ if (ui.getSession() != this) {
+ throw new IllegalArgumentException(
+ "The UI belongs to a different session");
+ }
+
+ uIs.put(Integer.valueOf(ui.getUIId()), ui);
+ }
+
+ /**
+ * Adds a UI provider to this session.
+ *
+ * @param uiProvider
+ * the UI provider that should be added
+ */
+ public void addUIProvider(UIProvider uiProvider) {
+ uiProviders.addFirst(uiProvider);
+ }
+
+ /**
+ * Removes a UI provider association from this session.
+ *
+ * @param uiProvider
+ * the UI provider that should be removed
+ */
+ public void removeUIProvider(UIProvider uiProvider) {
+ uiProviders.remove(uiProvider);
+ }
+
+ /**
+ * Gets the UI providers configured for this session.
+ *
+ * @return an unmodifiable list of UI providers
+ */
+ public List<UIProvider> getUIProviders() {
+ return Collections.unmodifiableList(uiProviders);
+ }
+
+ public VaadinService getService() {
+ return service;
+ }
+
+ /**
+ * Closes this session and discards all associated UI state. After the
+ * session has been discarded, any UIs that have been left open will give an
+ * Out of sync error ({@link SystemMessages#getOutOfSyncCaption()}) error
+ * and a new session will be created for serving new UIs.
+ * <p>
+ * To avoid causing out of sync errors, you should typically redirect to
+ * some other page using {@link Page#setLocation(String)} to make the
+ * browser unload the invalidated UI.
+ * <p>
+ * This method is just a shorthand to
+ * {@link VaadinService#closeSession(VaadinSession)}
+ *
+ * @see VaadinService#closeSession(VaadinSession)
+ *
+ */
+ public void close() {
+ getService().closeSession(this);
+ }
+
+}
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.Resource;
import com.vaadin.server.Terminal;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.ComponentState;
import com.vaadin.shared.ui.ComponentStateUtil;
if (parent != null) {
return parent.getLocale();
}
- final VaadinServiceSession session = getSession();
+ final VaadinSession session = getSession();
if (session != null) {
return session.getLocale();
}
*/
protected void focus() {
if (this instanceof Focusable) {
- final VaadinServiceSession session = getSession();
+ final VaadinSession session = getSession();
if (session != null) {
getUI().setFocusedComponent((Focusable) this);
delayedFocus = false;
import com.vaadin.server.UIProvider;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.server.VaadinServlet;
import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
* <p>
* When a new UI instance is needed, typically because the user opens a URL in a
* browser window which points to e.g. {@link VaadinServlet}, all
- * {@link UIProvider}s registered to the current {@link VaadinServiceSession}
- * are queried for the UI class that should be used. The selection is by defaylt
- * based on the {@value VaadinServiceSession#UI_PARAMETER} parameter from
- * web.xml.
+ * {@link UIProvider}s registered to the current {@link VaadinSession} are
+ * queried for the UI class that should be used. The selection is by defaylt
+ * based on the {@value VaadinSession#UI_PARAMETER} parameter from web.xml.
* </p>
* <p>
* After a UI has been created by the application, it is initialized using
/**
* The application to which this UI belongs
*/
- private VaadinServiceSession session;
+ private VaadinSession session;
/**
* List of windows in this UI.
* which a request originates. A negative value indicates that the UI id has
* not yet been assigned by the Application.
*
- * @see VaadinServiceSession#getNextUIid()
+ * @see VaadinSession#getNextUIid()
*/
private int uiId = -1;
* <p>
* Getting a null value is often a problem in constructors of regular
* components and in the initializers of custom composite components. A
- * standard workaround is to use {@link VaadinServiceSession#getCurrent()}
- * to retrieve the application instance that the current request relates to.
+ * standard workaround is to use {@link VaadinSession#getCurrent()} to
+ * retrieve the application instance that the current request relates to.
* Another way is to move the problematic initialization to
* {@link #attach()}, as described in the documentation of the method.
* </p>
* @see #attach()
*/
@Override
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return session;
}
*
* @see #getSession()
*/
- public void setSession(VaadinServiceSession session) {
+ public void setSession(VaadinSession session) {
if ((session == null) == (this.session == null)) {
throw new IllegalStateException(
"VaadinServiceSession has already been set. Old session: "
}
}
- private static String getSessionDetails(VaadinServiceSession session) {
+ private static String getSessionDetails(VaadinSession session) {
if (session == null) {
return null;
} else {
* heartbeat for this UI.
*
* @see #heartbeat()
- * @see VaadinServiceSession#cleanupInactiveUIs()
+ * @see VaadinSession#cleanupInactiveUIs()
*
* @return The time the last heartbeat request occurred.
*/
import org.junit.Test;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.CustomComponent;
String basePackage, String[] ignoredPackages) throws IOException {
List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
String basePackageDirName = "/" + basePackage.replace('.', '/');
- URL location = VaadinServiceSession.class
+ URL location = VaadinSession.class
.getResource(basePackageDirName);
if (location.getProtocol().equals("file")) {
try {
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.DefaultConverterFactory;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.TextField;
public class ConverterFactory extends TestCase {
}
public void testApplicationConverterFactoryInBackgroundThread() {
- VaadinServiceSession.setCurrent(null);
- final VaadinServiceSession appWithCustomIntegerConverter = new VaadinServiceSession(
+ VaadinSession.setCurrent(null);
+ final VaadinSession appWithCustomIntegerConverter = new VaadinSession(
null);
appWithCustomIntegerConverter
.setConverterFactory(new ConverterFactory42());
TextField tf = new TextField("", "123") {
@Override
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return appWithCustomIntegerConverter;
};
};
}
public void testApplicationConverterFactoryForDetachedComponent() {
- final VaadinServiceSession appWithCustomIntegerConverter = new VaadinServiceSession(
+ final VaadinSession appWithCustomIntegerConverter = new VaadinSession(
null);
appWithCustomIntegerConverter
.setConverterFactory(new ConverterFactory42());
- VaadinServiceSession.setCurrent(appWithCustomIntegerConverter);
+ VaadinSession.setCurrent(appWithCustomIntegerConverter);
TextField tf = new TextField("", "123");
tf.setConverter(Integer.class);
}
public void testApplicationConverterFactoryForDifferentThanCurrentApplication() {
- final VaadinServiceSession fieldAppWithCustomIntegerConverter = new VaadinServiceSession(
+ final VaadinSession fieldAppWithCustomIntegerConverter = new VaadinSession(
null);
fieldAppWithCustomIntegerConverter
.setConverterFactory(new ConverterFactory42());
- VaadinServiceSession.setCurrent(new VaadinServiceSession(null));
+ VaadinSession.setCurrent(new VaadinSession(null));
TextField tf = new TextField("", "123") {
@Override
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return fieldAppWithCustomIntegerConverter;
}
};
import com.vaadin.server.CommunicationManager;
import com.vaadin.server.StreamVariable;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.UI;
import com.vaadin.ui.Upload;
@Override
protected void setUp() throws Exception {
- final VaadinServiceSession application = new VaadinServiceSession(null);
+ final VaadinSession application = new VaadinSession(null);
final UI uI = new UI() {
@Override
protected void init(VaadinRequest request) {
}
@Override
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return application;
}
};
}
private CommunicationManager createCommunicationManager() {
- return new CommunicationManager(new VaadinServiceSession(null));
+ return new CommunicationManager(new VaadinSession(null));
}
}
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.Converter.ConversionException;
import com.vaadin.data.util.converter.StringToIntegerConverter;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.tests.data.bean.Address;
import com.vaadin.tests.data.bean.Country;
import com.vaadin.tests.data.bean.Person;
}
public void testNumberDoubleConverterChange() {
- final VaadinServiceSession a = new VaadinServiceSession(null);
- VaadinServiceSession.setCurrent(a);
+ final VaadinSession a = new VaadinSession(null);
+ VaadinSession.setCurrent(a);
TextField tf = new TextField() {
@Override
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return a;
}
};
import junit.framework.TestCase;
import com.vaadin.data.util.MethodProperty;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.tests.data.bean.Address;
import com.vaadin.tests.data.bean.Country;
import com.vaadin.tests.data.bean.Person;
}
public void testDefaultNumberConversion() {
- VaadinServiceSession app = new VaadinServiceSession(null);
- VaadinServiceSession.setCurrent(app);
+ VaadinSession app = new VaadinSession(null);
+ VaadinSession.setCurrent(app);
TextField tf = new TextField();
tf.setLocale(new Locale("en", "US"));
tf.setPropertyDataSource(new MethodProperty<Integer>(paulaBean,
import com.vaadin.data.util.AbstractProperty;
import com.vaadin.data.util.converter.Converter.ConversionException;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.UI;
int numReadOnlyChanges = 0;
AbstractField field = new AbstractField() {
- final private VaadinServiceSession application = new VaadinServiceSession(
+ final private VaadinSession application = new VaadinSession(
null);
private UI uI = new UI() {
}
@Override
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return application;
}
};
@Override
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return application;
};
};
import com.vaadin.data.Property;
import com.vaadin.data.util.MethodProperty;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.tests.data.bean.Person;
import com.vaadin.ui.Label;
}
public void testIntegerDataSource() {
- VaadinServiceSession.setCurrent(new VaadinServiceSession(null));
+ VaadinSession.setCurrent(new VaadinSession(null));
Label l = new Label("Foo");
Property ds = new MethodProperty<Integer>(Person.createTestPerson1(),
"age");
import com.vaadin.server.UIClassSelectionEvent;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.UI;
public class CustomUIClassLoader extends TestCase {
* if thrown
*/
public void testWithNullClassLoader() throws Exception {
- VaadinServiceSession application = createStubApplication();
+ VaadinSession application = createStubApplication();
application.setConfiguration(createConfigurationMock());
DefaultUIProvider uiProvider = new DefaultUIProvider();
private static DeploymentConfiguration createConfigurationMock() {
Properties properties = new Properties();
- properties.put(VaadinServiceSession.UI_PARAMETER, MyUI.class.getName());
+ properties.put(VaadinSession.UI_PARAMETER, MyUI.class.getName());
return new DefaultDeploymentConfiguration(CustomUIClassLoader.class,
properties);
}
}
- private VaadinServiceSession createStubApplication() {
- return new VaadinServiceSession(null) {
+ private VaadinSession createStubApplication() {
+ return new VaadinSession(null) {
@Override
public DeploymentConfiguration getConfiguration() {
return createConfigurationMock();
import org.junit.Test;
import com.vaadin.server.LegacyApplication;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
@Test
public void addSubWindow() {
- VaadinServiceSession.setCurrent(new VaadinServiceSession(null));
+ VaadinSession.setCurrent(new VaadinSession(null));
TestApp app = new TestApp();
app.init();
Window subWindow = new Window("Sub window");
import com.vaadin.server.ClientConnector;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
public class AttachDetachWindow {
- private VaadinServiceSession testApp = new VaadinServiceSession(null);
+ private VaadinSession testApp = new VaadinSession(null);
private interface TestContainer {
public boolean attachCalled();
public TestContent getTestContent();
- public VaadinServiceSession getSession();
+ public VaadinSession getSession();
}
private class TestWindow extends Window implements TestContainer {
}
@Override
- public VaadinServiceSession getSession() {
+ public VaadinSession getSession() {
return super.getSession();
}
}
getSession(win.getTestContent().child), null);
}
- private VaadinServiceSession getSession(ClientConnector testContainer) {
+ private VaadinSession getSession(ClientConnector testContainer) {
UI ui = testContainer.getUI();
if (ui != null) {
return ui.getSession();
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
public class LabelDataSource {
private static final Object INTEGER_STRING_VALUE_DE = "1.587";
ObjectProperty<String> stringDataSource;
private ObjectProperty<Integer> integerDataSource;
- VaadinServiceSession vaadinSession;
+ VaadinSession vaadinSession;
@Before
public void setup() {
- vaadinSession = new VaadinServiceSession(null);
- VaadinServiceSession.setCurrent(vaadinSession);
+ vaadinSession = new VaadinSession(null);
+ VaadinSession.setCurrent(vaadinSession);
label = new Label();
stringDataSource = new ObjectProperty<String>(STRING_DS_VALUE);
import com.vaadin.server.UIClassSelectionEvent;
import com.vaadin.server.UIProvider;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.server.VaadinServletRequest;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.UI;
}
protected void onVaadinSessionStarted(VaadinRequest request,
- VaadinServiceSession session) throws ServiceException {
+ VaadinSession session) throws ServiceException {
try {
final Class<?> classToRun = getClassToRun();
if (UI.class.isAssignableFrom(classToRun)) {
*
* @author Vaadin Ltd.
* @since 4.0.1
- * @see com.vaadin.server.VaadinServiceSession
+ * @see com.vaadin.server.VaadinSession
* @see com.vaadin.ui.Window
* @see com.vaadin.ui.Label
*/
import com.vaadin.server.RequestHandler;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Link;
setMainWindow(main);
// This class acts both as URI handler and parameter handler
- VaadinServiceSession.getCurrent().addRequestHandler(this);
+ VaadinSession.getCurrent().addRequestHandler(this);
final VerticalLayout layout = new VerticalLayout();
final Label info = new Label("To test URI and Parameter Handlers, "
}
@Override
- public boolean handleRequest(VaadinServiceSession session,
+ public boolean handleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response) throws IOException {
context.setValue("Context not available");
relative.setValue(request.getRequestPathInfo());
final Class<?> c = Class.forName(p);
if (c.getSuperclass() != null) {
if ((c.getSuperclass()
- .equals(com.vaadin.server.VaadinServiceSession.class))) {
+ .equals(com.vaadin.server.VaadinSession.class))) {
classes.add(c);
} else if ((c.getSuperclass()
.equals(com.vaadin.ui.CustomComponent.class))) {
import java.io.File;
import com.vaadin.data.Item;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.util.SampleDirectory;
import com.vaadin.ui.Label;
// Get sample directory
final File sampleDir = SampleDirectory.getDirectory(
- VaadinServiceSession.getCurrent(), main);
+ VaadinSession.getCurrent(), main);
// populate tree's root node with example directory
if (sampleDir != null) {
populateNode(sampleDir.getAbsolutePath(), null);
import com.vaadin.data.util.FilesystemContainer;
import com.vaadin.data.util.FilesystemContainer.FileItem;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.tests.util.SampleDirectory;
import com.vaadin.ui.Component.Event;
import com.vaadin.ui.Component.Listener;
// Get sample directory
final File sampleDir = SampleDirectory.getDirectory(
- VaadinServiceSession.getCurrent(), w);
+ VaadinSession.getCurrent(), w);
// Populate tree with FilesystemContainer
final FilesystemContainer fsc = new FilesystemContainer(sampleDir, true);
filesystem.setContainerDataSource(fsc);
import com.vaadin.server.DownloadStream;
import com.vaadin.server.PaintException;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.tests.components.AbstractTestCase;
import com.vaadin.tests.integration.FlagSeResource;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.UI;
public class ThreadLocalInstances extends AbstractTestCase {
- private static final VaadinServiceSession staticInitApplication = VaadinServiceSession
+ private static final VaadinSession staticInitApplication = VaadinSession
.getCurrent();
private static final UI staticInitRoot = UI.getCurrent();
}
private void reportCurrentStatus(String phase) {
- reportStatus(phase, VaadinServiceSession.getCurrent(), UI.getCurrent());
+ reportStatus(phase, VaadinSession.getCurrent(), UI.getCurrent());
}
- private void reportStatus(String phase, VaadinServiceSession application,
+ private void reportStatus(String phase, VaadinSession application,
UI uI) {
log.log(getState(application, this) + " app in " + phase);
log.log(getState(uI, mainWindow) + " root in " + phase);
package com.vaadin.tests.components;
import com.vaadin.server.LegacyApplication;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.server.WebBrowser;
public abstract class AbstractTestCase extends LegacyApplication {
protected abstract Integer getTicketNumber();
protected WebBrowser getBrowser() {
- WebBrowser webBrowser = VaadinServiceSession.getCurrent().getBrowser();
+ WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser();
return webBrowser;
}
package com.vaadin.tests.components;
import com.vaadin.server.UIProvider;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.server.WebBrowser;
public abstract class AbstractTestUIProvider extends UIProvider {
protected abstract Integer getTicketNumber();
protected WebBrowser getBrowser() {
- WebBrowser webBrowser = VaadinServiceSession.getCurrent().getBrowser();
+ WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser();
return webBrowser;
}
}
import com.vaadin.data.Item;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.AbstractField;
}
protected void updateLocale(Locale locale) {
- VaadinServiceSession.getCurrent().setLocale(locale);
+ VaadinSession.getCurrent().setLocale(locale);
for (Component c : fields) {
removeComponent(c);
}
import com.vaadin.server.UIClassSelectionEvent;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.tests.components.AbstractTestUIProvider;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
public class UIsInMultipleTabs extends AbstractTestUIProvider {
// No cleanup -> will leak, but shouldn't matter for tests
- private static ConcurrentHashMap<VaadinServiceSession, AtomicInteger> numberOfUIsOpened = new ConcurrentHashMap<VaadinServiceSession, AtomicInteger>();
+ private static ConcurrentHashMap<VaadinSession, AtomicInteger> numberOfUIsOpened = new ConcurrentHashMap<VaadinSession, AtomicInteger>();
public static class TabUI extends UI {
@Override
protected void init(VaadinRequest request) {
- VaadinServiceSession application = VaadinServiceSession
+ VaadinSession application = VaadinSession
.getCurrent();
AtomicInteger count = numberOfUIsOpened.get(application);
if (count == null) {
package com.vaadin.tests.minitutorials.v7a1;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
@Override
public void buttonClick(ClickEvent event) {
String msg = "Running in ";
- msg += VaadinServiceSession.getCurrent().getConfiguration()
+ msg += VaadinSession.getCurrent().getConfiguration()
.isProductionMode() ? "production" : "debug";
Notification.show(msg);
}
import com.vaadin.server.RequestHandler;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Link;
MyDynamicResource res = new MyDynamicResource();
- VaadinServiceSession.getCurrent().addRequestHandler(res);
+ VaadinSession.getCurrent().addRequestHandler(res);
w.addComponent(new Link(
"Test (without Content-Disposition, should suggest generatedFile.png when saving, browser default for actual disposition)",
* stream that contains the response from the server.
*/
@Override
- public boolean handleRequest(VaadinServiceSession session,
+ public boolean handleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response) throws IOException {
String relativeUri = request.getRequestPathInfo();
// Catch the given URI that identifies the resource, otherwise let other
import com.vaadin.server.RequestHandler;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
newState();
- VaadinServiceSession.getCurrent().addRequestHandler(this);
+ VaadinSession.getCurrent().addRequestHandler(this);
}
public void newState() {
}
@Override
- public boolean handleRequest(VaadinServiceSession session,
+ public boolean handleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response) throws IOException {
Map<String, String[]> parameters = request.getParameterMap();
String[] s = parameters.get("state");
import com.vaadin.server.RequestHandler;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Label;
Link l = new Link("l", icon);
main.addComponent(l);
- VaadinServiceSession.getCurrent().addRequestHandler(this);
+ VaadinSession.getCurrent().addRequestHandler(this);
}
@Override
- public boolean handleRequest(VaadinServiceSession session,
+ public boolean handleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response) throws IOException {
String relativeUri = request.getRequestPathInfo();
import com.vaadin.server.SystemError;
import com.vaadin.server.VaadinService;
-import com.vaadin.server.VaadinServiceSession;
+import com.vaadin.server.VaadinSession;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;
* @param application
* @return file pointing to sample directory
*/
- public static File getDirectory(VaadinServiceSession application,
+ public static File getDirectory(VaadinSession application,
LegacyWindow uI) {
String errorMessage = "Access to application "
+ "context base directory failed, "