Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [servlet-dev] ServletContext.getContext seems to be optional, but some TCK tests require it

Hi,

On Mon, Aug 3, 2020 at 5:46 PM Greg Wilkins <gregw@xxxxxxxxxxx> wrote

Cross context dispatch is really a huge PITA..... it has a tiny bit of usage but causes a lot of complexity and complication.  So I'd really like to start on a path to deprecate this feature and ultimately remove/replace it. 

That might certainly be a good idea. Perhaps we can already start this process for Jakarta EE 10/Servlet 6.

For now, shall I do a PR for the TCK to pass if the implementation returns null (as indicated by the javadoc), and only proceed with the test if a non-null is returned? Because of the late hour wrg to the Servlet 5 TCK this can be merged for the next version if needed, of course.

Kind regards,
Arjan




 
  

But the bigger issue is that while we have optional features, we don't have a mechanism to query if they are available or not.  In this case it is not possible to distinguish between a null return meaning there is no context vs there may be a context but the feature is not supported.    It probably would have been better to specify that UnsupportedOperation should have been thrown.

An alternative is to add an API to query a container's capabilities either on an adhoc basis or something more generic.  This could be added to the servlet-api itself, but perhaps for now just add something like that to the TCK so it can be configured to know what optional features should be tested.

cheers










On Mon, 3 Aug 2020 at 16:45, arjan tijms <arjan.tijms@xxxxxxxxx> wrote:
Hi,

ServletContext getContext(String uripath) in the type ServletContext has the following note in its javadoc:

"In a security conscious environment, the servlet container may return null for a given URL."

However, the TCK has a number of tests where the ServletContext can definitely not be null:

response.getWriter()
        .println("Before dispatch=" + System.currentTimeMillis());

ac.dispatch(
        request.getServletContext().getContext("/servlet_js_dispatchtest1_web"),
        "/DispatchTests10?testname=dispatchTest10");


Interestingly, some other tests in the TCK do explicitly take the null into account, like here:

// we expect ServletContext object that corresponds to the named URL or Null
    ServletContext context2 = context.getContext(alternateServlet);

    if ((context2 == context) || (context2 == null)) {
      passed = true;


Thoughts?

Kind regards,
Arjan
_______________________________________________
servlet-dev mailing list
servlet-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/servlet-dev


--
_______________________________________________
servlet-dev mailing list
servlet-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/servlet-dev

Back to the top