jakartaee / servlet

Jakarta Servlet
https://eclipse.org/ee4j/servlet
Other
262 stars 83 forks source link

Some ServletContext getters still throw UnsupportedOperationException #470

Open pnicolucci opened 2 years ago

pnicolucci commented 2 years ago

The following Servlet 6.0 issue removed this restriction from a number of getter methods: https://github.com/jakartaee/servlet/issues/416.

However, the following getter methods still throw an UnsupportedOperationException:

  1. https://jakarta.ee/specifications/servlet/6.0/apidocs/jakarta.servlet/jakarta/servlet/servletcontext#getServletRegistration(java.lang.String)
  2. https://jakarta.ee/specifications/servlet/6.0/apidocs/jakarta.servlet/jakarta/servlet/servletcontext#getServletRegistrations()
  3. https://jakarta.ee/specifications/servlet/6.0/apidocs/jakarta.servlet/jakarta/servlet/servletcontext#getFilterRegistration(java.lang.String)
  4. https://jakarta.ee/specifications/servlet/6.0/apidocs/jakarta.servlet/jakarta/servlet/servletcontext#getFilterRegistrations()
  5. https://jakarta.ee/specifications/servlet/6.0/apidocs/jakarta.servlet/jakarta/servlet/servletcontext#getSessionCookieConfig()

In addition, the Specification document still declares the following: https://github.com/jakartaee/servlet/blob/master/spec/src/main/asciidoc/servlet-spec-body.adoc#44-configuration-methods

The following methods are provided on the ServletContext interface to enable programmatic definition of servlets, filters and the url pattern(s) that they map to. These methods can only be called during the initialization of the application either from the contexInitialized method of a ServletContextListener implementation or from the onStartup method of a ServletContainerInitializer implementation. In addition to adding servlets and filters, one can also look up an instance of a Registration object corresponding to a servlet or filter or a map of all the Registration objects for the servlets or filters. If a ServletContext is passed to the ServletContextListener’s contextInitialized method where the ServletContextListener was neither declared in web.xml or web-fragment.xml nor annotated with @WebListener then an UnsupportedOperationException MUST be thrown for all the methods defined in ServletContext for programmatic configuration of servlets, filters and listeners.

I'd like to start a discussion about cleaning up these remaining "getters" and potentially a specification document update to ensure it matches the API.

arjantijms commented 2 years ago

If I remember well those other getters were delayed to a version after EE 10, since doing dynamic registrations may need a little extra care.