搜索

4.12. Eclipse Vert.x web 的更改

download PDF

以下部分介绍了 Eclipse Vert.x web 中的更改。

4.12.1. 将用户会话处理程序的功能组合到会话处理程序中

在较早版本的 Eclipse Vert.x 中,您必须在会话中指定 User SessionHandler 和 SessionHandler 处理程序处理程序。

为了简化这个过程,在 Eclipse Vert.x 4 中,UserSessionHandler 类已被删除,并在 SessionHandler 类中添加了其功能。在 Eclipse Vert.x 4 中,若要用于会话,您必须只指定一个处理程序。

4.12.3. Favicon 和 error 处理程序使用 Vertx 文件系统

FaviconHandlerErrorHandler 中的 create 方法已更新。您必须在创建方法中传递 Vertx 实例对象。这些方法访问文件系统。传递 Vertx 对象可确保使用"Vertx"文件系统对文件进行一致的访问。

以下示例演示了如何在 Eclipse Vert.x 3.x 版本中使用创建方法。

FaviconHandler.create();
ErrorHandler.create();

以下示例演示了如何在 Eclipse Vert.x 4 中使用创建方法。

FaviconHandler.create(vertx);
ErrorHandler.create(vertx);

4.12.4. 访问模板引擎

使用 TemplateEngine.unwrap () 方法访问模板引擎。然后,您可以将自定义和配置应用到模板。

用于获取和设置引擎配置的方法已弃用。改为使用 TemplateEngine.unwrap () 方法。

  • HandlebarsTemplateEngine.getHandlebars()
  • HandlebarsTemplateEngine.getResolvers()
  • HandlebarsTemplateEngine.setResolvers()
  • JadeTemplateEngine.getJadeConfiguration()
  • ThymeleafTemplateEngine.getThymeleafTemplateEngine()
  • ThymeleafTemplateEngine.setMode()

4.12.5. 删除了区域设置接口

io.vertx.ext.web.Locale 接口已被删除。使用 io.vertx.ext.web.LanguageHeader 接口。

4.12.6. 删除了可接受的区域设置方法

已删除 RoutingContext.acceptableLocales () 方法。使用 RoutingContext.acceptableLanguages () 方法。

4.12.7. 更新了挂载子路由器的方法

在较早版本的 Eclipse Vert.x 中,Router.mountSubRouter () 方法错误地返回 路由器。这个问题已被解决,方法现在会返回一个 Route

4.12.8. 删除了带有排除 JWT 身份验证处理的字符串的 create 方法

JWTAuthHandler.create (JWTAuth authProvider, String skip) 方法已被删除。使用 JWTAuthHandler.create (JWTAuth authProvider) 方法。

以下示例演示了如何在 Eclipse Vert.x 3.x 版本中创建 JWT 身份验证处理程序。

router
   // protect everything but "/excluded/path"
   .route().handler(JWTAuthHandler(jwtAuth, "/excluded/path")

以下示例演示了如何在 Eclipse Vert.x 4 中创建 JWT 身份验证处理程序。

router
   .route("/excluded/path").handler(/* public access to "/excluded/path" */)
   // protect everything
   .route().handler(JWTAuthHandler(jwtAuth)

4.12.9. 删除了在 OSGi 环境中使用的创建处理器方法

在 Eclipse Vert.x 4 中,GGi 环境不再被支持。StaticHandler.create (String, ClassLoader) 方法已被删除,因为此方法已在 OSGi 环境中使用。

如果您在应用程序中使用了此方法,那么在 Eclipse Vert.x 4 中,您可以将资源添加到应用程序类路径或提供文件系统中的资源。

4.12.10. 删除网桥选项类

sockjs.BridgeOptions 类已被删除。改为使用新的 sockjs.SockJSBridgeOptions 类。sockjs.SockJSBridgeOptions 类包含配置事件总线网桥所需的所有选项。

新类的行为没有改变,但数据对象类的名称已改变。

在以前的版本中,当您使用 sockjs.BridgeOptions 类来添加新网桥时,会出现许多重复的配置。新类包含所有可能的通用配置,并删除重复的配置。

4.12.11. SockJS 套接字事件总线默认不注册集群事件

默认情况下,Sock JSSocket 不再注册集群事件总线使用者。如果要使用事件总线写入套接字,您必须在 SockJSHandlerOptions 中启用 writeHandler。当您启用 writeHandler 时,事件总线使用者默认设为 local。

Router router = Router.router(vertx);
SockJSHandlerOptions options = new SockJSHandlerOptions()
  .setRegisterWriteHandler(true); // enable the event bus consumer registration
SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);
router.mountSubRouter("/myapp", sockJSHandler.socketHandler(sockJSSocket -> {
  // Retrieve the writeHandlerID and store it (For example, in a local map)
  String writeHandlerID = sockJSSocket.writeHandlerID();
}));

您可以将事件总线消费者配置为集群。

SockJSHandlerOptions options = new SockJSHandlerOptions()
  .setRegisterWriteHandler(true) // enable the event bus consumer registration
  .setLocalWriteHandler(false) // register a clustered event bus consumer

4.12.12. 添加身份验证提供程序的新方法

SessionHandler.setAuthProvider (AuthProvider) 方法已弃用。改为使用 SessionHandler.addAuthProvider () 方法。新的方法允许应用使用多个身份验证提供程序,并将会话对象链接到这些身份验证提供程序。

4.12.13. OAuth2 验证供应商创建方法需要 vertx 作为 constructor 参数

从 Eclipse Vert.x 4,OAuth2Auth.create (Vertx vertx) 方法需要 vertx 作为 constructor 参数。vertx 参数使用安全非阻塞随机数生成器来生成非保障,以确保应用程序的安全性。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.