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>();
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) {
ResourceResponse response, UI uI);
}
- /**
- * 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.
*
*/
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);
*/
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)) {
*/
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)) {
*/
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);
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;
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.
*
}
- @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) {
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)
// 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);
addonContext.init();
}
- protected DeploymentConfiguration createDeploymentConfiguration(
+ protected PortletDeploymentConfiguration createDeploymentConfiguration(
Properties applicationProperties) {
return new PortletDeploymentConfiguration(this, applicationProperties);
}
return deploymentConfiguration.isProductionMode();
}
+ public static WrappedPortletResponse getCurrentResponse() {
+ return currentResponse.get();
+ }
+
protected void handleRequest(PortletRequest request,
PortletResponse response) throws PortletException, IOException {
RequestTimer requestTimer = new RequestTimer();
WrappedPortletResponse wrappedResponse = new WrappedPortletResponse(
response, getDeploymentConfiguration());
+ currentResponse.set(wrappedResponse);
+
RequestType requestType = getRequestType(wrappedRequest);
if (requestType == RequestType.UNKNOWN) {
*/
PortletApplicationContext2 applicationContext = getApplicationContext(request
.getPortletSession());
- applicationContext.setResponse(response);
- applicationContext.setPortletConfig(getPortletConfig());
PortletCommunicationManager applicationManager = applicationContext
.getApplicationManager(application);
} finally {
UI.setCurrent(null);
Application.setCurrent(null);
+ currentResponse.set(null);
PortletSession session = request
.getPortletSession(false);
}
- protected DeploymentConfiguration getDeploymentConfiguration() {
+ protected PortletDeploymentConfiguration getDeploymentConfiguration() {
return deploymentConfiguration;
}
}
}
+ private static ThreadLocal<WrappedHttpServletRequest> currentRequest = new ThreadLocal<WrappedHttpServletRequest>();
+
// TODO Move some (all?) of the constants to a separate interface (shared
// with portlet)
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);
} finally {
UI.setCurrent(null);
Application.setCurrent(null);
+ currentRequest.set(null);
HttpSession session = request.getSession(false);
if (session != null) {
import javax.portlet.PortletResponse;
import javax.portlet.ResourceResponse;
+import com.vaadin.server.VaadinPortlet.PortletDeploymentConfiguration;
+
/**
* Wrapper for {@link PortletResponse} and its subclasses.
*
}
private final PortletResponse response;
- private DeploymentConfiguration deploymentConfiguration;
+ private PortletDeploymentConfiguration deploymentConfiguration;
/**
* Wraps a portlet response and an associated deployment configuration
* the associated deployment configuration
*/
public WrappedPortletResponse(PortletResponse response,
- DeploymentConfiguration deploymentConfiguration) {
+ PortletDeploymentConfiguration deploymentConfiguration) {
this.response = response;
this.deploymentConfiguration = deploymentConfiguration;
}
}
@Override
- public DeploymentConfiguration getDeploymentConfiguration() {
+ public PortletDeploymentConfiguration getDeploymentConfiguration() {
return deploymentConfiguration;
}
}
\ No newline at end of file