]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merge commit 'a810ce'
authorJohannes Dahlström <johannesd@vaadin.com>
Mon, 11 Jun 2012 10:18:46 +0000 (13:18 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Mon, 11 Jun 2012 10:18:46 +0000 (13:18 +0300)
Conflicts:
src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java

1  2 
src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java

index 5b2be308a34e0102a0ff197bd44a15984fb449b8,2ac574c2de6e0ab946e5acd82d34e49233f0a4a8..182321e54ee29fe2a914b42dbc718a24b835bd39
@@@ -67,130 -71,6 +67,131 @@@ public abstract class AbstractApplicati
      private static final Logger logger = Logger
              .getLogger(AbstractApplicationPortlet.class.getName());
  
 +    public static class WrappedHttpAndPortletRequest extends
 +            WrappedPortletRequest {
 +
 +        public WrappedHttpAndPortletRequest(PortletRequest request,
 +                HttpServletRequest originalRequest,
 +                DeploymentConfiguration deploymentConfiguration) {
 +            super(request, deploymentConfiguration);
 +            this.originalRequest = originalRequest;
 +        }
 +
 +        private final HttpServletRequest originalRequest;
 +
 +        @Override
 +        public String getParameter(String name) {
 +            String parameter = super.getParameter(name);
 +            if (parameter == null) {
 +                parameter = originalRequest.getParameter(name);
 +            }
 +            return parameter;
 +        }
 +
 +        @Override
 +        public String getRemoteAddr() {
 +            return originalRequest.getRemoteAddr();
 +        }
 +
 +        @Override
 +        public String getHeader(String name) {
 +            String header = super.getHeader(name);
 +            if (header == null) {
 +                header = originalRequest.getHeader(name);
 +            }
 +            return header;
 +        }
 +
 +        @Override
 +        public Map<String, String[]> getParameterMap() {
 +            Map<String, String[]> parameterMap = super.getParameterMap();
 +            if (parameterMap == null) {
 +                parameterMap = originalRequest.getParameterMap();
 +            }
 +            return parameterMap;
 +        }
 +    }
 +
 +    public static class WrappedGateinRequest extends
 +            WrappedHttpAndPortletRequest {
 +        public WrappedGateinRequest(PortletRequest request,
 +                DeploymentConfiguration deploymentConfiguration) {
 +            super(request, getOriginalRequest(request), deploymentConfiguration);
 +        }
 +
 +        private static final HttpServletRequest getOriginalRequest(
 +                PortletRequest request) {
 +            try {
 +                Method getRealReq = request.getClass().getMethod(
 +                        "getRealRequest");
 +                HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq
 +                        .invoke(request);
 +                return origRequest;
 +            } catch (Exception e) {
 +                throw new IllegalStateException("GateIn request not detected",
 +                        e);
 +            }
 +        }
 +    }
 +
 +    public static class WrappedLiferayRequest extends
 +            WrappedHttpAndPortletRequest {
 +
 +        public WrappedLiferayRequest(PortletRequest request,
 +                DeploymentConfiguration deploymentConfiguration) {
 +            super(request, getOriginalRequest(request), deploymentConfiguration);
 +        }
 +
 +        @Override
 +        public String getPortalProperty(String name) {
 +            return PropsUtil.get(name);
 +        }
 +
 +        private static HttpServletRequest getOriginalRequest(
 +                PortletRequest request) {
 +            try {
 +                // httpRequest = PortalUtil.getHttpServletRequest(request);
 +                HttpServletRequest httpRequest = (HttpServletRequest) PortalClassInvoker
 +                        .invoke("com.liferay.portal.util.PortalUtil",
 +                                "getHttpServletRequest", request);
 +
 +                // httpRequest =
 +                // PortalUtil.getOriginalServletRequest(httpRequest);
 +                httpRequest = (HttpServletRequest) PortalClassInvoker.invoke(
 +                        "com.liferay.portal.util.PortalUtil",
 +                        "getOriginalServletRequest", httpRequest);
 +                return httpRequest;
 +            } catch (Exception e) {
 +                throw new IllegalStateException("Liferay request not detected",
 +                        e);
 +            }
 +        }
 +
 +    }
 +
 +    public static class AbstractApplicationPortletWrapper implements Callback {
 +
 +        private final AbstractApplicationPortlet portlet;
 +
 +        public AbstractApplicationPortletWrapper(
 +                AbstractApplicationPortlet portlet) {
 +            this.portlet = portlet;
 +        }
 +
++        @Override
 +        public void criticalNotification(WrappedRequest request,
 +                WrappedResponse response, String cap, String msg,
 +                String details, String outOfSyncURL) throws IOException {
 +            PortletRequest portletRequest = WrappedPortletRequest.cast(request)
 +                    .getPortletRequest();
 +            PortletResponse portletResponse = ((WrappedPortletResponse) response)
 +                    .getPortletResponse();
 +            portlet.criticalNotification(portletRequest,
 +                    (MimeResponse) portletResponse, cap, msg, details,
 +                    outOfSyncURL);
 +        }
 +    }
 +
      /**
       * This portlet parameter is used to add styles to the main element. E.g
       * "height:500px" generates a style="height:500px" to the main element.
  
      private boolean productionMode = false;
  
 +    private DeploymentConfiguration deploymentConfiguration = new DeploymentConfiguration() {
++        @Override
 +        public String getConfiguredWidgetset(WrappedRequest request) {
 +
 +            String widgetset = getApplicationOrSystemProperty(
 +                    PARAMETER_WIDGETSET, null);
 +
 +            if (widgetset == null) {
 +                // If no widgetset defined for the application, check the portal
 +                // property
 +                widgetset = WrappedPortletRequest.cast(request)
 +                        .getPortalProperty(PORTAL_PARAMETER_VAADIN_WIDGETSET);
 +            }
 +
 +            if (widgetset == null) {
 +                // If no widgetset defined for the portal, use the default
 +                widgetset = DEFAULT_WIDGETSET;
 +            }
 +
 +            return widgetset;
 +        }
 +
++        @Override
 +        public String getConfiguredTheme(WrappedRequest request) {
 +
 +            // is the default theme defined by the portal?
 +            String themeName = WrappedPortletRequest.cast(request)
 +                    .getPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME);
 +
 +            if (themeName == null) {
 +                // no, using the default theme defined by Vaadin
 +                themeName = DEFAULT_THEME_NAME;
 +            }
 +
 +            return themeName;
 +        }
 +
++        @Override
 +        public String getApplicationOrSystemProperty(String propertyName,
 +                String defaultValue) {
 +            return AbstractApplicationPortlet.this
 +                    .getApplicationOrSystemProperty(propertyName, defaultValue);
 +        }
 +
++        @Override
 +        public boolean isStandalone(WrappedRequest request) {
 +            return false;
 +        }
 +
 +        /*
 +         * (non-Javadoc)
 +         * 
 +         * @see
 +         * com.vaadin.terminal.DeploymentConfiguration#getStaticFileLocation
 +         * (com.vaadin.terminal.WrappedRequest)
 +         * 
 +         * Return the URL from where static files, e.g. the widgetset and the
 +         * theme, are served. In a standard configuration the VAADIN folder
 +         * inside the returned folder is what is used for widgetsets and themes.
 +         * 
 +         * @return The location of static resources (inside which there should
 +         * be a VAADIN directory). Does not end with a slash (/).
 +         */
++        @Override
 +        public String getStaticFileLocation(WrappedRequest request) {
 +            String staticFileLocation = WrappedPortletRequest.cast(request)
 +                    .getPortalProperty(
 +                            Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH);
 +            if (staticFileLocation != null) {
 +                // remove trailing slash if any
 +                while (staticFileLocation.endsWith(".")) {
 +                    staticFileLocation = staticFileLocation.substring(0,
 +                            staticFileLocation.length() - 1);
 +                }
 +                return staticFileLocation;
 +            } else {
 +                // default for Liferay
 +                return "/html";
 +            }
 +        }
 +
++        @Override
 +        public ClassLoader getClassLoader() {
 +            // Custom class loaders not currently supported in portlets (see
 +            // #8574)
 +            return null;
 +        }
 +    };
 +
      @Override
      public void init(PortletConfig config) throws PortletException {
          super.init(config);
  
                          }
                      } finally {
-                         requestTimer
-                                 .stop((AbstractWebApplicationContext) application
-                                         .getContext());
 +                        Root.setCurrentRoot(null);
 +                        Application.setCurrentApplication(null);
 +
+                         PortletSession session = request
+                                 .getPortletSession(false);
+                         if (session != null) {
+                             requestTimer.stop(getApplicationContext(session));
+                         }
                      }
                  }
              }
              this.throwable = throwable;
          }
  
++        @Override
          public Throwable getThrowable() {
              return throwable;
          }
index 905cfe7e3cf0836d47520270801f87e30e35a0d2,68089e18e031f32d842a6469f881ccf649478968..7f16f48cbe83a714851ee191401465bf989aabc0
@@@ -65,77 -64,125 +65,84 @@@ import com.vaadin.ui.Root
  public abstract class AbstractApplicationServlet extends HttpServlet implements
          Constants {
  
 +    private static class AbstractApplicationServletWrapper implements Callback {
 +
 +        private final AbstractApplicationServlet servlet;
 +
 +        public AbstractApplicationServletWrapper(
 +                AbstractApplicationServlet servlet) {
 +            this.servlet = servlet;
 +        }
 +
++        @Override
 +        public void criticalNotification(WrappedRequest request,
 +                WrappedResponse response, String cap, String msg,
 +                String details, String outOfSyncURL) throws IOException {
 +            servlet.criticalNotification(
 +                    WrappedHttpServletRequest.cast(request),
 +                    ((WrappedHttpServletResponse) response), cap, msg, details,
 +                    outOfSyncURL);
 +        }
 +    }
 +
      // TODO Move some (all?) of the constants to a separate interface (shared
      // with portlet)
  
      private static final Logger logger = Logger
              .getLogger(AbstractApplicationServlet.class.getName());
  
 -    /**
 -     * The version number of this release. For example "6.2.0". Always in the
 -     * format "major.minor.revision[.build]". The build part is optional. All of
 -     * major, minor, revision must be integers.
 -     */
 -    public static final String VERSION;
 -    /**
 -     * Major version number. For example 6 in 6.2.0.
 -     */
 -    public static final int VERSION_MAJOR;
 +    private Properties applicationProperties;
  
 -    /**
 -     * Minor version number. For example 2 in 6.2.0.
 -     */
 -    public static final int VERSION_MINOR;
 +    private boolean productionMode = false;
  
 -    /**
 -     * Version revision number. For example 0 in 6.2.0.
 -     */
 -    public static final int VERSION_REVISION;
 +    private final String resourcePath = null;
  
 -    /**
 -     * Build identifier. For example "nightly-20091123-c9963" in
 -     * 6.2.0.nightly-20091123-c9963.
 -     */
 -    public static final String VERSION_BUILD;
 +    private int resourceCacheTime = 3600;
  
 -    /* Initialize version numbers from string replaced by build-script. */
 -    static {
 -        if ("@VERSION@".equals("@" + "VERSION" + "@")) {
 -            VERSION = "9.9.9.INTERNAL-DEBUG-BUILD";
 -        } else {
 -            VERSION = "@VERSION@";
 -        }
 -        final String[] digits = VERSION.split("\\.", 4);
 -        VERSION_MAJOR = Integer.parseInt(digits[0]);
 -        VERSION_MINOR = Integer.parseInt(digits[1]);
 -        VERSION_REVISION = Integer.parseInt(digits[2]);
 -        if (digits.length == 4) {
 -            VERSION_BUILD = digits[3];
 -        } else {
 -            VERSION_BUILD = "";
 +    private DeploymentConfiguration deploymentConfiguration = new DeploymentConfiguration() {
++        @Override
 +        public String getStaticFileLocation(WrappedRequest request) {
 +            HttpServletRequest servletRequest = WrappedHttpServletRequest
 +                    .cast(request);
 +            return AbstractApplicationServlet.this
 +                    .getStaticFilesLocation(servletRequest);
          }
 -    }
  
 -    /**
 -     * If the attribute is present in the request, a html fragment will be
 -     * written instead of a whole page.
 -     * 
 -     * It is set to "true" by the {@link ApplicationPortlet} (Portlet 1.0) and
 -     * read by {@link AbstractApplicationServlet}.
 -     */
 -    public static final String REQUEST_FRAGMENT = ApplicationServlet.class
 -            .getName() + ".fragment";
 -    /**
 -     * This request attribute forces widgetsets to be loaded from under the
 -     * specified base path; e.g shared widgetset for all portlets in a portal.
 -     * 
 -     * It is set by the {@link ApplicationPortlet} (Portlet 1.0) based on
 -     * {@link Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH} and read by
 -     * {@link AbstractApplicationServlet}.
 -     */
 -    public static final String REQUEST_VAADIN_STATIC_FILE_PATH = ApplicationServlet.class
 -            .getName() + ".widgetsetPath";
 -    /**
 -     * This request attribute forces widgetset used; e.g for portlets that can
 -     * not have different widgetsets.
 -     * 
 -     * It is set by the {@link ApplicationPortlet} (Portlet 1.0) based on
 -     * {@link ApplicationPortlet.PORTLET_PARAMETER_WIDGETSET} and read by
 -     * {@link AbstractApplicationServlet}.
 -     */
 -    public static final String REQUEST_WIDGETSET = ApplicationServlet.class
 -            .getName() + ".widgetset";
 -    /**
 -     * This request attribute indicates the shared widgetset (e.g. portal-wide
 -     * default widgetset).
 -     * 
 -     * It is set by the {@link ApplicationPortlet} (Portlet 1.0) based on
 -     * {@link Constants.PORTAL_PARAMETER_VAADIN_WIDGETSET} and read by
 -     * {@link AbstractApplicationServlet}.
 -     */
 -    public static final String REQUEST_SHARED_WIDGETSET = ApplicationServlet.class
 -            .getName() + ".sharedWidgetset";
 -    /**
 -     * If set, do not load the default theme but assume that loading it is
 -     * handled e.g. by ApplicationPortlet.
 -     * 
 -     * It is set by the {@link ApplicationPortlet} (Portlet 1.0) based on
 -     * {@link Constants.PORTAL_PARAMETER_VAADIN_THEME} and read by
 -     * {@link AbstractApplicationServlet}.
 -     */
 -    public static final String REQUEST_DEFAULT_THEME = ApplicationServlet.class
 -            .getName() + ".defaultThemeUri";
 -    /**
 -     * This request attribute is used to add styles to the main element. E.g
 -     * "height:500px" generates a style="height:500px" to the main element,
 -     * useful from some embedding situations (e.g portlet include.)
 -     * 
 -     * It is typically set by the {@link ApplicationPortlet} (Portlet 1.0) based
 -     * on {@link ApplicationPortlet.PORTLET_PARAMETER_STYLE} and read by
 -     * {@link AbstractApplicationServlet}.
 -     */
 -    public static final String REQUEST_APPSTYLE = ApplicationServlet.class
 -            .getName() + ".style";
++        @Override
 +        public String getConfiguredWidgetset(WrappedRequest request) {
 +            return getApplicationOrSystemProperty(
 +                    AbstractApplicationServlet.PARAMETER_WIDGETSET,
 +                    AbstractApplicationServlet.DEFAULT_WIDGETSET);
 +        }
  
 -    private Properties applicationProperties;
++        @Override
 +        public String getConfiguredTheme(WrappedRequest request) {
 +            // Use the default
 +            return AbstractApplicationServlet.getDefaultTheme();
 +        }
  
 -    private boolean productionMode = false;
++        @Override
 +        public String getApplicationOrSystemProperty(String propertyName,
 +                String defaultValue) {
 +            return AbstractApplicationServlet.this
 +                    .getApplicationOrSystemProperty(propertyName, defaultValue);
 +        }
  
 -    private final String resourcePath = null;
++        @Override
 +        public boolean isStandalone(WrappedRequest request) {
 +            return true;
 +        }
 +
++        @Override
 +        public ClassLoader getClassLoader() {
 +            try {
 +                return AbstractApplicationServlet.this.getClassLoader();
 +            } catch (ServletException e) {
 +                throw new RuntimeException(e);
 +            }
 +        }
 +    };
  
 -    private int resourceCacheTime = 3600;
      static final String UPLOAD_URL_PREFIX = "APP/UPLOAD/";
  
      /**
                                  .onRequestEnd(request, response);
                      }
                  } finally {
-                     requestTimer
-                             .stop((AbstractWebApplicationContext) application
-                                     .getContext());
 +                    Root.setCurrentRoot(null);
 +                    Application.setCurrentApplication(null);
 +
+                     HttpSession session = request.getSession(false);
+                     if (session != null) {
+                         requestTimer.stop(getApplicationContext(session));
+                     }
                  }
              }
  
              this.throwable = throwable;
          }
  
++        @Override
          public Throwable getThrowable() {
              return throwable;
          }