Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324616 - Adding a servlet results in an inappropriate deletion of filter in web.xml
Summary: Adding a servlet results in an inappropriate deletion of filter in web.xml
Status: NEW
Alias: None
Product: WTP Java EE Tools
Classification: WebTools
Component: jst.servlet (show other bugs)
Version: 3.2   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: Future   Edit
Assignee: jst.servlet CLA
QA Contact: Chuck Bridgham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-07 02:40 EDT by Alexander Ryan CLA
Modified: 2015-11-18 03:43 EST (History)
3 users (show)

See Also:


Attachments
create fake servlet object with name * (1.41 KB, patch)
2011-01-20 09:50 EST, Dimitar Giormov CLA
no flags Details | Diff
A second patch (2.71 KB, patch)
2011-05-10 09:10 EDT, Vladislav Iliev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Ryan CLA 2010-09-07 02:40:34 EDT
Build Identifier: 20100617-1415

Selecting to add a new servlet to a web app is causing a line of code to get deleted from web.xml that should not be.
	<filter>
		<description>
		</description>
		<display-name>
		PersistentSessionFilter</display-name>
		<filter-name>PersistentSessionFilter</filter-name>
		<filter-class>net.visualocity.filters.PersistentSessionFilter</filter-class>
	</filter>
  <filter-mapping>
    <filter-name>PersistentSessionFilter</filter-name> 
    <servlet-name>*</servlet-name>  
  </filter-mapping>	
	<filter-mapping>
		<filter-name>PersistentSessionFilter</filter-name>
		<url-pattern>*.jsp</url-pattern>
	</filter-mapping>

The line that gets deleted is 
    <servlet-name>*</servlet-name>  

This happens EVERY time I add a new servlet


Reproducible: Always

Steps to Reproduce:
1.Add a filter to a web app with an entry like the one I specified above.
2.Simply add a new servlet to your app
3.Observe that eclipse tells you there is a problem with your web.xml
Comment 1 Carl Anderson CLA 2010-09-07 12:26:11 EDT
Alexander, judging by the build ID, I am assuming that you encountered this with the Eclipse Helios release, which corresponds to WTP 3.2.
Judging by the fact that I cannot reproduce this with a Web 2.5 project, but can reproduce it with a Web 2.4 project, I am assuming that you used a Web 2.4 (or older) project.
If either of these assumptions are incorrect, please update this bug.
Comment 2 Carl Anderson CLA 2010-09-07 12:27:00 EDT
I am assigning this to Kaloyan for initial investigation.  Please retarget/reassign as appropriate.
Comment 3 Alexander Ryan CLA 2010-09-07 12:29:28 EDT
Yes it is Helios.
Yes it is a web 2.4 project.
Comment 4 Dimitar Giormov CLA 2011-01-20 09:50:05 EST
Created attachment 187187 [details]
create fake servlet object with name *

The root cause of the problem is that in the transformation from EMF2DOM the model tries to resolve the reference of filter-mapping's servlet-name to a real servlet, in the case where the servlet name is * it fails to resolve it and thus removes it from the DOM tree.

The fix will create a fake servlet emf object that is not related to the model and return it as the referenced object.
Comment 5 Dimitar Giormov CLA 2011-01-20 09:51:14 EST
I am not sure that this is the correct way to fix this, but at least there is no data loss.
Comment 6 Chuck Bridgham CLA 2011-01-25 15:27:31 EST
I don't like this patch... Can you take a look at the translator itself?

it uses the SourceLinkTranslator that passes in a flag ... here is the method in question:

public static Translator createFilterMapping13Translator() {
		GenericTranslator result = new GenericTranslator(FILTER_MAPPING, WEBAPP_PKG.getWebApp_FilterMappings());
		result.setChildren(new Translator[] {
			new SourceLinkTranslator(FILTER_NAME, WEBAPP_PKG.getFilterMapping_Filter(), 
						new TranslatorPath(new Translator[] {
							new Translator(WEB_APP, Translator.CONTAINER_FEATURE), 
							new Translator(FILTER, WEBAPP_PKG.getWebApp_Filters()), 
							new Translator(FILTER_MAPPING, WEBAPP_PKG.getFilter_Name())
						})),
			new Translator(URL_PATTERN, WEBAPP_PKG.getFilterMapping_UrlPattern()), 
			new SourceLinkTranslator(SERVLET_NAME, WEBAPP_PKG.getFilterMapping_Servlet(), 
						new TranslatorPath(new Translator[] {
							new Translator(WEB_APP, Translator.CONTAINER_FEATURE), 
							new Translator(SERVLET, WEBAPP_PKG.getWebApp_Servlets()), 
							new Translator(SERVLET_NAME, WEBAPP_PKG.getServlet_ServletName()) 
						}), Translator.STRING_RESULT_OK),
		});
		return result;
	}



please take a look at changing here to avoid removing the node if not resolvable.
Comment 7 Dimitar Giormov CLA 2011-02-04 03:56:46 EST
I cannot find a way to fix this using the translators, re-targeting for 3.3, since potential fix could compromise the stability of the build.
Comment 8 Chuck Bridgham CLA 2011-03-11 12:58:17 EST
Removing review until we find another solution
Comment 9 Vladislav Iliev CLA 2011-05-10 09:10:28 EDT
Created attachment 195209 [details]
A second patch

New patch proposed.
Basically the changes are in FilterMapping implementation as well as in the involded translator (org.eclipse.wst.common.internal.emf.resource.SourceLinkTranslator).
Comment 10 Dimitar Giormov CLA 2011-05-20 02:58:55 EDT
re-targeting for SR1
Comment 11 Dimitar Giormov CLA 2011-05-20 03:29:29 EDT
re-targeting SR1
Comment 12 Dimitar Giormov CLA 2011-08-26 10:22:28 EDT
re-targeting 3.3.2
Comment 13 Dimitar Giormov CLA 2012-04-09 04:28:00 EDT
Hi Chuck,

we are lost here, frankly I am not sure if the translators could help. Can you give us a hand or point us to someone who is more familiar with the translators.
Basically we tried out different approaches, but we were unsuccessful.

thanks, 
Dimitar