This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 160049 - Multiple url-pattern elements within a servlet-mapping element declared invalid
Summary: Multiple url-pattern elements within a servlet-mapping element declared invalid
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P2 blocker (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-10 22:08 UTC by jessholle
Modified: 2009-04-27 00:03 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
web.xml which reproduces this issue (807 bytes, text/xml)
2009-03-20 19:03 UTC, Petr Jiricka
Details
a patch (6.04 KB, text/plain)
2009-04-21 03:43 UTC, David Konecny
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jessholle 2009-03-10 22:08:41 UTC
NetBeans 6.5 (and 6.7M2) produce a fatal error on the all views except the XML view for web.xml files that a
servlet-mapping element which contains multiple url-pattern child elements.  This is despite the fact that the servlet
2.5 specification and DTD both allow this cardinality and check and validate XML actions both succeed.

Overall it would appear that the web.xml views have not kept up with the spec and fall flat on their face for this use
case.  This is unfortunate as producing one servlet-mapping element per url-pattern is verbose and hard to read by
comparison, so overall I'll keep my web.xml readable and have to forgo nice web.xml browsing features NetBeans would
otherwise have provided.
Comment 1 Petr Jiricka 2009-03-20 19:02:26 UTC
Yes, I can reproduce. I am attaching a web.xml file that reproduces this issue. 

The problem is that multiple url-pattern elements are not handled at the level of the NetBeans deployment descriptor
API. There is also a corresponding TODO comment in j2ee.dd/src/org/netbeans/modules/j2ee/dd/impl/resources/web-app_2_5.xsd.

I thing this was not easy to fix but I am not sure why - Erno, do you recall? Was it because it was hard to do in a
backward compatible way, so that the org.netbeans.modules.j2ee.dd.api classes remain compatible? Thanks.
Comment 2 Petr Jiricka 2009-03-20 19:03:33 UTC
Created attachment 78546 [details]
web.xml which reproduces this issue
Comment 3 Erno Mononen 2009-03-20 20:00:36 UTC
That may have been the reason, and/or that s2b doesn't support this. I'll try to search for more details.
Comment 4 Petr Jiricka 2009-04-08 16:35:36 UTC
Tomas, can you please look at this? 

Jess, so would you normally use the graphical editor for web.xml? How useful is it to you (or would be, if this issue
was fixed), compared to the plain text editor? Thanks.
Comment 5 jessholle 2009-04-08 17:37:26 UTC
I normally hand-edit web.xml as text.  The graphical editor is just a nice to have item for browsing.

In any case, however, the editor shouldn't claim that a valid web.xml is invalid (and worse yet has "fatal errors"!)
simply because it is not up to the task of dealing with it.  Doing so engenders unnecessary confusion and causes the
user to question both their web.xml and the reliability of NetBeans.
Comment 6 Tomas Mysik 2009-04-15 13:55:44 UTC
In fact, this will be very hard to fix and right now I have no idea what the correct fix is.
Comment 7 jessholle 2009-04-15 13:59:52 UTC
Could you at least stop blaming the web.xml and claiming that it has "fatal errors" and instead say something to
indicate that the web.xml is too sophisticated for the current graphic editor functionality?  Or just automatically drop
the graphical editor tabs/panes in this situation?  Telling the user their web.xml is in error when the editor itself is
in error is my main complaint.
Comment 8 Tomas Mysik 2009-04-16 12:46:29 UTC
A possible fix of this issue could be (not tested):

- create a new interface ServletMapping25 (extends ServletMapping) with getter and setter for String[] urlPatterns
- implement this interface for web.xml 2.5
- in MDD file - map DTD property url-pattern to urlPatterns and create getter/setter for "old" String urlPattern (they should delegate to
the new methods and print warning to console)

This solution should be backward compatible so no existing client should stop working.

Unfortunately, mapping "url-pattern" to "urlPatterns" in MDD file does not work for me (possible bug in schema2beans module?).
Comment 9 Milan Kuchtiak 2009-04-16 13:22:41 UTC
Other solution (may be not) is writing some <user-code> element to mdd file (implement getUrlPatterns(),
serUrlPatterns() methods) 
Comment 10 Tomas Mysik 2009-04-16 13:42:00 UTC
I don't think so, Milane - one needs to ensure that these methods are called (so the mapping between url-pattern and getUrlPatterns() is
still needed).
Comment 11 Milan Kuchtiak 2009-04-17 10:11:11 UTC
I cannot find a way to modify mdd file.
One solution I see is to prepare the ServletMapping bean ahead (e.g. in resources package). Then, after bean generation
replace the generated ServletMapping version with this one. It could be done in build.xml.
Comment 12 Petr Jiricka 2009-04-17 13:15:21 UTC
Or, as Tomas suggested, apply a patch on the generated file as a part of the build.
Comment 13 David Konecny 2009-04-21 03:41:39 UTC
re. "mapping "url-pattern" to "urlPatterns" in MDD file does not work" - how would you do that? I'm getting familiar
with DD API module and was curious how would you describe it in MDD file? I would expect meta-property to have an
attribute like "field-name" via which you could override default name but I have not found anything like that.

Attached patch seems to do half the job (there is one more TODO item to fix in XSD and UI for editting URLs needs to be
enhanced or disabled otherwise it may clobber changes done by hand).
Comment 14 David Konecny 2009-04-21 03:43:04 UTC
Created attachment 80555 [details]
a patch
Comment 15 Tomas Mysik 2009-04-21 11:35:48 UTC
> re. "mapping "url-pattern" to "urlPatterns" in MDD file does not work" - how would you do that?

I tried to do this:
----- >% -----
<meta-property>
    <dtd-name>url-pattern</dtd-name>
    <bean-name>UrlPatterns</bean-name>
</meta-property>
----- >% -----

But now I see that's incorrect (I overlooked that dtd-name cannot be specified for meta-property).

> Attached patch seems to do half the job (there is one more TODO item to fix in XSD and UI for editting URLs needs to be
> enhanced or disabled otherwise it may clobber changes done by hand).

Yes, I would prefer to enhance Web XML multiview if possible. I will look at it and try to fix it.

Thanks for the patch, Davide!
Comment 16 Tomas Mysik 2009-04-22 14:36:02 UTC
FYI I filed issue #163396 for filter mappings.
Comment 17 Tomas Mysik 2009-04-23 09:16:50 UTC
Fixed, please verify if possible. Thanks.
http://hg.netbeans.org/web-main/rev/c11933ffed15
Comment 18 Quality Engineering 2009-04-23 19:54:20 UTC
Integrated into 'main-golden', will be available in build *200904231401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/c11933ffed15
User: Tomas Mysik <tmysik@netbeans.org>
Log: #160049: Multiple url-pattern elements within a servlet-mapping element declared invalid
Comment 19 David Konecny 2009-04-23 20:51:38 UTC
Tomas, I think something similar needs to be done also for "filter-name" - search XSD for TODO comment.
Comment 20 Tomas Mysik 2009-04-24 08:34:30 UTC
Davide, do you mean this issue #163396?
Comment 21 David Konecny 2009-04-27 00:03:05 UTC
Yeap, I overlooked you've created separate issue for that. Thanks.