Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330753

Summary: web.xml content gets deleted when adding servlets via the servlet wizards
Product: [WebTools] WTP Java EE Tools Reporter: Dimo Stoilov <Dimo.Stoilov>
Component: jst.j2eeAssignee: Dimitar Giormov <dimitar.giormov>
Status: RESOLVED FIXED QA Contact: Chuck Bridgham <cbridgha>
Severity: normal    
Priority: P3 CC: ccc, dimitar.giormov, djgraff209, neil.hauge, thatnitind, vladislav.iliev
Version: 3.2Flags: dimitar.giormov: pmc_approved? (david_williams)
dimitar.giormov: pmc_approved? (raghunathan.srinivasan)
dimitar.giormov: pmc_approved? (naci.dai)
dimitar.giormov: pmc_approved? (deboer)
neil.hauge: pmc_approved+
dimitar.giormov: pmc_approved? (kaloyan)
cbridgha: pmc_approved+
cbridgha: review+
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows XP   
URL: CSN#0002737221/2010
Whiteboard: PMC
Attachments:
Description Flags
sample web project
none
patch proposed dimitar.giormov: iplog+

Description Dimo Stoilov CLA 2010-11-21 12:45:49 EST
Build Identifier: M20100909-0800

We have a web project with a custom structure. When adding a servlet via the servlet wizard, the content of the web.xml gets deleted (the existing servlet etries dissappear). As a result the new servlet class is created but there are no servlet entries inside.

Reproducible: Always

Steps to Reproduce:
1. import the attached web project
2. create a servlet via the servlet wizard
Comment 1 Dimo Stoilov CLA 2010-11-21 12:46:57 EST
Created attachment 183537 [details]
sample web project
Comment 2 Carl Anderson CLA 2010-11-29 15:06:18 EST
I am assigning this to Kaloyan for the final triaging and/or fixing.

The problem here comes in the setup of the web project- the setup within the project is as follows:

webm\webContent\
webm\WEB-INF\

So in JEE5ModelProvider, it gets the root folder and appends the passed-in path to it.  The passed-in path is \WEB-INF\web.xml .  This is appended to the root folder, which is webm\webContent , and this yields webm\webContent\WEB-INF\web.xml, which does not exist.

The interesting thing is that, going through the ResourceSet (which, in this case, is a ProjectResourceSetEditImpl), there is already a mapping from the bad URI, webm\webContent\WEB-INF\web.xml, to the good URI, webm\WEB-INF\web.xml, so when the file is "created" at the end of the AddServletOperation, the existing content is replaced by the default content.

Thus, my assumption here is that JEE5ModelProvider.getModelResource() should be updated to see if the web.xml exists in the "correct" location (since, in the component file, WEB-INF has a different mapping than just being off of the project root.)
Comment 3 Dimitar Giormov CLA 2011-08-26 10:24:12 EDT
re-targeting for 3.3.2
Comment 4 Dimo Stoilov CLA 2012-01-20 11:37:00 EST
Created attachment 209838 [details]
patch proposed

Use the virtual components API when accessing the DD. This way the DD can be accessed with custom project structure.
Comment 5 Dimitar Giormov CLA 2012-01-23 08:33:43 EST
Chuck can you review the change?

Basically the virtual components model is used to pinpoint the web.xml instead of taking the resource from the file system.
Comment 6 Chuck Bridgham CLA 2012-01-23 09:39:11 EST
looks good - thanks - please add to HEAD too
Comment 7 Dimitar Giormov CLA 2012-01-25 05:00:40 EST
Once the builds are declared I will commit it in HEAD and 3_3_maintenance
Comment 8 Dimitar Giormov CLA 2012-01-30 08:54:24 EST
Q: Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug"
(requested by an adopter) please document it as such. 
A: The bug causes a custom structured projects to lose data. Web.xml file content gets deleted, since the model does not load the file from the correct location. Instead an empty web.xml content is loaded.

Q: Is there a work-around? If so, why do you believe the work-around is
insufficient? 
A: There is no workaround.

Q: How has the fix been tested? Is there a test case attached to the bugzilla
record? Has a JUnit Test been added? 
A: The fix has been tested manually with standard structure projects and the sample project given.


Q: Give a brief technical overview. Who has reviewed this fix? 
A: The fix changes the way the web.xml is found, instead of trying to assemble the location from the file system, the location is taken from the virtual components model (where it is always under /WEB-INF/web.xml)

Q: What is the risk associated with this fix? 
A: Low risk
Comment 9 Dimitar Giormov CLA 2012-02-01 05:58:08 EST
committed and released in HEAD and 3_3_maintenance