• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with web fragments

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi All,

I am new to this forum and need help with Servlet 3.0

I am facing a problem with web fragments .I cannot understand the ouput (am using Tomcat 7.0.23) . I
have read the web fragment part in servlet 3.0 spec "8.2.2 Ordering of web.xml and web-fragment.xml" but I think
I missed out on something.

My application contains 1 servlet , 2 filters ,web.xml and a web-fragment.xml.Following is the structure :--

There are two directories servlets and filters in WEB-INF/classes folder.
i) servlets directory contains a servlet - testservlet2.java and its class file .
ii) filters directory contains a filter - wf1Filter.java and its class file .


There is a jar file called frag2.jar in WEB-INF/lib folder. It contains--

i) A filter wf2Filter.java and its class file in the webfragment2 folder in WEB-INF\lib\frag2.jar.
ii) A web-fragment.xml in the WEB-INF\lib\frag2.jar\META-INF directory .


The code :-





web-fragment.xml in the META-INF folder in WEB-INF\lib\frag2.jar.
----------------------------------------------------------------------------




testservlet2.java and its class file in WEB-INF/classes/servlets folder
----------------




wf1Filter.java and its class file in WEB-INF/classes/filters folder
--------------




wf2Filter.java and its class file in the webfragment2 folder in WEB-INF\lib\frag2.jar.
-----------------------------------------------------




Output that I am getting in Tomcat 7.0.23 is :-
----------------------------------------------

Before chain.doFilter in wf1Filter
Before chain.doFilter in wf2Filter
in testservlet2
After chain.doFilter in wf2Filter
After chain.doFilter in wf1Filter

What I cannot understand is why is the wf1Filter firing first ? The web.xml has an <absolute-ordering> element which says that the
web-fragment with <name>A</name> should be executed first .So should not the wf2Filter be invoked first and then wf1Filter?
wf1Filter uses an annotation and should be processed after wf2Filter. Is not the precedence like this --> web.xml , web-fragment.xml and then
the anotations. Please help.

Please reply.

Regards
Simran



 
Simran Dass
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi

Am I supposed to post this question in the SCWCD forum. I
am not able to make progress.

Regards
Simran
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the appropriate forum...
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Simran,
you can try with this
@WebFilter(filterName="wf1Filter")
public class wf1Filter implements Filter {}

@WebFilter(filterName="wf2Filter")
public class wf2Filter implements Filter {}

mention in your filter classes

and configure this in your web.xml file

<filter-mapping>
<filter-name>wf1Filter</filter-name>
<url-pattern>/*</filter-name>
</filter-mapping>
<filter-mapping>
<filter-name>wf2Filter</filter-name>
<url-pattern>/*</filter-name>
</filter-mapping>

I dont have much idea about web-fragment.xml ..so youi can try with..

 
Simran Dass
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks Eshwin .My problem is web fragments.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Simran

the last paragraph in 8.2.1 Modularity of web.xml says


[...] The order in which configuration from web-fragment.xml and annotations should be applied is undefined. [...]



See the first paragraph in 8.2.3 Assembling the descriptor from web.xml, web-fragment.xml and annotations, that is even more concrete.

You do not specify the wf1Filter in a web-fragment.xml, hence the order of wf1Filter (defined by annotation) and wf2Filter (defined by web-fragment.xml) is undefined. BTW, specifying the wf1Filter in the web.xml would not lead to what you are looking for, either, as web.xml must be processed before web-fragments. The only way to achieve what you want is to provide an additional jar with META-INF/web-fragment.xml and the definition of the wf1Filter:



Probably, you have to delete the annotation in your wf1Filter class; at least Glassfish has problems in that regard, and does not overwrite the annotation, but augments it, leading to

INFO: Before chain.doFilter in wf1Filter
INFO: Before chain.doFilter in wf2Filter
INFO: Before chain.doFilter in wf1Filter
INFO: in testservlet
INFO: After chain.doFilter in wf1Filter
INFO: After chain.doFilter in wf2Filter
INFO: After chain.doFilter in wf1Filter

Best regards
Christian
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic