ef-labs / vertx-jersey

Run jersey in vert.x
MIT License
150 stars 47 forks source link

How to deal Web Session,How to deal templates? #71

Closed yale8848 closed 6 years ago

yale8848 commented 6 years ago

Could you give some example with how to deal session and templates? Thanks very much!

adrianluisgonzalez commented 6 years ago

Could you provide a little more detail about what you are trying to achieve?

yale8848 commented 6 years ago
  1. We can use session in Vertx-Web like this:

    SessionStore store = LocalSessionStore.create(vertx);
    SessionHandler sessionHandler = SessionHandler.create(store)
    router.route().handler(sessionHandler);

    So my question is how do this in vertx-jersey?

  2. We can use templates in Vertx-Web like this:

    TemplateEngine engine = ThymeleafTemplateEngine.create();
    TemplateHandler handler = TemplateHandler.create(engine);
    router.getWithRegex(".+\\.hbs").handler(handler);

    So how do this in vertx-jersey?

I hope you can give me some example. Thanks very much.

adrianluisgonzalez commented 6 years ago

Ok, I understand what you are asking about.

vertx-web and vertx-jersey are not exactly equivalent. The intention of vertx-jersey is to allow you to work with standard JAX-RS resources with vert.x acting as the container rather than the traditional HttpServlet (Jetty, Tomcat, etc.).

Jersey is typically used in a stateless way, session management is delegated to the container. In theory you could try to use the vertx-web SessionStore with Jersey, but you would need to recreate the SessionHandlerImpl functionality to work with HttpServerRequest rather than RoutingContext in a JAX-RS ContainerRequestFilter.

For templating, try searching for JAX-RS template and you should find plenty of examples. Here is someone using mustache.

Hope this helps.

yale8848 commented 6 years ago

Get it. Thanks you very much. 👍