From: Henri Sara Date: Thu, 4 Mar 2010 14:48:28 +0000 (+0000) Subject: #4188 PortletListener window parameter and #3921 limited GateIn support X-Git-Tag: 6.7.0.beta1~1992 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2559e674bce8306b3d9919f4e38fecd2e58b7b96;p=vaadin-framework.git #4188 PortletListener window parameter and #3921 limited GateIn support svn changeset:11646/svn branch:6.3 --- diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index 522293c00b..5c0e40b38b 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -321,8 +321,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet final PrintWriter outWriter = new PrintWriter(new BufferedWriter( new OutputStreamWriter(out, "UTF-8"))); outWriter.print("dummy page"); - outWriter.flush(); - out.close(); + outWriter.close(); } else if (requestType == RequestType.STATIC_FILE) { serveStaticResources((ResourceRequest) request, (ResourceResponse) response); @@ -390,20 +389,43 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet /* Notify listeners */ + // Finds the window within the application + Window window = null; + synchronized (application) { + if (application.isRunning()) { + switch (requestType) { + case FILE_UPLOAD: + // no window + break; + case APPLICATION_RESOURCE: + // use main window - should not need any window + window = application.getMainWindow(); + break; + default: + window = applicationManager.getApplicationWindow( + request, this, application, null); + } + // if window not found, not a problem - use null + } + } + // TODO Should this happen before or after the transaction // starts? if (request instanceof RenderRequest) { applicationContext.firePortletRenderRequest(application, - (RenderRequest) request, (RenderResponse) response); + window, (RenderRequest) request, + (RenderResponse) response); } else if (request instanceof ActionRequest) { applicationContext.firePortletActionRequest(application, - (ActionRequest) request, (ActionResponse) response); + window, (ActionRequest) request, + (ActionResponse) response); } else if (request instanceof EventRequest) { applicationContext.firePortletEventRequest(application, - (EventRequest) request, (EventResponse) response); + window, (EventRequest) request, + (EventResponse) response); } else if (request instanceof ResourceRequest) { applicationContext.firePortletResourceRequest(application, - (ResourceRequest) request, + window, (ResourceRequest) request, (ResourceResponse) response); } @@ -416,7 +438,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet // Handles AJAX UIDL requests applicationManager.handleUidlRequest( (ResourceRequest) request, - (ResourceResponse) response, this); + (ResourceResponse) response, this, window); return; } else { /* @@ -428,7 +450,8 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet } handleOtherRequest(request, response, requestType, - application, applicationContext, applicationManager); + application, window, applicationContext, + applicationManager); } } catch (final SessionExpiredException e) { // TODO Figure out a better way to deal with @@ -485,14 +508,10 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet */ private void handleOtherRequest(PortletRequest request, PortletResponse response, RequestType requestType, - Application application, + Application application, Window window, PortletApplicationContext2 applicationContext, PortletCommunicationManager applicationManager) throws PortletException, IOException, MalformedURLException { - /* - * Always use the main window when running inside a portlet. - */ - Window window = application.getMainWindow(); if (window == null) { throw new PortletException(ERROR_NO_WINDOW_FOUND); } @@ -623,6 +642,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet while ((bytesRead = data.read(buffer)) > 0) { out.write(buffer, 0, bytesRead); + // TODO this may cause problems on GateIn out.flush(); } out.close(); @@ -1360,9 +1380,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet + "\"appError\": {" + "\"caption\":" + caption + "," + "\"message\" : " + message + "," + "\"url\" : " + url + "}}, \"resources\": {}, \"locales\":[]}]"); - outWriter.flush(); outWriter.close(); - out.flush(); } /** diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 77e83838c5..8c901ba7e7 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -438,7 +438,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements return; } else if (requestType == RequestType.UIDL) { // Handles AJAX UIDL requests - applicationManager.handleUidlRequest(request, response, this); + Window window = applicationManager.getApplicationWindow( + request, this, application, null); + applicationManager.handleUidlRequest(request, response, this, + window); return; } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 2bc10b4cc0..66b3eb30ca 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -4,32 +4,6 @@ package com.vaadin.terminal.gwt.server; -import com.vaadin.Application; -import com.vaadin.Application.SystemMessages; -import com.vaadin.external.org.apache.commons.fileupload.FileItemIterator; -import com.vaadin.external.org.apache.commons.fileupload.FileItemStream; -import com.vaadin.external.org.apache.commons.fileupload.FileUpload; -import com.vaadin.external.org.apache.commons.fileupload.FileUploadException; -import com.vaadin.external.org.apache.commons.fileupload.ProgressListener; -import com.vaadin.terminal.ApplicationResource; -import com.vaadin.terminal.DownloadStream; -import com.vaadin.terminal.PaintException; -import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.Paintable; -import com.vaadin.terminal.URIHandler; -import com.vaadin.terminal.UploadStream; -import com.vaadin.terminal.VariableOwner; -import com.vaadin.terminal.Paintable.RepaintRequestEvent; -import com.vaadin.terminal.Terminal.ErrorEvent; -import com.vaadin.terminal.Terminal.ErrorListener; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout; -import com.vaadin.ui.AbstractField; -import com.vaadin.ui.Component; -import com.vaadin.ui.Upload; -import com.vaadin.ui.Window; -import com.vaadin.ui.Upload.UploadException; - import java.io.BufferedWriter; import java.io.CharArrayWriter; import java.io.IOException; @@ -66,6 +40,32 @@ import javax.portlet.PortletResponse; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; +import com.vaadin.Application; +import com.vaadin.Application.SystemMessages; +import com.vaadin.external.org.apache.commons.fileupload.FileItemIterator; +import com.vaadin.external.org.apache.commons.fileupload.FileItemStream; +import com.vaadin.external.org.apache.commons.fileupload.FileUpload; +import com.vaadin.external.org.apache.commons.fileupload.FileUploadException; +import com.vaadin.external.org.apache.commons.fileupload.ProgressListener; +import com.vaadin.terminal.ApplicationResource; +import com.vaadin.terminal.DownloadStream; +import com.vaadin.terminal.PaintException; +import com.vaadin.terminal.PaintTarget; +import com.vaadin.terminal.Paintable; +import com.vaadin.terminal.URIHandler; +import com.vaadin.terminal.UploadStream; +import com.vaadin.terminal.VariableOwner; +import com.vaadin.terminal.Paintable.RepaintRequestEvent; +import com.vaadin.terminal.Terminal.ErrorEvent; +import com.vaadin.terminal.Terminal.ErrorListener; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout; +import com.vaadin.ui.AbstractField; +import com.vaadin.ui.Component; +import com.vaadin.ui.Upload; +import com.vaadin.ui.Window; +import com.vaadin.ui.Upload.UploadException; + /** * This is a common base class for the server-side implementations of the * communication system between the client code (compiled with GWT into @@ -496,11 +496,14 @@ public abstract class AbstractCommunicationManager implements * @param request * @param response * @param callback + * @param window + * target window for the UIDL request, can be null if target not + * found * @throws IOException * @throws InvalidUIDLSecurityKeyException */ protected void doHandleUidlRequest(Request request, Response response, - Callback callback) throws IOException, + Callback callback, Window window) throws IOException, InvalidUIDLSecurityKeyException { // repaint requested or session has timed out and new one is created @@ -526,10 +529,7 @@ public abstract class AbstractCommunicationManager implements synchronized (application) { // Finds the window within the application - Window window = null; if (application.isRunning()) { - window = doGetApplicationWindow(request, callback, application, - null); // Returns if no window found if (window == null) { // This should not happen, no windows exists but @@ -586,8 +586,7 @@ public abstract class AbstractCommunicationManager implements } } - // out.flush(); - this line will cause errors when deployed on GateIn. - out.close(); + outWriter.close(); } /** @@ -941,7 +940,6 @@ public abstract class AbstractCommunicationManager implements outWriter.print("}]"); } - outWriter.flush(); outWriter.close(); } @@ -1846,7 +1844,7 @@ public abstract class AbstractCommunicationManager implements } return stream; } else { - // Resolve the prefix end inded + // Resolve the prefix end index final int index = uri.indexOf('/'); if (index > 0) { String prefix = uri.substring(0, index); diff --git a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java index 8799e37899..4e6bfbd158 100644 --- a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java @@ -238,16 +238,22 @@ public class CommunicationManager extends AbstractCommunicationManager { * * @param request * @param response + * @param applicationServlet + * @param window + * target window of the UIDL request, can be null if window not + * found * @throws IOException * @throws ServletException */ public void handleUidlRequest(HttpServletRequest request, HttpServletResponse response, - AbstractApplicationServlet applicationServlet) throws IOException, - ServletException, InvalidUIDLSecurityKeyException { + AbstractApplicationServlet applicationServlet, Window window) + throws IOException, ServletException, + InvalidUIDLSecurityKeyException { doHandleUidlRequest(new HttpServletRequestWrapper(request), new HttpServletResponseWrapper(response), - new AbstractApplicationServletWrapper(applicationServlet)); + new AbstractApplicationServletWrapper(applicationServlet), + window); } /** diff --git a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java index ab1b1da81f..a6f8d7f204 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java +++ b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java @@ -139,18 +139,18 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext { } } - public void firePortletRenderRequest(Application app, + public void firePortletRenderRequest(Application app, Window window, RenderRequest request, RenderResponse response) { Set listeners = portletListeners.get(app); if (listeners != null) { for (PortletListener l : listeners) { l.handleRenderRequest(request, new RestrictedRenderResponse( - response)); + response), window); } } } - public void firePortletActionRequest(Application app, + public void firePortletActionRequest(Application app, Window window, ActionRequest request, ActionResponse response) { String key = request.getParameter(ActionRequest.ACTION_NAME); if (eventActionDestinationMap.containsKey(key)) { @@ -172,28 +172,28 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext { Set listeners = portletListeners.get(app); if (listeners != null) { for (PortletListener l : listeners) { - l.handleActionRequest(request, response); + l.handleActionRequest(request, response, window); } } } } - public void firePortletEventRequest(Application app, EventRequest request, - EventResponse response) { + public void firePortletEventRequest(Application app, Window window, + EventRequest request, EventResponse response) { Set listeners = portletListeners.get(app); if (listeners != null) { for (PortletListener l : listeners) { - l.handleEventRequest(request, response); + l.handleEventRequest(request, response, window); } } } - public void firePortletResourceRequest(Application app, + public void firePortletResourceRequest(Application app, Window window, ResourceRequest request, ResourceResponse response) { Set listeners = portletListeners.get(app); if (listeners != null) { for (PortletListener l : listeners) { - l.handleResourceRequest(request, response); + l.handleResourceRequest(request, response, window); } } } @@ -201,16 +201,16 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext { public interface PortletListener extends Serializable { public void handleRenderRequest(RenderRequest request, - RenderResponse response); + RenderResponse response, Window window); public void handleActionRequest(ActionRequest request, - ActionResponse response); + ActionResponse response, Window window); public void handleEventRequest(EventRequest request, - EventResponse response); + EventResponse response, Window window); public void handleResourceRequest(ResourceRequest request, - ResourceResponse response); + ResourceResponse response, Window window); } /** diff --git a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java index 0a3307fbb0..7fe324b1db 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java @@ -3,6 +3,7 @@ package com.vaadin.terminal.gwt.server; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.reflect.Method; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; @@ -13,6 +14,8 @@ import javax.portlet.PortletResponse; import javax.portlet.PortletSession; import javax.portlet.ResourceRequest; import javax.portlet.ResourceResponse; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequestWrapper; import com.vaadin.Application; import com.vaadin.external.org.apache.commons.fileupload.FileItemIterator; @@ -54,7 +57,20 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { } public String getParameter(String name) { - return request.getParameter(name); + String value = request.getParameter(name); + if (value == null) { + // for GateIn portlet container simple-portal + try { + Method getRealReq = request.getClass().getMethod( + "getRealRequest"); + HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq + .invoke(request); + value = origRequest.getParameter(name); + } catch (Exception e) { + // do nothing - not on GateIn simple-portal + } + } + return value; } public String getRequestID() { @@ -209,11 +225,12 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { public void handleUidlRequest(ResourceRequest request, ResourceResponse response, - AbstractApplicationPortlet applicationPortlet) + AbstractApplicationPortlet applicationPortlet, Window window) throws InvalidUIDLSecurityKeyException, IOException { doHandleUidlRequest(new PortletRequestWrapper(request), new PortletResponseWrapper(response), - new AbstractApplicationPortletWrapper(applicationPortlet)); + new AbstractApplicationPortletWrapper(applicationPortlet), + window); } DownloadStream handleURI(Window window, ResourceRequest request, @@ -224,4 +241,29 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { new AbstractApplicationPortletWrapper(applicationPortlet)); } + /** + * Gets the existing application or creates a new one. Get a window within + * an application based on the requested URI. + * + * @param request + * the portlet Request. + * @param applicationPortlet + * @param application + * the Application to query for window. + * @param assumedWindow + * if the window has been already resolved once, this parameter + * must contain the window. + * @return Window matching the given URI or null if not found. + * @throws ServletException + * if an exception has occurred that interferes with the + * servlet's normal operation. + */ + Window getApplicationWindow(PortletRequest request, + AbstractApplicationPortlet applicationPortlet, + Application application, Window assumedWindow) { + return doGetApplicationWindow(new PortletRequestWrapper(request), + new AbstractApplicationPortletWrapper(applicationPortlet), + application, assumedWindow); + } + }