Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 312752 - As a user, I would like to configure Context elements for all web apps
Summary: As a user, I would like to configure Context elements for all web apps
Status: CLOSED FIXED
Alias: None
Product: Gemini.Web
Classification: RT
Component: unknown (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 1.1.0.M03-incubation   Edit
Assignee: Glyn Normington CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-13 03:53 EDT by Glyn Normington CLA
Modified: 2010-07-22 11:05 EDT (History)
2 users (show)

See Also:
glyn.normington: documentation+
glyn.normington: iplog+


Attachments
The archive contains the patch that I want to propose. (3.85 KB, patch)
2010-06-23 04:03 EDT, Violeta Georgieva CLA
no flags Details | Diff
The archive contains the patch that I want to propose. (17.88 KB, patch)
2010-07-06 02:27 EDT, Violeta Georgieva CLA
no flags Details | Diff
The archive contains the patch that I want to propose. (17.91 KB, patch)
2010-07-06 03:59 EDT, Violeta Georgieva CLA
no flags Details | Diff
User documentation (1.32 KB, text/plain)
2010-07-16 11:00 EDT, Violeta Georgieva CLA
no flags Details
Screenshot of documentation update (85.75 KB, image/png)
2010-07-21 07:39 EDT, Glyn Normington CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Glyn Normington CLA 2010-05-13 03:53:23 EDT
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html describes how standard Tomcat may be configured via $CATALINA_HOME/conf/context.xml to provide Context element information that will be loaded for all web apps. A user of the web container was trying to set "crossContext" using this approach, but couldn't find a way of providing this configuration to the Gemini web container.

Either the mechanism is too obscure and we need to document it or it fell through the cracks when the web container was written (i.e. completely rewritten for dm Server 2.0) and we need to reinstate the function (which the user could use in dm Server 1.0 via the config/servlet/context.xml file). Either way, this will require documentation.
Comment 1 Rob Harrop CLA 2010-05-13 06:08:04 EDT
In 1.0, *some* of the options worked, in particular, the crossContext and contextPath options.

In 2.0 these should be supported as well. This should be quite easy to accomplish, you'll just need to read in the context.xml file using the Tomcat digester code. This will populate a Tomcat context object for you.

In general though, supporting all the options for the Context tag will not work. One that comes to mind is support for a custom classloader, which is obviously not an option in OSGi
Comment 2 Glyn Normington CLA 2010-05-18 06:44:57 EDT
Standard Tomcat handles conf/context.xml in ContextConfig.contextConfig() which performs the following steps:
* loads conf/context.xml
* loads conf/<engine>/<host>/context.xml.default
* loads webapp's context.xml

Note that ContextConfig.contextConfig obtains conf/context.xml relative to Tomcat's base directory (see ContextConfig.getBaseDir), so ContextConfig.contextConfig is not directly applicable in Virgo (assuming Tomcat configuration files in Virgo are to reside in the config directory).
Comment 3 Violeta Georgieva CLA 2010-06-22 02:21:21 EDT
Hi,

I am also interested in this functionality and I implemented the web application part i.e.
- conf/<engine>/<host>/<web-app>.xml
- META-INF/context.xml

I will be happy to contribute the implementation if you are interested.

Probably I will be able to implement also and the global part (for all web apps)
- conf/context.xml
- conf/<engine>/<host>/context.xml.default

Thanks
Violeta
Comment 4 Glyn Normington CLA 2010-06-22 03:28:33 EDT
Hi Violeta

(In reply to comment #3)
> Hi,
> 
> I am also interested in this functionality and I implemented the web
> application part i.e.
> - conf/<engine>/<host>/<web-app>.xml
> - META-INF/context.xml
> 
> I will be happy to contribute the implementation if you are interested.

Yes, that would be very helpful. Please would you attach a patch to this bug.

> 
> Probably I will be able to implement also and the global part (for all web
> apps)
> - conf/context.xml
> - conf/<engine>/<host>/context.xml.default

That would be excellent.

> 
> Thanks
> Violeta

Regards,
Glyn
Comment 5 Glyn Normington CLA 2010-06-22 03:52:59 EDT
(In reply to comment #4)

Please read http://wiki.eclipse.org/Virgo/Community#Contributions for help with making a contribution.
Comment 6 Violeta Georgieva CLA 2010-06-23 04:03:39 EDT
Created attachment 172488 [details]
The archive contains the patch that I want to propose.

Hi,

Here is the patch that I want to propose.

Regards
Violeta
Comment 7 Glyn Normington CLA 2010-06-23 06:20:43 EDT
Thanks for those files! Some initial comments:

1. I'm concerned by the file copying. Doesn't this pollute the configuration directory which should really be under control of the user? Why is the copy necessary at all?

2. It would be great to have an integration test which validates the function and gives an example of its use.

3. It would also be great to have some unit tests since the code in Tomcat.java has expanded considerably and I suspect not many paths will be exercised by the current test suite. It would probably be necessary to break out one or more helper classes along logical boundaries and mock out any dependencies on Tomcat.

4. There were extraneous carriage returns in the files which made diffing difficult. I removed these using the shell command:

tr -d '\r' <inputfile >outputfile

It would be really helpful if you could avoid adding carriage returns in future. :-) Some Windows editors support this - not sure what the default behaviour of Eclipse is.
Comment 8 Glyn Normington CLA 2010-06-23 06:31:39 EDT
Created bug312752 branch to track this work. Captured the initial patch in commit 4feac292ffbb339d33f585f7b86a49e1997e0d8b.
Comment 9 Violeta Georgieva CLA 2010-06-23 13:44:33 EDT
Hi Glyn,

(In reply to comment #7)
> Thanks for those files! Some initial comments:
> 1. I'm concerned by the file copying. Doesn't this pollute the configuration
> directory which should really be under control of the user? Why is the copy
> necessary at all?

There are two reasons behind this implementation:
- I followed the algorithm in Tomcat's documentation: "Only if a context file does not exist for the application in the $CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase." (http://tomcat.apache.org/tomcat-6.0-doc/config/context.html)
- I want to set the config file to the StandardContext and the method parameter is path to the file (context.setConfigFile(contextXml.getAbsolutePath());). When we installing an archive I cannot set this config file if it is not copied outside of the archive.

> 2. It would be great to have an integration test which validates the function
> and gives an example of its use.
> 3. It would also be great to have some unit tests since the code in Tomcat.java
> has expanded considerably and I suspect not many paths will be exercised by the
> current test suite. It would probably be necessary to break out one or more
> helper classes along logical boundaries and mock out any dependencies on
> Tomcat.

Sure I will prepare the tests.

> 4. There were extraneous carriage returns in the files which made diffing
> difficult. I removed these using the shell command:
> tr -d '\r' <inputfile >outputfile
> It would be really helpful if you could avoid adding carriage returns in
> future. :-) Some Windows editors support this - not sure what the default
> behaviour of Eclipse is.

I'm using Windows and Eclipse and I'll take care in the future :)

Regards
Violeta
Comment 10 Glyn Normington CLA 2010-06-25 04:01:57 EDT
Thanks for the explanation. I'll look forward to the tests.
Comment 11 Violeta Georgieva CLA 2010-07-06 02:27:24 EDT
Created attachment 173496 [details]
The archive contains the patch that I want to propose.

Hi Glyn,

Here is the new patch that I prepared.
I changed a little bit the implementation and also added the missing global context.xml files functionality
- conf/context.xml
- conf/Catalina/localhost/context.xml.default
I removed copying of the web application's context.xml and now the copy is done only in case the doc base is a jar file.
I want to mention also one point in the implementation - you will see that I'm using a relative path for the global context.xml. This is because in the current Tomcat implementation it is not possible to use absolute paths regardless of the fact that in the javadoc of the setter method it is stated that the absolute paths are acceptable (ContextConfig.setDefaultContextXml(String path)). I reported a but to Tomcat and they replied that this is fixed in 7.0.x and will be proposed for fixing in 6.0.x
(https://issues.apache.org/bugzilla/show_bug.cgi?id=49551)
I also added JUnit tests and an integration test.

I hope that I removed correctly the carriage returns this time.

I'm looking forward to your comments.

Regards
Violeta
Comment 12 Violeta Georgieva CLA 2010-07-06 03:59:28 EDT
Created attachment 173508 [details]
The archive contains the patch that I want to propose.

Resources created during integration test are cleared before exit.
Excuse me for missing this.
Regards
Violeta
Comment 13 Glyn Normington CLA 2010-07-08 11:49:19 EDT
(In reply to comment #12)

Thanks for adding the tests - this patch is looking really good. I've committed and pushed your changes on the branch with just one change in a comment (incorrect apostrophe - a mistake even native English speakers make fairly frequently :-) ).

The next step is to tweak the tests to avoid test files (specifically a xml file in config/Catalina/localhost) going directly into org.eclipse.gemini.web.test rather than org.eclipse.gemini.web.test/target which is our usual convention.

I would also like to examine the code more closely. I am wondering, for example, whether some of the static methods should be instance methods with longer-lived parameters passed to a constructor. Also we have a coding convention of minimising scope, so it may be possible to change a public class to be package visibility.

I will look at this in the next few days and get back to you if there are any questions. Please don't make any of the above changes for now as I'd like to avoid working on a moving base.

Before long we should be able to merge the branch into master.
Comment 14 Glyn Normington CLA 2010-07-13 06:57:32 EDT
(In reply to comment #13)
> The next step is to tweak the tests to avoid test files (specifically a xml
> file in config/Catalina/localhost) going directly into
> org.eclipse.gemini.web.test rather than org.eclipse.gemini.web.test/target
> which is our usual convention.

I moved the generated config into target and set a system property appropriately. I had to modify TomcatConfigLocator to work around what may be an Equinox bug (see bug 319679). See commit d54f545f7e9accd456b2b94ec279217ee91bdf5c for details.

However TomcatServletContainerTests.testWarWithContextXml now fails with a HTTP 500 and I haven't had a chance to investigate further.
Comment 15 Violeta Georgieva CLA 2010-07-13 09:52:44 EDT
(In reply to comment #14)

> I moved the generated config into target and set a system property
> appropriately. I had to modify TomcatConfigLocator to work around what may be
> an Equinox bug (see bug 319679). 

Thanks

> See commit d54f545f7e9accd456b2b94ec279217ee91bdf5c for details.
> However TomcatServletContainerTests.testWarWithContextXml now fails with a 
> HTTP 500 and I haven't had a chance to investigate further.

Could you please change in the TomcatServletContainerTests.beforeClass() method, the value of the property:

+    @BeforeClass
+    public static void beforeClass() throws Exception {
+        System.setProperty("org.eclipse.gemini.web.tomcat.config.path", "target/config");
+    }

instead of "target/config", we need "target/config/tomcat-server.xml"

with this change the build on my system is successful.

Thanks
Violeta
Comment 16 Violeta Georgieva CLA 2010-07-13 10:52:15 EDT
In addition to my previous comment.
I think that we do not need this file:
org.eclipse.gemini.web.test/config/Catalina/localhost/war-with-context-xml-resources.xml
it will be generated automatically

Thanks
Violeta
Comment 17 Glyn Normington CLA 2010-07-14 05:58:41 EDT
Hi Violeta

Thanks. I've corrected the property and deleted the file (checked in accidentally - apologies).

The next problem is that ant precommit shows a findbug error which needs fixing. WebappConfigLocator.copyFile does not test the return value of mkdirs.

Please could you take a look and advise?

Regards,
Glyn
Comment 18 Violeta Georgieva CLA 2010-07-14 08:57:59 EDT
Hi Glyn,

Let's do it as follows:

OLD

    private static void copyFile(InputStream source, File destination) throws IOException {
159        destination.getParentFile().mkdirs();
           ...
    }

NEW

    private static void copyFile(InputStream source, File destination) throws IOException {
159    if (!destination.getParentFile().mkdirs()) {
160            throw new IOException("Cannot create parent directories for file " + destination.getAbsolutePath());
161        }
        ...
    }

Excuse me for missing this. I'll check the findbugs report in the future.

Thanks
Violeta
Comment 19 Glyn Normington CLA 2010-07-14 11:05:19 EDT
(In reply to comment #18)
That change made a test fail:
[junit] Testsuite: org.eclipse.gemini.web.tomcat.internal.WebappConfigLocatorTest
    [junit] Tests run: 3, Failures: 0, Errors: 1, Time elapsed: 0.067 sec
    [junit] 
    [junit] Testcase: testResolveWebappContextXml(org.eclipse.gemini.web.tomcat.internal.WebappConfigLocatorTest):	Caused an ERROR
    [junit] Cannot copy /Users/glynnormington/eclipse/gemini/org.eclipse.gemini.web.gemini-web-container/org.eclipse.gemini.web.tomcat/target/test-classes/test1.xml to /Users/glynnormington/eclipse/gemini/org.eclipse.gemini.web.gemini-web-container/org.eclipse.gemini.web.tomcat/target/test-classes/test1.xml
    [junit] org.eclipse.gemini.web.core.spi.ServletContainerException: Cannot copy /Users/glynnormington/eclipse/gemini/org.eclipse.gemini.web.gemini-web-container/org.eclipse.gemini.web.tomcat/target/test-classes/test1.xml to /Users/glynnormington/eclipse/gemini/org.eclipse.gemini.web.gemini-web-container/org.eclipse.gemini.web.tomcat/target/test-classes/test1.xml
    [junit] 	at org.eclipse.gemini.web.tomcat.internal.WebappConfigLocator.resolveWebappContextXml(WebappConfigLocator.java:120)
    [junit] 	at org.eclipse.gemini.web.tomcat.internal.WebappConfigLocatorTest.testResolveWebappContextXml(WebappConfigLocatorTest.java:147)
    [junit] Caused by: java.io.IOException: Cannot create parent directories for file '/Users/glynnormington/eclipse/gemini/org.eclipse.gemini.web.gemini-web-container/org.eclipse.gemini.web.tomcat/target/test-classes/test1.xml'
    [junit] 	at org.eclipse.gemini.web.tomcat.internal.WebappConfigLocator.copyFile(WebappConfigLocator.java:160)
    [junit] 	at org.eclipse.gemini.web.tomcat.internal.WebappConfigLocator.resolveWebappContextXml(WebappConfigLocator.java:118)

I wonder if mkdirs returns false if the directory to be created already exists? If so, it may be necessary to avoid calling mkdirs in that case so that the return code can be interpreted as failure. I'll let you decide...
Comment 20 Glyn Normington CLA 2010-07-14 11:21:12 EDT
I should have pointed out that we use org.eclipse.virgo.util.io.PathReference elsewhere for such tasks. Please take a look at it and see if you would like to use something like the following sequence:

PathReference dest = new PathReference(destination);
dest.getParent().createDirectory();

This will throw an unchecked exception if and only if there is a failure to create the parent directory.
Comment 21 Violeta Georgieva CLA 2010-07-14 13:17:48 EDT
(In reply to comment #20)
> I should have pointed out that we use org.eclipse.virgo.util.io.PathReference
> elsewhere for such tasks. Please take a look at it and see if you would like to
> use something like the following sequence:
> PathReference dest = new PathReference(destination);
> dest.getParent().createDirectory();
> This will throw an unchecked exception if and only if there is a failure to
> create the parent directory.

Hi Glyn,

I look at the PathReference and I absolutely agree with your proposal.
Let's use it.

Regards
Violeta
Comment 22 Glyn Normington CLA 2010-07-15 04:50:00 EDT
(In reply to comment #21)
> Hi Glyn,
> 
> I look at the PathReference and I absolutely agree with your proposal.
> Let's use it.
> 
> Regards
> Violeta

That fixed the problem and precommit now passes. I'm now "reverse" merging master into our branch and re-testing in preparation for merging our branch into master.
Comment 23 Glyn Normington CLA 2010-07-15 04:57:02 EDT
Hi Violeta

It occurs to me that the only documentation of the new function is in this bug. Would you be able to take a look at the existing Virgo configuration documentation [1] and propose a paragraph or two to explain the new function from a user's perspective? (If you can't do this, it will need to wait for me to get around to it.) 

Thanks,
Glyn

[1] http://www.eclipse.org/virgo/documentation/virgo-documentation-2.1.0.M02-incubation/docs/virgo-user-guide/htmlsingle/virgo-user-guide.html#configuring-tomcat
Comment 24 Glyn Normington CLA 2010-07-15 11:20:27 EDT
Hi Violeta

In preparation for merging this branch and in view of the due diligence process [1], please could you confirm that you wrote 100% of the code you contributed in this bug and that you have the right to contribute the code to Eclipse. I note that the file headers now contain the appropriate License header.

I should have confirmed this before pushing the code to Eclipse. My mistake, for which I apologise.

Thanks,
Glyn
[1] http://www.eclipse.org/legal/EclipseLegalProcessPoster.pdf
Comment 25 Violeta Georgieva CLA 2010-07-16 07:05:04 EDT
Hi Glyn,

I confirm that I wrote 100% of the patch and I have the right to contribute it to Eclipse. 

Regards
Violeta
Comment 26 Violeta Georgieva CLA 2010-07-16 11:00:02 EDT
Created attachment 174503 [details]
User documentation

Hi,

Here is the user docu that I want to propose for this functionality.

Regards
Violeta
Comment 27 Glyn Normington CLA 2010-07-21 07:15:25 EDT
(In reply to comment #26)

Hi Violeta

Thanks for that documentation which I will include in the Virgo user guide as we don't currently provide any documentation for Gemini Web other than the OSGi specification.

I made some editorial and stylistic changes which I hope you won't mind, but I wanted to check something with you. You refer to the directory:

$SERVER_HOME/config/[enginename]/[hostname]

I think it's true that the web container uses a single default engine and so [enginename]=Catalina. Do you agree?

Regards,
Glyn
Comment 28 Violeta Georgieva CLA 2010-07-21 07:26:51 EDT
(In reply to comment #27)
Hi Glyn,

> but I
> wanted to check something with you. You refer to the directory:
> $SERVER_HOME/config/[enginename]/[hostname]
> I think it's true that the web container uses a single default engine and so
> [enginename]=Catalina. Do you agree?

Yes the default name is Catalina, but you can change the name of the engine in the server.xml

instead of 
<Engine name="Catalina" defaultHost="localhost">

you can rename the engine to something else
<Engine name="MyServer" defaultHost="localhost">

because of this I did not specify it as "Catalina" in the documentation.

Regards
Violeta
Comment 29 Glyn Normington CLA 2010-07-21 07:39:25 EDT
Created attachment 174832 [details]
Screenshot of documentation update
Comment 30 Glyn Normington CLA 2010-07-21 07:41:58 EDT
(In reply to comment #28)

Thanks Violeta - I had missed that. Please would you review the attached screenshot [1] of the updated documentation and see if you are happy with it.

(I have added you to the list of authors and I am investigating if the copyright needs tweaking.)

Regards,
Glyn

[1] https://bugs.eclipse.org/bugs/attachment.cgi?id=174832
Comment 31 Violeta Georgieva CLA 2010-07-21 09:12:36 EDT
> screenshot [1] of the updated documentation and see if you are happy with it.

I'm happy with it ;)

Regards
Violeta
Comment 32 Glyn Normington CLA 2010-07-21 09:58:52 EDT
Code merged into master by 002e9724e9fba7cd4484cb5c260d2fde6ea8ad10 and pushed.
Comment 33 Glyn Normington CLA 2010-07-21 10:47:25 EDT
Documentation added in Virgo documentation commit 7b582d3d21d5255485d083a95e68db6d11c68793.