Skip to main content



      Home
Home » Language IDEs » ServerTools (WTP) » WTP M3/M4 -- Tomcat 5.0.28 -- META-INF/ context.xml not being processed
WTP M3/M4 -- Tomcat 5.0.28 -- META-INF/ context.xml not being processed [message #106047] Thu, 19 May 2005 20:53 Go to next message
Eclipse UserFriend
Originally posted by: laurentd75___no.sp_am.yahoo.fr

Hi,

I know a great of work has been done up to very recently concerning Tomcat
support in WTP.

For Tomcat 5.x especially, the WTP Tomcat plugin is supposed to look for
WebContent/META-INF/context.xml, extract the child nodes of the Context
element and copy them into the corresponding Context element it creates in
the Tomcat launch configuration's server.xml file.

Well, this is the theory, but in practice I found that this mechanism was
very unstable: sometimes it works, sometimes it does not, and I'm not sure
why.

To prove my point:

I created a simple test Webapp ("TestTomcatContext2Web"), inspiring myself
from the sample illustrated in Bug Report #8212
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=82812) posted by Larry
Isaacs.

The Webapp is a simple Web module (J2EE Web app project in WTP M3, and J2EE
Web module created within a flexible project in WTP M4).

The application has two environment resource refs, plus an env. entry. The
env. resource refs defined in WEB-INF/web.xml map to corresponding entries
in META-INF/context.xml

There is a single index.jsp page that basically tries to lookup the 3 JNDI
variables defined and tries to print their values (converting all values to
String to keep things simple).

When I try to run the Webapp from inside WTP (using either Eclipse 3.1M5 +
WTP M3, or Eclipse 3.1M6 + WTP M4) I get Naming exceptions. The reason is,
the META-INF/context.xml is *not * being processed as it should, and WTP
creates an "empty" Context element in the server configuration's server.xml
file.

However, when I package and deploy the application as a WAR file and start
Tomcat outside WTP, it works and is able to successfully retrieve & print
the JNDI values.

I am attaching my 3 test files: context.xml, web.xml and index.jsp

Below is the correct output I get from index.jsp when deploying the app as a
WAR file in Tomcat:
______________________

TestTomcatContext2 Env entry

JNDI value for 'java:comp/env/log/console' = on
JNDI value for 'java:comp/env/intValue' = 33
JNDI value for 'java:/comp/env/jdbc/MySampleDB' =
org.apache.commons.dbcp.BasicDataSource
______________________

Now, this is the incorrect output I get from index.jsp when trying to deploy
& test the app from within WTP:

______________________

TestTomcatContext2Web

NamingException occurred while retrieving JNDI value for
'java:comp/env/log/console': javax.naming.NamingException: Cannot create
resource instance
JNDI value for 'java:comp/env/intValue' = 33
NamingException occurred while retrieving JNDI value for
'java:comp/env/jdbc/MySampleDB': javax.naming.NamingException: Cannot
create resource instance
______________________

In this case, you will notice that the only successful lookup is for the
env-entry, since it is only defined in web.xml and has no mapping in
context.xml. The "cannot create resource instance' errors occur because
Tomcat fails to map entries defined in web.xml to corresponding entries in
the "TestTomcatContext2Web.xml" file that the plugin creates in the
" workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp 0\conf " folder,
since the <Context> element in this file does not contain any of the child
nodes in the META-INF/context.xml file.

I have been dealing with this error for the last 2 days, and could not find
the cause of the problem, or a workaround.

When I create my Tomcat 5.0 server in WTP, I normally use the default
configuration (with the "Run modules directly from the workspace" option
checked). However, unchecking this option doesn't make any difference.

I also tried to add/remove the project several times to the server and test
it again, but it always fails.

What is weird is, I could actually make the original example illustrated in
Larry Isaacs' Bugzilla report work perfectly... But his sample only has a
single <Environment> child node in context.xml, whereas my sample as a
couple more entries.

So, I first suspected there might be an error in my "context.xml" file that
prevented the WTP Tomcat plugin from correctly parsing it... But then, why
would it work if I deploy the application as a WAR file and start Tomcat
outside WTP ??

Obviously, this issue is critical to me: if I cannot use WTP to develop &
test Webapps that use JNDI objects mapped in context.xml, then I am in big
trouble...

Therefore, I would be very much indebted to anyone that can help me resolve
this issue...

A million thanks in advance,

Laurent




  • Attachment: web.xml
    (Size: 0.82KB, Downloaded 167 times)
  • Attachment: context.xml
    (Size: 1.09KB, Downloaded 154 times)
  • Attachment: index.jsp
    (Size: 0.93KB, Downloaded 153 times)
Re: WTP M3/M4 -- Tomcat 5.0.28 -- META-INF/ context.xml not being processed [message #106106 is a reply to message #106047] Thu, 19 May 2005 20:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: laurentd75___no.sp_am.yahoo.fr

PS -- I opened Bug report #96047 against the wst.server component for this
issue.
Re: WTP M3/M4 -- Tomcat 5.0.28 -- META-INF/ context.xml not being processed [message #106133 is a reply to message #106106] Thu, 19 May 2005 21:43 Go to previous messageGo to next message
Eclipse UserFriend
Hi Laurent,

Before addressing the bug, I need to determine something, at least with
respect to M4. I need to determine if the problem is in the incremental
building or in the Tomcat handling itself. I have seen this behavior in
M4, but only due to incremental building.

With the flexible project structure in M4, the Tomcat handling does
*not* look for:

<project>/<module>/WebContent/META-INF/context.xml

but instead looks for:

<project>/.deployables/<module>/META-INF/context.xml

After adding or changing the "WebContent" file, those changes don't
always make it into the ".deployables" directory. To force the
".deployables" directory to be updated, execute Project -> Clean for the
project containing the webapp. If you do this, does the context
configuration still not appear in the server.xml under the
".metadata\.plugins\org.eclipse.wst.server.core\tmp?" directory? Note,
if the server thinks it is synchronized, you may have to remove and
re-add the module to the server to get it to re-publish and update the
server.xml. Thanks.

Larry


Laurent D wrote:
> PS -- I opened Bug report #96047 against the wst.server component for this
> issue.
>
>
Re: WTP M3/M4 -- Tomcat 5.0.28 -- META-INF/ context.xml not being processed [message #106239 is a reply to message #106133] Fri, 20 May 2005 07:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: laurentd75__no___spa_m.yahoo.fr

Larry Isaacs wrote:

> Before addressing the bug, I need to determine something, at least with
> respect to M4. I need to determine if the problem is in the incremental
> building or in the Tomcat handling itself. I have seen this behavior in
> M4, but only due to incremental building.
> With the flexible project structure in M4, the Tomcat handling does
> *not* look for:
> <project>/<module>/WebContent/META-INF/context.xml
> but instead looks for:
> <project>/.deployables/<module>/META-INF/context.xml
> After adding or changing the "WebContent" file, those changes don't
> always make it into the ".deployables" directory. To force the
> ".deployables" directory to be updated, execute Project -> Clean for the
> project containing the webapp. If you do this, does the context
> configuration still not appear in the server.xml under the
> ".metadata.pluginsorg.eclipse.wst.server.coretmp?" directory? Note,
> if the server thinks it is synchronized, you may have to remove and
> re-add the module to the server to get it to re-publish and update the
> server.xml. Thanks.

Hi Larry,

Thanks for the quick reply, that's a real big relief for me to see you're
going to look into this !!

To answer your question:
- first, to be absolutely sure, I've reproduced this behaviour on a fresh
install of Eclipse 3.1 + WTP M4, against a fresh install of Tomcat 5.0.28

- Created a new Tomcat 5.0 Server. Started and stopped it to check it was
working ok.

- Created new Flexible Project "TomcatContext2Proj", added a 2.3 Web
module to it called "TomcatContext2Web".

- used the 3 files I attached to my previous message (inde.jsp, web.xml,
context.xml) and copied them where they belong in the Web module (the
web.xml replacing the one created by the wizard).

- right-clicked on y "TomcatContext2Proj" project and selected "RUn As -6>
Run on Server". In the dialog box, I checked "use existing server",
selected my Tomcat Server and clicked Finish.

- The server starts correctly, the Web browser window is displayed but the
index.jsp page produces Naming exceptions cause it can't find any JNDI
mappings cause the Context element for the webapp in server.xml doesn't
have any child nodes.

This is what gets copied into my server.xml in
C:\Dev\Eclipse3.1M6\workspace\.metadata\.plugins\org.eclipse .wst.server.core\tmp0\conf
:

(it's really all on one line but I cut it to improve legibility):

<Context
docBase=" C:\Dev\Eclipse3.1M6workspace\TomcatContext2Proj\.deployables \TomcatContext2Web "
path="/TomcatContext2Web" reloadable="true"
source="com.ibm.wtp.web.server:TomcatContext2Web"/>

In can also see a "TomcatContext2Web.xml" file in
C:\Dev\Eclipse3.1M6\workspace\.metadata\.plugins\org.eclipse .wst.server.core\tmp0\conf\Catalina\localhost

which contains the same, empty <Context> element as the one in
server.xml...


****
*** Now, to answer your questions:
****
- In my .deployables folder, I do have the exact copy of my original
context.xml file, with all the correct entries

- I've tried stoppng the server, removing the project from the server,
re-adding the project to the server, and then hitting the "publish"
option, and finally starting it. It still doesn't make an difference.


So... I think this leaves us with:

- either a synchronization issue: you said that sometimes the server
thinks it is synchronized, and it is necesary to remove and re-add the
module to the server to get it to re-publish and update the server.xml.
However, I think I went through the correct steps to do that, didn't I ?

- either a bug in the "Tomcat handling" itself in the plugin.


What do you reckon ?? Any ideas ??


Actually, I did take a peek at the code I checked out from CVS.

I looked in
jst/server/plugins/org.eclipse.jst.server.tomcat.core/tomcat core,

and I gathered that most of the functionality for handling conext.xml was
in class org.eclipse.jst.server.tomcat.core.internal.Tomcat50Configur ation
(v 1.17, last changed 29 Apr 2005 15:01)

Unfortunately, I don't have a clue about the Eclipse plugin architecture,
and I'm not very knowledgeable about Tomcat's internals, and quite frankly
I wouldn't know exactly where to look, and how to debug WTP using the
source... But I'm just thinking that if there's a bug, there's a good
chance it is hiding somewhere here... But obviously, you already know all
this, and much more !


I really look forward to your examination of this bug or strange
behaviour...

Thanks,

Laurent
Re: WTP M3/M4 -- Tomcat 5.0.28 -- META-INF/ context.xml not being processed [message #106517 is a reply to message #106239] Sat, 21 May 2005 09:56 Go to previous messageGo to next message
Eclipse UserFriend
As noted in Bug 96047, the cause of this behavior is that the
context.xml file begins with a UTF-8 Byte-Order-Mark, which the Crimson
parser isn't able to handle. The Tomcat handling uses Crimson because
that is the default parser provided by the JDK 1.4.x Eclipse is running
under in this case. Note that even though the context.xml can't be read
by Crimson, the file will still validate because Xerces is used for
validation and Xerces *is* able to handle the BOM. Temporarily
switching the encoding of the file to US-ASCII and removing the 3 funny
characters at the beginning of the file would remove the BOM and fix
this behavior.

Larry

Laurent D wrote:
> Larry Isaacs wrote:
>
>> Before addressing the bug, I need to determine something, at least
>> with respect to M4. I need to determine if the problem is in the
>> incremental building or in the Tomcat handling itself. I have seen
>> this behavior in M4, but only due to incremental building.
>> With the flexible project structure in M4, the Tomcat handling does
>> *not* look for:
>> <project>/<module>/WebContent/META-INF/context.xml
>> but instead looks for:
>> <project>/.deployables/<module>/META-INF/context.xml
>> After adding or changing the "WebContent" file, those changes don't
>> always make it into the ".deployables" directory. To force the
>> ".deployables" directory to be updated, execute Project -> Clean for
>> the project containing the webapp. If you do this, does the context
>> configuration still not appear in the server.xml under the
>> ".metadata.pluginsorg.eclipse.wst.server.coretmp?" directory? Note,
>> if the server thinks it is synchronized, you may have to remove and
>> re-add the module to the server to get it to re-publish and update the
>> server.xml. Thanks.
>
>
> Hi Larry,
>
> Thanks for the quick reply, that's a real big relief for me to see
> you're going to look into this !!
>
> To answer your question:
> - first, to be absolutely sure, I've reproduced this behaviour on a
> fresh install of Eclipse 3.1 + WTP M4, against a fresh install of Tomcat
> 5.0.28
>
> - Created a new Tomcat 5.0 Server. Started and stopped it to check it
> was working ok.
>
> - Created new Flexible Project "TomcatContext2Proj", added a 2.3 Web
> module to it called "TomcatContext2Web".
>
> - used the 3 files I attached to my previous message (inde.jsp, web.xml,
> context.xml) and copied them where they belong in the Web module (the
> web.xml replacing the one created by the wizard).
>
> - right-clicked on y "TomcatContext2Proj" project and selected "RUn As
> -6> Run on Server". In the dialog box, I checked "use existing server",
> selected my Tomcat Server and clicked Finish.
>
> - The server starts correctly, the Web browser window is displayed but
> the index.jsp page produces Naming exceptions cause it can't find any
> JNDI mappings cause the Context element for the webapp in server.xml
> doesn't have any child nodes.
>
> This is what gets copied into my server.xml in
> C:\Dev\Eclipse3.1M6\workspace\.metadata\.plugins\org.eclipse .wst.server.core\tmp0\conf
> :
>
> (it's really all on one line but I cut it to improve legibility):
>
> <Context
> docBase=" C:\Dev\Eclipse3.1M6workspace\TomcatContext2Proj\.deployables \TomcatContext2Web "
> path="/TomcatContext2Web" reloadable="true"
> source="com.ibm.wtp.web.server:TomcatContext2Web"/>
>
> In can also see a "TomcatContext2Web.xml" file in
> C:\Dev\Eclipse3.1M6\workspace\.metadata\.plugins\org.eclipse .wst.server.core\tmp0\conf\Catalina\localhost
>
>
> which contains the same, empty <Context> element as the one in
> server.xml...
>
>
> ****
> *** Now, to answer your questions:
> ****
> - In my .deployables folder, I do have the exact copy of my original
> context.xml file, with all the correct entries
>
> - I've tried stoppng the server, removing the project from the server,
> re-adding the project to the server, and then hitting the "publish"
> option, and finally starting it. It still doesn't make an difference.
>
>
> So... I think this leaves us with:
>
> - either a synchronization issue: you said that sometimes the server
> thinks it is synchronized, and it is necesary to remove and re-add the
> module to the server to get it to re-publish and update the server.xml.
> However, I think I went through the correct steps to do that, didn't I ?
>
> - either a bug in the "Tomcat handling" itself in the plugin.
>
>
> What do you reckon ?? Any ideas ??
>
>
> Actually, I did take a peek at the code I checked out from CVS.
>
> I looked in
> jst/server/plugins/org.eclipse.jst.server.tomcat.core/tomcat core,
>
> and I gathered that most of the functionality for handling conext.xml
> was in class
> org.eclipse.jst.server.tomcat.core.internal.Tomcat50Configur ation
> (v 1.17, last changed 29 Apr 2005 15:01)
>
> Unfortunately, I don't have a clue about the Eclipse plugin
> architecture, and I'm not very knowledgeable about Tomcat's internals,
> and quite frankly I wouldn't know exactly where to look, and how to
> debug WTP using the source... But I'm just thinking that if there's a
> bug, there's a good chance it is hiding somewhere here... But obviously,
> you already know all this, and much more !
>
>
> I really look forward to your examination of this bug or strange
> behaviour...
>
> Thanks,
>
> Laurent
>
>
Re: WTP M3/M4 -- Tomcat 5.0.28 -- META-INF/ context.xml not being processed [message #106562 is a reply to message #106517] Sun, 22 May 2005 14:09 Go to previous message
Eclipse UserFriend
Originally posted by: laurentd75___no.sp_am.yahoo.fr

Larry Isaacs wrote:

> As noted in Bug 96047, the cause of this behavior is that the
> context.xml file begins with a UTF-8 Byte-Order-Mark, which the Crimson
> parser isn't able to handle. <cut>
> Temporarily switching the encoding of the file to US-ASCII and removing
> the 3 funny characters at the beginning of the file would remove the BOM
> and fix this behavior.

THANK YOU SO MUCH LARRY, YOU CRACKED IT !! It now works perfectly both in M3
and in M4 !!

You really did an amazing job with this issue, and very quickly too, and I
really wanted to express publicly my sincere thanks for your precious help
in this matter, you really saved me an awful lot of trouble !

Hoping I can pay back the WTP community someway very soon,

Obligingly Yours,

Laurent
Previous Topic:Flexible project model and server API enhancement request deferred to 1.1
Next Topic:Getting referenced projects into the webapp classpath
Goto Forum:
  


Current Time: Sun May 11 16:27:42 EDT 2025

Powered by FUDForum. Page generated in 0.03602 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top