[MGNLGROOVY-179] Groovy Classes representing Servlet or Filter are not reloaded upon scripts changed Created: 01/Apr/19  Updated: 05/Apr/19  Resolved: 02/Apr/19

Status: Closed
Project: Magnolia Groovy Module
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Viet Nguyen Assignee: Federico Grilli
Resolution: Not an issue Votes: 0
Labels: None
Remaining Estimate: 0d
Time Spent: 3h
Original Estimate: Not Specified

Attachments: PNG File change-it.png     File config.server.filters.servlets.TestServlet.yaml     PNG File running.png     XML File scripts.info.xml     PNG File test-servlet.png    
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Documentation update required:
Yes
Date of First Response:
Sprint: Foundation 7
Story Points: 1

 Description   

Reproduce steps:

  • Create a new Groovy Class for testing such as this one:
    scripts.info.xml
  • Note that we put it under correct folder structure as below:
  • Configure our servlet accordingly as below
    config.server.filters.servlets.TestServlet.yaml
  • Test the servlet that it is running fine
  • 1st try: Change the script then try again the servlet
  • The issue is the response has not been updated accordingly, it is still `Requesting /1234` after my changes.

-> Expected result is that our Groovy Class Loader will reload the classes upon scripts changed.



 Comments   
Comment by Federico Grilli [ 01/Apr/19 ]

Looks like MGNLGROOVY-68 is repeating but needs further investigation.

Comment by Federico Grilli [ 02/Apr/19 ]

viet.nguyen I think I know why this doesn't work. It is no regression and it has to do with the fact that in this case we're dealing with http filters and servlets. Those managed by Magnolia (and not by the web container) are (re-)instantiated and initialised only when some change occurs under /config/server/filters which will trigger ServletDispatchingFilter#newServletInstance and eventually ObjectManufacturer#newInstance(java.lang.Class<?>, info.magnolia.objectfactory.ParameterResolver...)
The latter checks if the current ClassFactory is an instance of ReloadableClassFactory (GroovyClassFactory is) and recompilation will happen if source is new. 

In other cases, like a model class or a component, ComponentProvider will try to re-instantiate the class anytime it is needed, for instance when the page or the app where it is used is reloaded. 
As a workaround for reinstantiating servlets and filters one can change some property in configuration (for instance, in the example above the value of property at /server/filters/servlets/TestServlet/parameters@test). 

Comment by Federico Grilli [ 02/Apr/19 ]

jlegendre/docu team: maybe worth adding explicitly to the Groovy module documentation the special case of Groovy scripts acting as Servlets and Filters. Grazie! 

Comment by Viet Nguyen [ 03/Apr/19 ]

Thanks fgrilli,

It works follow your suggestion.
Change the servlet configuration such as /server/filters/servlets/TestServlet/parameters@test=123 to a new value 1234 so that the whole filter chain to reload.

Cheers,

Comment by Julie Legendre [ 05/Apr/19 ]

cmeier & akhamis please see Federico's comment above.

Generated at Mon Feb 12 05:56:22 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.