edrikL / javamelody

Automatically exported from code.google.com/p/javamelody
0 stars 0 forks source link

monitoring-path param in web.xml under jdk8_0_31 not working #459

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create simple project with web.xml 
<param-name>monitoring-path</param-name>
<param-value>/m1</param-value>

What is the expected output? What do you see instead?
Javamelody still working with path /monitoring, instead of expected /m1.
Under jdk7_0_75 all work fine. Other <param-name> under jdk8 not working too.

What version of the product are you using? On what application server, JDK,
operating system?
Eclise Luna SR1a, Tomcat 8.0.15, JDK8_0_31, JDK7_0_75, windows 7 x64

Please provide any additional information below.
Simple /test project for Eclipse is included.

Original issue reported on code.google.com by 4340...@gmail.com on 15 Feb 2015 at 10:47

Attachments:

GoogleCodeExporter commented 9 years ago
I have reproduced the issue using Tomcat 8, JDK8 on windows, with a webapp 
version 3.1.
The fact is that when using JDK8, the filter instance is now created twice by 
Tomcat, which is not the case when using JDK7.
The cause is related to the META-INF/web-fragment.xml inside the javamelody jar 
file.

As a workaround to the issue in this case, I suggest to remove MonitoringFilter 
and SessionListener from web.xml (they are already in web-fragment) and add 
context parameters in your web.xml file. More info:
https://code.google.com/p/javamelody/wiki/UserGuide#6._Optional_parameters

For example:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    version="3.1">

     <context-param>
        <param-name>javamelody.monitoring-path</param-name>
        <param-value>/m1</param-value>
     </context-param>

</web-app>

Original comment by evernat@free.fr on 22 Feb 2015 at 8:28

GoogleCodeExporter commented 9 years ago
Thank U. Your decision to help.
All work fine.

Original comment by 4340...@gmail.com on 24 Feb 2015 at 11:39

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
To be precise about what happens if you have a webapp version 3.1:
1. With JDK7 and JDK8, without MonitoringFilter and SessionListener in web.xml: 
the MonitoringFilter is active thanks to web-fragment.xml in the javamelody jar 
file. You can add parameters with context-param for example. This is the 
recommended configuration for webapp version 3.1. OK.

2. With JDK7, when you add MonitoringFilter with a filter-name "monitoring" in 
web.xml of your webapp: the MonitoringFilter from web.xml is active and the 
MonitoringFilter from web-fragment.xml is in fact inactive. OK.

3. With JDK8, when you add MonitoringFilter with a filter-name "monitoring" in 
web.xml: the MonitoringFilter from web.xml is inactive! and the 
MonitoringFilter from web-fragment.xml is active. So the init-parameters of the 
filter in web.xml are ignored. KO.

That's because filter definitions are listed in Tomcat in a HashMap and not a 
LinkedHashMap:
http://grepcode.com/file/repo1.maven.org/maven2/org.apache.tomcat/tomcat-catalin
a/8.0.17/org/apache/catalina/core/StandardContext.java#StandardContext.0filterDe
fs
And so the order between initialization of filters happens to be dependant on 
the implementation of HashMap in the JDK and it happens that the order of 
HashMap has changed between JDK7 and JDK8:
http://docs.oracle.com/javase/8/docs/technotes/guides/collections/changes8.html
This is JavaEE compliant but unfortunate that the order of filters' 
initializations changes between JDK7 and JDK8.

4. With JDK7 and JDK8, when you add MonitoringFilter with a filter-name 
"javamelody" (instead of "monitoring") in web.xml: the MonitoringFilter from 
web.xml is active because it overrides the one from web-fragment.xml which has 
the same name. OK.

So the case 1 is the one recommended for webapp version 3.1 as said in my 
previous comment.
And in order that other people don't go to case 3 and go to case 1 or 4 
instead, I have changed the filter-name example and I have added a 
context-param example in the user guide:
https://code.google.com/p/javamelody/wiki/UserGuide#2._web.xml_file

Thanks for the issue.

Original comment by evernat@free.fr on 14 Mar 2015 at 11:55