From: Petter Holmström Date: Fri, 6 Nov 2009 08:48:58 +0000 (+0000) Subject: WIP X-Git-Tag: 6.7.0.beta1~2266^2~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b590ec6b58c36322a68d43a6d537696ec2c7e7e9;p=vaadin-framework.git WIP svn changeset:9656/svn branch:portlet_2.0 --- diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java index dfdf4e3230..20f0b1821a 100644 --- a/src/com/vaadin/Application.java +++ b/src/com/vaadin/Application.java @@ -742,8 +742,11 @@ public abstract class Application implements URIHandler, * the resource to get relative location. * @return the relative uri of the resource. */ + @Deprecated public String getRelativeLocation(ApplicationResource resource) { + // FIXME Move to ApplicationContext + // Gets the key final String key = (String) resourceKeyMap.get(resource); diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index c8ae4d108b..8c2d3eb40c 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -30,7 +30,7 @@ import javax.portlet.PortletException; import javax.portlet.PortletRequest; import javax.portlet.PortletResponse; import javax.portlet.PortletSession; -import javax.portlet.RenderMode; +import javax.portlet.PortletURL; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.ResourceRequest; @@ -303,129 +303,132 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet protected void handleRequest(PortletRequest request, PortletResponse response) throws PortletException, IOException { - // System.out.println("AbstractApplicationPortlet.handleRequest() " + - // System.currentTimeMillis()); +// System.out.println("AbstractApplicationPortlet.handleRequest() " +// + System.currentTimeMillis()); RequestType requestType = getRequestType(request); - // System.out.println(" RequestType: " + requestType); - // System.out.println(" WindowID: " + request.getWindowID()); +// System.out.println(" RequestType: " + requestType); +// System.out.println(" WindowID: " + request.getWindowID()); if (requestType == RequestType.UNKNOWN) { - System.out.println("Unknown request type"); - return; + System.err.println("Unknown request type"); } else if (requestType == RequestType.STATIC_FILE) { serveStaticResources((ResourceRequest) request, (ResourceResponse) response); - return; - } - - Application application = null; - - try { - /* Find out which application this request is related to */ - application = findApplicationInstance(request, requestType); - if (application == null) { - return; - } - if (response instanceof MimeResponse) { - application - .setResourceURLGenerator(new PortletResourceURLGenerator( - (MimeResponse) response)); - } - - /* - * Get or create an application context and an application manager - * for the session - */ - PortletApplicationContext2 applicationContext = PortletApplicationContext2 - .getApplicationContext(request.getPortletSession()); - PortletCommunicationManager applicationManager = applicationContext - .getApplicationManager(application); - - /* Update browser information from request */ - applicationContext.getBrowser().updateBrowserProperties(request); - - /* Start the newly created application */ - startApplication(request, application, applicationContext); - - /* - * Transaction starts. Call transaction listeners. Transaction end - * is called in the finally block below. - */ - applicationContext.startTransaction(application, request); - - /* Handle the request */ - if (requestType == RequestType.FILE_UPLOAD) { - applicationManager.handleFileUpload((ActionRequest) request, - (ActionResponse) response); - return; - } else if (requestType == RequestType.UIDL) { - // Handles AJAX UIDL requests - applicationManager.handleUidlRequest((ResourceRequest) request, - (ResourceResponse) response, this); - return; - } - - /* - * Removes the application if it has stopped - */ - if (!application.isRunning()) { - endApplication(request, response, application); - return; - } + } else { + Application application = null; + try { + // TODO What about PARAM_UNLOADBURST & redirectToApplication + + /* Find out which application this request is related to */ + application = findApplicationInstance(request, requestType); + if (application == null) { + return; + } + if (response instanceof MimeResponse) { + application + .setResourceURLGenerator(new PortletResourceURLGenerator( + (MimeResponse) response)); + } - /* - * Always use the main window when running inside a portlet. - */ - Window window = application.getMainWindow(); - if (window == null) { - throw new PortletException(ERROR_NO_WINDOW_FOUND); - } + /* + * Get or create an application context and an application + * manager for the session + */ + PortletApplicationContext2 applicationContext = PortletApplicationContext2 + .getApplicationContext(request.getPortletSession()); + PortletCommunicationManager applicationManager = applicationContext + .getApplicationManager(application); - /* - * Sets terminal type for the window, if not already set - */ - if (window.getTerminal() == null) { - window.setTerminal(applicationContext.getBrowser()); - } + /* Update browser information from request */ + applicationContext.getBrowser() + .updateBrowserProperties(request); - /* - * Handle parameters - */ - final Map parameters = request.getParameterMap(); - if (window != null && parameters != null) { - window.handleParameters(parameters); - } + /* Start the newly created application */ + startApplication(request, application, applicationContext); - if (requestType == RequestType.APPLICATION_RESOURCE) { - handleURI(applicationManager, window, - (ResourceRequest) request, (ResourceResponse) response); - } else if (requestType == RequestType.RENDER) { /* - * Send initial AJAX page that kickstarts the Vaadin application + * Transaction starts. Call transaction listeners. Transaction + * end is called in the finally block below. */ - writeAjaxPage((RenderRequest) request, - (RenderResponse) response, window, application); - } - } catch (final SessionExpired e) { - // TODO Figure out a better way to deal with SessionExpired - // -exceptions - System.err.println("Session has expired"); - e.printStackTrace(System.err); - } catch (final GeneralSecurityException e) { - // TODO Figure out a better way to deal with - // GeneralSecurityExceptions - System.err - .println("General security exception, should never happen"); - e.printStackTrace(System.err); - } catch (final Throwable e) { - handleServiceException(request, response, application, e); - } finally { - // Notifies transaction end - if (application != null) { - ((PortletApplicationContext2) application.getContext()) - .endTransaction(application, request); + applicationContext.startTransaction(application, request); + + /* Handle the request */ + if (requestType == RequestType.FILE_UPLOAD) { + applicationManager.handleFileUpload( + (ActionRequest) request, (ActionResponse) response); + return; + } else if (requestType == RequestType.UIDL) { + // Handles AJAX UIDL requests + applicationManager.handleUidlRequest( + (ResourceRequest) request, + (ResourceResponse) response, this); + return; + } else { + /* + * Removes the application if it has stopped + */ + if (!application.isRunning()) { + endApplication(request, response, application); + return; + } + + /* + * Always use the main window when running inside a portlet. + */ + Window window = application.getMainWindow(); + if (window == null) { + throw new PortletException(ERROR_NO_WINDOW_FOUND); + } + + /* + * Sets terminal type for the window, if not already set + */ + if (window.getTerminal() == null) { + window.setTerminal(applicationContext.getBrowser()); + } + + /* + * Handle parameters + */ + final Map parameters = request + .getParameterMap(); + if (window != null && parameters != null) { + window.handleParameters(parameters); + } + + if (requestType == RequestType.APPLICATION_RESOURCE) { + handleURI(applicationManager, window, + (ResourceRequest) request, + (ResourceResponse) response); + } else if (requestType == RequestType.RENDER) { + writeAjaxPage((RenderRequest) request, + (RenderResponse) response, window, application); + } else { + throw new IllegalStateException( + "handleRequest() without anything to do - should never happen!"); + } + } + } catch (final SessionExpired e) { + // TODO Figure out a better way to deal with SessionExpired + // -exceptions + System.err.println("Session has expired"); + e.printStackTrace(System.err); + } catch (final GeneralSecurityException e) { + // TODO Figure out a better way to deal with + // GeneralSecurityExceptions + System.err + .println("General security exception, should never happen"); + e.printStackTrace(System.err); + } catch (final Throwable e) { + handleServiceException(request, response, application, e); + } finally { + // Notifies transaction end + if (application != null) { + ((PortletApplicationContext2) application.getContext()) + .endTransaction(application, request); + } } } } @@ -549,21 +552,18 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet @Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { - // System.out.println("AbstractApplicationPortlet.processAction()"); handleRequest(request, response); } - - @RenderMode(name = "VIEW") - public void doRender(RenderRequest request, RenderResponse response) + + @Override + protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { - // System.out.println("AbstractApplicationPortlet.render()"); handleRequest(request, response); } @Override public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { - // System.out.println("AbstractApplicationPortlet.serveResource()"); handleRequest(request, response); } @@ -677,6 +677,11 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet final PortletSession session = request .getPortletSession(allowSessionCreation); + +// System.out.println("getExistingApplication: allowSessionCreation=" +// + allowSessionCreation + ", session=" + session); +// System.out.println(" - session.isNew() = " + session.isNew()); + if (session == null) { throw new SessionExpired(); } @@ -772,7 +777,14 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet page.write("vaadin.vaadinConfigurations[\"" + request.getWindowID() + "\"] = {"); - page.write("appUri: '', "); + + /* + * We need this in order to get uploads to work TODO This may cause + * weird side effects on other places where appUri is used! + */ + PortletURL appUri = response.createActionURL(); + + page.write("appUri: '" + appUri.toString() + "', "); page.write("usePortletURLs: true, "); ResourceURL uidlUrlBase = response.createResourceURL(); diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 756ea8fc8e..600c35698e 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -259,6 +259,8 @@ public abstract class AbstractCommunicationManager implements // ignored, upload requests contains only files } else { final String pid = name.split("_")[0]; + // TODO Remove debug printlns + System.out.println("Looking up upload component with PID " + pid); final Upload uploadComponent = (Upload) idPaintableMap .get(pid); if (uploadComponent == null) { @@ -316,13 +318,14 @@ public abstract class AbstractCommunicationManager implements } // Send short response to acknowledge client that request was done + /* TODO Acknowledge upload in some other way response.setContentType("text/html"); final OutputStream out = response.getOutputStream(); final PrintWriter outWriter = new PrintWriter(new BufferedWriter( new OutputStreamWriter(out, "UTF-8"))); outWriter.print("download handled"); outWriter.flush(); - out.close(); + out.close();*/ } /** @@ -342,8 +345,8 @@ public abstract class AbstractCommunicationManager implements boolean repaintAll; final OutputStream out; - repaintAll = (request.getParameter(GET_PARAM_REPAINT_ALL) != null) - || (request.getSession().isNew()); + repaintAll = (request.getParameter(GET_PARAM_REPAINT_ALL) != null); + //|| (request.getSession().isNew()); FIXME What the h*ll is this?? out = response.getOutputStream(); boolean analyzeLayouts = false; @@ -1291,7 +1294,9 @@ public abstract class AbstractCommunicationManager implements * @return the paintable Id. */ public String getPaintableId(Paintable paintable) { - + // TODO Remove debug println:s from this method + //System.out.println("getPaintableId: " + paintable + " (" + paintable.getClass().getName() + ")"); + String id = paintableIdMap.get(paintable); if (id == null) { // use testing identifier as id if set @@ -1301,6 +1306,7 @@ public abstract class AbstractCommunicationManager implements } else { id = "PID_S" + id; } + //System.out.println(" id: " + id); Paintable old = idPaintableMap.put(id, paintable); if (old != null && old != paintable) { /*