Flow: Abstract access to servlet specific resource from flow internal through VaadinService

Created on 18 Mar 2018  路  4Comments  路  Source: vaadin/flow

When flow internal components need to access technology specific resources
I want to be able to implement those logic through VaadinService
so that I'm not coupled to underlying technology

Some flow internal components needs to access servlet specific logic or resource;
to do this there are explicit casts (to VadinServletRequest, VaadinServletService, ...),
direct access to VaadinServlet or ServletHelper, etc.

If those method will be moved as abstract to VaadinService they could be
implemented on the base of the underlying technology.

Some methods that could possibly moved or added to VaadinService are:

  • resolveResource(String url); present in VaadinServlet
  • getUrlTranslation(AbstractTheme theme, String urlToTranslate); present in VaadinServlet
  • since VaadinService.getResource(String path) is mainly used to check if a resource
    exists, an hasResource(path) method could be defined; maybe in servlet environment this
    can have the logic present in VaadinServlet.resourceIsFound
  • introduce String getServicePath() method; this could be used instead of VaadinServletRequest.getServletPath().

Other refactoring suggestions are:

  • rename VaadinUriResolverFactory.toServletContextPath to VaadinUriResolverFactory.toResourcePath
    so that method is no more tighted to servlet naming and it could be overriden to by
    custom implementations of VaadinUriResolverFactory for non serlvet technology
  • use VaadinService.getResource and VaadinService.getResourceAsStream in BundleFilterInitializer
  • ServletHelper could be renamed to RequestHelper and actual ServletHelper.getContextRootRelativePath
    could replace call to VaadinServletRequest.getServletPath with VaadinService.getServicePath
    so the cast to VaadinServletRequest could be removed
Help wanted enhancement feedback

Most helpful comment

@mcollovati sure if you help us by making sure we don't drop the ball with that issue

All 4 comments

Related to #2775

If someone can give some advice on this I would be glad to try to implement it.

Most of the points listed on the issue are already done; missing changes may be

  • introduce String getServicePath() method in VaadinService; this could be used in place of VaadinServletRequest.getServletPath().
  • ServletHelper could be renamed to ServiceHelper and actual ServletHelper.getContextRootRelativePath
    could replace call to VaadinServletRequest.getServletPath with VaadinService.getServicePath so the cast to VaadinServletRequest could be removed

Maybe this issue can be closed in favor of #5565

@mcollovati sure if you help us by making sure we don't drop the ball with that issue

Was this page helpful?
0 / 5 - 0 ratings