summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-09-04 13:05:44 +0300
committerLeif Åstrand <leif@vaadin.com>2012-09-05 11:39:32 +0300
commita8f65623b64e64fbf4ccd885f1dfccf500e3dbf3 (patch)
tree66a7beddd68240777938e3ef45150bbd3a3c2d79 /server/src
parenta27c7ec9cc43f4cfd7333053903f9d8cf64812eb (diff)
downloadvaadin-framework-a8f65623b64e64fbf4ccd885f1dfccf500e3dbf3.tar.gz
vaadin-framework-a8f65623b64e64fbf4ccd885f1dfccf500e3dbf3.zip
Get current request and response instead of explicitly setting (#9402)
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/server/PortletApplicationContext2.java34
-rw-r--r--server/src/com/vaadin/server/ServletApplicationContext.java21
-rw-r--r--server/src/com/vaadin/server/VaadinPortlet.java17
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java9
-rw-r--r--server/src/com/vaadin/server/WrappedPortletResponse.java8
5 files changed, 42 insertions, 47 deletions
diff --git a/server/src/com/vaadin/server/PortletApplicationContext2.java b/server/src/com/vaadin/server/PortletApplicationContext2.java
index c883e9ddfe..3efcc91c08 100644
--- a/server/src/com/vaadin/server/PortletApplicationContext2.java
+++ b/server/src/com/vaadin/server/PortletApplicationContext2.java
@@ -60,12 +60,8 @@ public class PortletApplicationContext2 extends ApplicationContext {
protected Map<Application, Set<PortletListener>> portletListeners = new HashMap<Application, Set<PortletListener>>();
- protected transient PortletConfig portletConfig;
-
protected HashMap<String, Application> portletWindowIdToApplicationMap = new HashMap<String, Application>();
- private transient PortletResponse response;
-
private final Map<String, QName> eventActionDestinationMap = new HashMap<String, QName>();
private final Map<String, Serializable> eventActionValueMap = new HashMap<String, Serializable>();
@@ -156,12 +152,19 @@ public class PortletApplicationContext2 extends ApplicationContext {
return session;
}
- public PortletConfig getPortletConfig() {
- return portletConfig;
+ private PortletResponse getCurrentResponse() {
+ WrappedPortletResponse currentResponse = VaadinPortlet
+ .getCurrentResponse();
+ if (currentResponse != null) {
+ return currentResponse.getPortletResponse();
+ } else {
+ return null;
+ }
}
- public void setPortletConfig(PortletConfig config) {
- portletConfig = config;
+ public PortletConfig getPortletConfig() {
+ return VaadinPortlet.getCurrentResponse().getDeploymentConfiguration()
+ .getPortlet().getPortletConfig();
}
public void addPortletListener(Application app, PortletListener listener) {
@@ -255,17 +258,6 @@ public class PortletApplicationContext2 extends ApplicationContext {
}
/**
- * This is for use by {@link VaadinPortlet} only.
- *
- * TODO cleaner implementation, now "semi-static"!
- *
- * @param mimeResponse
- */
- void setResponse(PortletResponse response) {
- this.response = response;
- }
-
- /**
* Creates a new action URL.
*
* @param action
@@ -274,6 +266,7 @@ public class PortletApplicationContext2 extends ApplicationContext {
*/
public PortletURL generateActionURL(String action) {
PortletURL url = null;
+ PortletResponse response = getCurrentResponse();
if (response instanceof MimeResponse) {
url = ((MimeResponse) response).createActionURL();
url.setParameter("javax.portlet.action", action);
@@ -306,6 +299,7 @@ public class PortletApplicationContext2 extends ApplicationContext {
*/
public void sendPortletEvent(UI uI, QName name, Serializable value)
throws IllegalStateException {
+ PortletResponse response = getCurrentResponse();
if (response instanceof MimeResponse) {
String actionKey = "" + System.currentTimeMillis();
while (eventActionDestinationMap.containsKey(actionKey)) {
@@ -352,6 +346,7 @@ public class PortletApplicationContext2 extends ApplicationContext {
*/
public void setSharedRenderParameter(UI uI, String name, String value)
throws IllegalStateException {
+ PortletResponse response = getCurrentResponse();
if (response instanceof MimeResponse) {
String actionKey = "" + System.currentTimeMillis();
while (sharedParameterActionNameMap.containsKey(actionKey)) {
@@ -391,6 +386,7 @@ public class PortletApplicationContext2 extends ApplicationContext {
*/
public void setPortletMode(UI uI, PortletMode portletMode)
throws IllegalStateException, PortletModeException {
+ PortletResponse response = getCurrentResponse();
if (response instanceof MimeResponse) {
PortletURL url = ((MimeResponse) response).createRenderURL();
url.setPortletMode(portletMode);
diff --git a/server/src/com/vaadin/server/ServletApplicationContext.java b/server/src/com/vaadin/server/ServletApplicationContext.java
index 1ac4a85df3..ecf6202917 100644
--- a/server/src/com/vaadin/server/ServletApplicationContext.java
+++ b/server/src/com/vaadin/server/ServletApplicationContext.java
@@ -20,7 +20,6 @@ import java.io.File;
import java.util.Enumeration;
import java.util.HashMap;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
@@ -42,11 +41,6 @@ public class ServletApplicationContext extends ApplicationContext {
private transient boolean reinitializingSession = false;
/**
- * Stores a reference to the currentRequest. Null it not inside a request.
- */
- private transient Object currentRequest = null;
-
- /**
* Creates a new Web Application Context.
*
*/
@@ -55,18 +49,6 @@ public class ServletApplicationContext extends ApplicationContext {
}
@Override
- protected void startTransaction(Application application, Object request) {
- currentRequest = request;
- super.startTransaction(application, request);
- }
-
- @Override
- protected void endTransaction(Application application, Object request) {
- super.endTransaction(application, request);
- currentRequest = null;
- }
-
- @Override
public void valueUnbound(HttpSessionBindingEvent event) {
if (!reinitializingSession) {
// Avoid closing the application if we are only reinitializing the
@@ -102,8 +84,7 @@ public class ServletApplicationContext extends ApplicationContext {
reinitializingSession = false;
// Create a new session
- HttpSession newSession = ((HttpServletRequest) currentRequest)
- .getSession();
+ HttpSession newSession = VaadinServlet.getCurrentRequest().getSession();
// Restores all attributes (security key, reference to this context
// instance)
diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java
index 4d6d7b84f0..199b8e1fc1 100644
--- a/server/src/com/vaadin/server/VaadinPortlet.java
+++ b/server/src/com/vaadin/server/VaadinPortlet.java
@@ -293,9 +293,11 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
// TODO Can we close the application when the portlet is removed? Do we know
// when the portlet is removed?
- private DeploymentConfiguration deploymentConfiguration;
+ private PortletDeploymentConfiguration deploymentConfiguration;
private AddonContext addonContext;
+ private static ThreadLocal<WrappedPortletResponse> currentResponse = new ThreadLocal<WrappedPortletResponse>();
+
@Override
public void init(PortletConfig config) throws PortletException {
super.init(config);
@@ -324,7 +326,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
addonContext.init();
}
- protected DeploymentConfiguration createDeploymentConfiguration(
+ protected PortletDeploymentConfiguration createDeploymentConfiguration(
Properties applicationProperties) {
return new PortletDeploymentConfiguration(this, applicationProperties);
}
@@ -393,6 +395,10 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
return deploymentConfiguration.isProductionMode();
}
+ public static WrappedPortletResponse getCurrentResponse() {
+ return currentResponse.get();
+ }
+
protected void handleRequest(PortletRequest request,
PortletResponse response) throws PortletException, IOException {
RequestTimer requestTimer = new RequestTimer();
@@ -406,6 +412,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
WrappedPortletResponse wrappedResponse = new WrappedPortletResponse(
response, getDeploymentConfiguration());
+ currentResponse.set(wrappedResponse);
+
RequestType requestType = getRequestType(wrappedRequest);
if (requestType == RequestType.UNKNOWN) {
@@ -449,8 +457,6 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
*/
PortletApplicationContext2 applicationContext = getApplicationContext(request
.getPortletSession());
- applicationContext.setResponse(response);
- applicationContext.setPortletConfig(getPortletConfig());
PortletCommunicationManager applicationManager = applicationContext
.getApplicationManager(application);
@@ -604,6 +610,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
} finally {
UI.setCurrent(null);
Application.setCurrent(null);
+ currentResponse.set(null);
PortletSession session = request
.getPortletSession(false);
@@ -640,7 +647,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
}
- protected DeploymentConfiguration getDeploymentConfiguration() {
+ protected PortletDeploymentConfiguration getDeploymentConfiguration() {
return deploymentConfiguration;
}
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index a10ad965c5..078263c623 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -157,6 +157,8 @@ public class VaadinServlet extends HttpServlet implements Constants {
}
}
+ private static ThreadLocal<WrappedHttpServletRequest> currentRequest = new ThreadLocal<WrappedHttpServletRequest>();
+
// TODO Move some (all?) of the constants to a separate interface (shared
// with portlet)
@@ -261,12 +263,18 @@ public class VaadinServlet extends HttpServlet implements Constants {
service(createWrappedRequest(request), createWrappedResponse(response));
}
+ public static WrappedHttpServletRequest getCurrentRequest() {
+ return currentRequest.get();
+ }
+
private void service(WrappedHttpServletRequest request,
WrappedHttpServletResponse response) throws ServletException,
IOException {
RequestTimer requestTimer = new RequestTimer();
requestTimer.start();
+ currentRequest.set(request);
+
AbstractApplicationServletWrapper servletWrapper = new AbstractApplicationServletWrapper(
this);
@@ -417,6 +425,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
} finally {
UI.setCurrent(null);
Application.setCurrent(null);
+ currentRequest.set(null);
HttpSession session = request.getSession(false);
if (session != null) {
diff --git a/server/src/com/vaadin/server/WrappedPortletResponse.java b/server/src/com/vaadin/server/WrappedPortletResponse.java
index f84e3619d2..e3010501b6 100644
--- a/server/src/com/vaadin/server/WrappedPortletResponse.java
+++ b/server/src/com/vaadin/server/WrappedPortletResponse.java
@@ -29,6 +29,8 @@ import javax.portlet.MimeResponse;
import javax.portlet.PortletResponse;
import javax.portlet.ResourceResponse;
+import com.vaadin.server.VaadinPortlet.PortletDeploymentConfiguration;
+
/**
* Wrapper for {@link PortletResponse} and its subclasses.
*
@@ -46,7 +48,7 @@ public class WrappedPortletResponse implements WrappedResponse {
}
private final PortletResponse response;
- private DeploymentConfiguration deploymentConfiguration;
+ private PortletDeploymentConfiguration deploymentConfiguration;
/**
* Wraps a portlet response and an associated deployment configuration
@@ -57,7 +59,7 @@ public class WrappedPortletResponse implements WrappedResponse {
* the associated deployment configuration
*/
public WrappedPortletResponse(PortletResponse response,
- DeploymentConfiguration deploymentConfiguration) {
+ PortletDeploymentConfiguration deploymentConfiguration) {
this.response = response;
this.deploymentConfiguration = deploymentConfiguration;
}
@@ -114,7 +116,7 @@ public class WrappedPortletResponse implements WrappedResponse {
}
@Override
- public DeploymentConfiguration getDeploymentConfiguration() {
+ public PortletDeploymentConfiguration getDeploymentConfiguration() {
return deploymentConfiguration;
}
} \ No newline at end of file