*/
protected int getUidlRequestTimeout() {
return configuration.isIdleUICleanupEnabled() ? getContext()
- .getMaxInactiveInterval() : -1;
+ .getSession().getMaxInactiveInterval() : -1;
}
/**
checkWidgetsetVersion(request);
requestThemeName = request.getParameter("theme");
- maxInactiveInterval = request.getSessionMaxInactiveInterval();
+ maxInactiveInterval = request.getWrappedSession()
+ .getMaxInactiveInterval();
// repaint requested or session has timed out and new one is created
boolean repaintAll;
final OutputStream out;
*/
protected String getSecurityKey(WrappedRequest request) {
String seckey = null;
- seckey = (String) request
- .getSessionAttribute(ApplicationConstants.UIDL_SECURITY_TOKEN_ID);
+ WrappedSession session = request.getWrappedSession();
+ seckey = (String) session
+ .getAttribute(ApplicationConstants.UIDL_SECURITY_TOKEN_ID);
if (seckey == null) {
seckey = UUID.randomUUID().toString();
- request.setSessionAttribute(
- ApplicationConstants.UIDL_SECURITY_TOKEN_ID, seckey);
+ session.setAttribute(ApplicationConstants.UIDL_SECURITY_TOKEN_ID,
+ seckey);
}
return seckey;
// ApplicationServlet has stored the security token in the
// session; check that it matched the one sent in the UIDL
String sessId = (String) request
- .getSessionAttribute(ApplicationConstants.UIDL_SECURITY_TOKEN_ID);
+ .getWrappedSession()
+ .getAttribute(
+ ApplicationConstants.UIDL_SECURITY_TOKEN_ID);
if (sessId == null || !sessId.equals(bursts[0])) {
throw new InvalidUIDLSecurityKeyException(
private long lastRequestTime = -1;
+ private transient WrappedSession session;
+
/**
* Adds a transaction listener to this context. The transaction listener is
* called before and after each each request related to this session except
public abstract File getBaseDirectory();
/**
- * Returns the time between requests, in seconds, before this context is
- * invalidated. A negative time indicates the context should never timeout.
+ * Gets the session to which this application context is currently
+ * associated.
+ *
+ * @return the wrapped session for this context
+ */
+ public WrappedSession getSession() {
+ return session;
+ }
+
+ /**
+ * Sets the session to which this application context is currently
+ * associated.
+ *
+ * @param session
+ * the wrapped session for this context
*/
- public abstract int getMaxInactiveInterval();
+ public void setSession(WrappedSession session) {
+ this.session = session;
+ }
}
\ No newline at end of file
}
@Override
- public int getSessionMaxInactiveInterval() {
- return secondRequest.getSessionMaxInactiveInterval();
- }
-
- @Override
- public Object getSessionAttribute(String name) {
- return secondRequest.getSessionAttribute(name);
- }
-
- @Override
- public void setSessionAttribute(String name, Object attribute) {
- secondRequest.setSessionAttribute(name, attribute);
+ public WrappedSession getWrappedSession() {
+ return secondRequest.getWrappedSession();
}
@Override
protected Map<Application, Set<PortletListener>> portletListeners = new HashMap<Application, Set<PortletListener>>();
- protected transient PortletSession session;
protected transient PortletConfig portletConfig;
protected HashMap<String, Application> portletWindowIdToApplicationMap = new HashMap<String, Application>();
@Override
public File getBaseDirectory() {
+ PortletSession session = getPortletSession();
String resultPath = session.getPortletContext().getRealPath("/");
if (resultPath != null) {
return new File(resultPath);
cx = new PortletApplicationContext2();
session.setAttribute(PortletApplicationContext2.class.getName(), cx);
}
- if (cx.session == null) {
- cx.session = session;
- }
+ cx.setSession(new WrappedPortletSession(session));
return cx;
}
}
public PortletSession getPortletSession() {
+ WrappedSession wrappedSession = getSession();
+ PortletSession session = ((WrappedPortletSession) wrappedSession)
+ .getPortletSession();
return session;
}
}
}
- @Override
- public int getMaxInactiveInterval() {
- return getPortletSession().getMaxInactiveInterval();
- }
-
private Logger getLogger() {
return Logger.getLogger(PortletApplicationContext2.class.getName());
}
@SuppressWarnings("serial")
public class ServletApplicationContext extends ApplicationContext {
- protected transient HttpSession session;
private transient boolean reinitializingSession = false;
/**
}
// Update the "current session" variable
- session = newSession;
+ setSession(new WrappedHttpSession(newSession));
}
/**
*/
@Override
public File getBaseDirectory() {
- final String realPath = VaadinServlet.getResourcePath(
- session.getServletContext(), "/");
+ final String realPath = VaadinServlet.getResourcePath(getHttpSession()
+ .getServletContext(), "/");
if (realPath == null) {
return null;
}
* @return HttpSession this application context resides in.
*/
public HttpSession getHttpSession() {
- return session;
+ WrappedSession session = getSession();
+ return ((WrappedHttpSession) session).getHttpSession();
}
/**
cx = new ServletApplicationContext();
session.setAttribute(ServletApplicationContext.class.getName(), cx);
}
- if (cx.session == null) {
- cx.session = session;
- }
+ cx.setSession(new WrappedHttpSession(session));
return cx;
}
}
return mgr;
}
-
- @Override
- public int getMaxInactiveInterval() {
- return getHttpSession().getMaxInactiveInterval();
- }
}
}
@Override
- public int getSessionMaxInactiveInterval() {
- return getSession().getMaxInactiveInterval();
- }
-
- @Override
- public Object getSessionAttribute(String name) {
- return getSession().getAttribute(name);
- }
-
- @Override
- public void setSessionAttribute(String name, Object attribute) {
- getSession().setAttribute(name, attribute);
+ public WrappedSession getWrappedSession() {
+ return new WrappedHttpSession(getSession());
}
/**
--- /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 javax.servlet.http.HttpSession;
+
+/**
+ * Wrapper for {@link HttpSession}.
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class WrappedHttpSession implements WrappedSession {
+
+ private final HttpSession session;
+
+ /**
+ * Creates a new wrapped http session.
+ *
+ * @param session
+ * the http session to wrap.
+ */
+ public WrappedHttpSession(HttpSession session) {
+ this.session = session;
+ }
+
+ @Override
+ public int getMaxInactiveInterval() {
+ return session.getMaxInactiveInterval();
+ }
+
+ @Override
+ public Object getAttribute(String name) {
+ return session.getAttribute(name);
+ }
+
+ @Override
+ public void setAttribute(String name, Object value) {
+ session.setAttribute(name, value);
+ }
+
+ /**
+ * Gets the wrapped {@link HttpSession}.
+ *
+ * @return the wrapped http session
+ */
+ public HttpSession getHttpSession() {
+ return session;
+ }
+
+}
}
@Override
- public int getSessionMaxInactiveInterval() {
- return request.getPortletSession().getMaxInactiveInterval();
- }
-
- @Override
- public Object getSessionAttribute(String name) {
- return request.getPortletSession().getAttribute(name);
- }
-
- @Override
- public void setSessionAttribute(String name, Object attribute) {
- request.getPortletSession().setAttribute(name, attribute);
+ public WrappedSession getWrappedSession() {
+ return new WrappedPortletSession(request.getPortletSession());
}
/**
--- /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 javax.portlet.PortletSession;
+
+/**
+ * Wrapper for
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class WrappedPortletSession implements WrappedSession {
+
+ private final PortletSession session;
+
+ /**
+ * Creates a new wrapped portlet session.
+ *
+ * @param session
+ * the portlet session to wrap.
+ */
+ public WrappedPortletSession(PortletSession session) {
+ this.session = session;
+ }
+
+ @Override
+ public int getMaxInactiveInterval() {
+ return session.getMaxInactiveInterval();
+ }
+
+ @Override
+ public Object getAttribute(String name) {
+ return session.getAttribute(name);
+ }
+
+ @Override
+ public void setAttribute(String name, Object value) {
+ session.setAttribute(name, value);
+ }
+
+ /**
+ * Gets the wrapped {@link PortletSession}.
+ *
+ * @return the wrapped portlet session
+ */
+ public PortletSession getPortletSession() {
+ return session;
+ }
+}
* A generic request to the server, wrapping a more specific request type, e.g.
* HttpServletReqest or PortletRequest.
*
- * @since 7.0
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
*/
public interface WrappedRequest extends Serializable {
public String getRequestPathInfo();
/**
- * Returns the maximum time interval, in seconds, that the session
- * associated with this request will be kept open between client accesses.
+ * Gets the session associated with this request.
*
- * @return an integer specifying the number of seconds the session
- * associated with this request remains open between client requests
+ * @see WrappedSession
+ * @see HttpServletRequest#getSession()
+ * @see PortletRequest#getPortletSession()
*
- * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
- * @see javax.portlet.PortletSession#getMaxInactiveInterval()
+ * @return the wrapped session for this request
*/
- public int getSessionMaxInactiveInterval();
-
- /**
- * Gets an attribute from the session associated with this request.
- *
- * @param name
- * the name of the attribute
- * @return the attribute value, or <code>null</code> if the attribute is not
- * defined in the session
- *
- * @see javax.servlet.http.HttpSession#getAttribute(String)
- * @see javax.portlet.PortletSession#getAttribute(String)
- */
- public Object getSessionAttribute(String name);
-
- /**
- * Saves an attribute value in the session associated with this request.
- *
- * @param name
- * the name of the attribute
- * @param attribute
- * the attribute value
- *
- * @see javax.servlet.http.HttpSession#setAttribute(String, Object)
- * @see javax.portlet.PortletSession#setAttribute(String, Object)
- */
- public void setSessionAttribute(String name, Object attribute);
+ public WrappedSession getWrappedSession();
/**
* Returns the MIME type of the body of the request, or null if the type is
--- /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 javax.portlet.PortletSession;
+import javax.servlet.http.HttpSession;
+
+/**
+ * A generic session, wrapping a more specific session implementation, e.g.
+ * {@link HttpSession} or {@link PortletSession}.
+ *
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public interface WrappedSession {
+ /**
+ * Returns the maximum time interval, in seconds, that this session will be
+ * kept open between client accesses.
+ *
+ * @return an integer specifying the number of seconds this session remains
+ * open between client requests
+ *
+ * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
+ * @see javax.portlet.PortletSession#getMaxInactiveInterval()
+ */
+ public int getMaxInactiveInterval();
+
+ /**
+ * Gets an attribute from this session.
+ *
+ * @param name
+ * the name of the attribute
+ * @return the attribute value, or <code>null</code> if the attribute is not
+ * defined in the session
+ *
+ * @see javax.servlet.http.HttpSession#getAttribute(String)
+ * @see javax.portlet.PortletSession#getAttribute(String)
+ */
+ public Object getAttribute(String name);
+
+ /**
+ * Saves an attribute value in this session.
+ *
+ * @param name
+ * the name of the attribute
+ * @param value
+ * the attribute value
+ *
+ * @see javax.servlet.http.HttpSession#setAttribute(String, Object)
+ * @see javax.portlet.PortletSession#setAttribute(String, Object)
+ */
+ public void setAttribute(String name, Object value);
+}