#180 Difficult to initialize ServletRunner

open
Wolfgang Fahl
None
5
2009-08-19
2008-12-28
Mark Ziesemer
No

httpunit's test cases don't appear to address this, as any configuration pointing to "web.xml" appears to come from a dynamically-generated "web.xml" file. It would seem ideal to have and use a "WebContent" directory, just as would be used by most modern Java servlet containers. It could then be assumed that the "web.xml" could be loaded from "/WEB-INF/web.xml".

The best way to provide this may be to accept a File that points to the desired context root. Since ServletRunner already provide a constructor that takes a File, assuming it points to "web.xml", it could be checked for being a directory instead. If so, use it as the context root, then look for "web.xml" under the "WEB-INF" subdirectory.

The following inconsistencies should also be considered for improvement:

new ServletRunner(new File("TestWebContent/WEB-INF/web.xml"), null) or new ServletRunner(new File("TestWebContent/WEB-INF/web.xml"), "") somewhat works, though almost in reverse of this suggestion. It appears that the server's context root is set to the grandparent of "web.xml", or in this example, "TestWebContent". However, removing the 2nd argument, new ServletRunner(new File("TestWebContent/WEB-INF/web.xml")), uses the current working directory instead.

Additionally, providing any other value to the 2nd argument (other than null or an empty string) seems to require a leading "/", or the following error is thrown:

java.lang.IllegalArgumentException: Context path TestWebContent must start with '/'

This isn't documented in the API docs, and doesn't seem to provide any useful purpose, as any such use currently resolves to the root of the working drive. It would possibly make more sense if the leading "/" were to imply a meaningful location, e.g. the current working directory or some other defined parent.

Discussion

  • Mark Ziesemer
    Mark Ziesemer
    2008-12-28

    Ignore my comments about the context path - I wasn't thinking clearly! (This is the URL context path at which requests are listened for, not the physical disk path.)

     
  • Wolfgang Fahl
    Wolfgang Fahl
    2009-08-19

    Dear Mark,

    I have moved this to the feature requests and would kindly ask you to supply a patch for this.

    Yours
    Wolfgang

     
  • Wolfgang Fahl
    Wolfgang Fahl
    2009-08-19

    • assigned_to: nobody --> wolfgang_fahl
     
  • Wolfgang Fahl
    Wolfgang Fahl
    2009-08-19

    If you have a fix for this, I would be very happy to incorporate
    it. Please include a test case or instructions for duplicating
    the problem.