添加第二个 UI 到 Vaadin 7 应用程序会导致问题

Adding second UI to Vaadin 7 app causes problems

我有一个 Vaadin 7 应用程序,而我最初只有一个 UI。发生了以下事情,我不介意甚至喜欢:

  1. 安装新的 WAR 文件后,当前打开该 URL 的所有浏览器选项卡都出现黑色“连接失败”或“会话已过期”错误,迫使我刷新。此外,在部署应用程序时,我经常会在右上角收到“服务器加载”错误。这个有点难以解释,但希望这是有道理的。 None 其中直接由我的代码触发,所有这些都是我从 Vaadin 获得的开箱即用的行为。
  2. 如果我在多个浏览器选项卡中登录到同一个网站(和同一个用户),然后从一个选项卡注销,我对 logout/inactivate 所有选项卡的代码都运行良好 - 它们都返回到登录屏幕,正如我将它们编码的那样。

当时我web.xml如下:

web-app id="WebApp_ID" version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>vaadinwebsite</display-name>

    <context-param>
        <description>Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>${productionMode}</param-value>
    </context-param>
    <servlet>
        <!-- <servlet-name>WmsUIServlet</servlet-name> -->
        <servlet-name>WmsServlet</servlet-name>
        <servlet-class>com.mobiwms.website.WmsServlet</servlet-class>
        <init-param>
            <param-name>UI</param-name>
            <param-value>com.mobiwms.website.WmsUI</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <!-- <servlet-name>WmsUIServlet</servlet-name> -->
        <servlet-name>WmsServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    
<!-- Uncomment if add more than one UI 
    <servlet-mapping>
        <servlet-name>Vaadintutorial</servlet-name>
        <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping>
 -->
... <!-- some other stuff-->
</web-app>

我最近添加了第二个 UI,这意味着我需要调整第一个 UI 的路径。所以我做了以下事情:

  1. 更改 web.xml 因此它使用 3.0,并在 web.xml 中注释掉 servlet 引用以便它在代码中使用 WebServlet 注释。
  2. 根据文档,将我的第一个 UI 的 url 模式从 @WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = true) 更改为 @WebServlet(urlPatterns = {"/*", "/VAADIN/*"}, name = "WmsServlet", asyncSupported = true)。所以这使得“根”应用程序成为我的主要 UI,就像我只有一个 UI 时一样。根据我上面的 web.xml 片段,我总是有一个 url 模式的“/*”。
  3. 使用 @WebServlet(urlPatterns = "/Registration/*", name = "WmsRegistrationServlet", asyncSupported = true) 添加了新的 UI 和 url 模式。

现在我遇到以下怪事:

  1. 安装新的 WAR 不强制我刷新。换句话说,我什至没有注意到我需要刷新,直到我开始做某事,此时我得到正常的黑色“通信失败”,就像正常一样。
  2. 当我在两个选项卡上登录并注销时,它肯定会使另一个选项卡中的会话无效(我看到黑色的“通信失败”错误),但它不会像以前那样返回到登录屏幕到.
  3. 我们多次看到无法加载小部件集错误。
  4. 有时候,当我们做一些事情,比如上传文件时,我们会收到黑色的“通信失败”错误。

2 UIs 和 servlet 大同小异,只是布局不同。较新的UI是一个注册UI,所以实际上只有一种形式,一种视图,非常简单。另一个是成熟的应用程序。

我在较新的应用程序(注册 UI)上尝试使用 asyncSupported = false,但没有成功。然后我注释掉了 @WebServlet(urlPatterns = "/Registration/*", name = "WmsRegistrationServlet", asyncSupported = false),因此实际上我的新 UI 无法访问。这也没有解决它。

因为我还更改了 web.xml 以便我使用 3.0(web.xml 在此之前有 2.5),我将我的两个 UI servlet 的 asyncSupport 更改为 false 所以它匹配2.5 的默认行为。这也没有解决它。

于是我再次注释掉了 Registration WebServlet 注释并将 @WebServlet(urlPatterns = {"/*", "/VAADIN/*"}, name = "WmsServlet", asyncSupported = false) 更改为 @WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = false)(因此摆脱了 VAADIN 引用)。这实际上解决了问题,现在一切都像以前一样工作。那我是不是处理2UI错了?也许我处理的“/VAADIN/*”有误?

好吧,看了好几遍documentation,我终于注意到他们提出的一个小问题:

You do not have to provide the above /VAADIN/* mapping if you serve both the widget sets and (custom and default) themes statically in the /VAADIN directory in the web application. The mapping simply allows serving them dynamically from the Vaadin JAR. Serving them statically is recommended for production environments as it is faster. If you serve the content from within the same web application, you may not have the root pattern /* for the Vaadin servlet, as then all the requests would be mapped to the servlet.

因此,一旦我将 @WebServlet(urlPatterns = {"/*", "/VAADIN/*"}, name = "WmsServlet", asyncSupported = false) 更改为 @WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = true),事情就会变得更好。因为我没有使用 VAADIN jar 文件,但是 Vaadin 的东西在我的 WAR 文件中,它被分解到一个目录(据我所知,默认设置),它实际上是静态的,因此这是有效的。

顺便说一句,我设置 asyncSupported = true 来绕过“当前链的过滤器或 servlet 不支持异步操作”。错误(我提到这个错误 here),但老实说,我不是 100% 确定我必须这样做。由于它似乎没有伤害我,所以我将其保留为“真实”。