Issue #3713 - Emit warning when invoking deprecated method in Jetty XML.

Fixed references to deprecated methods WebAppContext.prependServerClass(),
WebAppContext.addServerClass() and WebAppContext.addSystemClass().

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2019-06-07 09:22:31 +02:00
parent 5b5848eb73
commit a510ed31cb
7 changed files with 85 additions and 72 deletions

View File

@ -2,21 +2,21 @@
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.util.Decorator</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.util.DecoratedObjectFactory</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler.</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
</Call>
<Get name="serverClasspathPattern">
<Call name="add">
<Arg>-org.eclipse.jetty.util.Decorator</Arg>
</Call>
<Call name="add">
<Arg>-org.eclipse.jetty.util.DecoratedObjectFactory</Arg>
</Call>
<Call name="add">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler.</Arg>
</Call>
<Call name="add">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
</Call>
<Call name="add">
<Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
</Call>
</Get>
</Configure>

View File

@ -23,6 +23,7 @@ import javax.naming.Reference;
import org.eclipse.jetty.plus.jndi.Resource;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.webapp.ClasspathPattern;
import org.eclipse.jetty.webapp.WebAppContext;
/**
@ -45,22 +46,22 @@ public class JettyWeldInitializer
initContext(webapp);
// webapp cannot change / replace weld classes
webapp.addSystemClass("org.jboss.weld.");
webapp.addSystemClass("org.jboss.classfilewriter.");
webapp.addSystemClass("org.jboss.logging.");
webapp.addSystemClass("com.google.common.");
webapp.addSystemClass("org.eclipse.jetty.cdi.websocket.annotation.");
ClasspathPattern systemClasses = webapp.getSystemClasspathPattern();
systemClasses.add("org.jboss.weld.");
systemClasses.add("org.jboss.classfilewriter.");
systemClasses.add("org.jboss.logging.");
systemClasses.add("com.google.common.");
systemClasses.add("org.eclipse.jetty.cdi.websocket.annotation.");
// don't hide weld classes from webapps (allow webapp to use ones from system classloader)
webapp.prependServerClass("-org.eclipse.jetty.cdi.websocket.annotation.");
webapp.prependServerClass("-org.eclipse.jetty.cdi.core.");
webapp.prependServerClass("-org.eclipse.jetty.cdi.servlet.");
webapp.addServerClass("-org.jboss.weld.");
webapp.addServerClass("-org.jboss.classfilewriter.");
webapp.addServerClass("-org.jboss.logging.");
webapp.addServerClass("-com.google.common.");
ClasspathPattern serverClasses = webapp.getServerClasspathPattern();
serverClasses.add("-org.eclipse.jetty.cdi.websocket.annotation.");
serverClasses.add("-org.eclipse.jetty.cdi.core.");
serverClasses.add("-org.eclipse.jetty.cdi.servlet.");
serverClasses.add("-org.jboss.weld.");
serverClasses.add("-org.jboss.classfilewriter.");
serverClasses.add("-org.jboss.logging.");
serverClasses.add("-com.google.common.");
}
public static void initContext(ContextHandler handler) throws NamingException

View File

@ -32,7 +32,8 @@ ____
This configuration is essentially the multiple logger configuration with added configuration to the deployers to force a `WebAppClassLoader` change to use the server classpath over the webapps classpath for the logger specific classes.
The technique used by this configuration is to provide an link:{JDURL}org/eclipse/jetty/deploy/AppLifeCycle.Binding.html[AppLifeCycle.Binding] against the link:{JDURL}/org/eclipse/jetty/deploy/AppLifeCycle.html[`"deploying"`node] that modifies the link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#addSystemClass(java.lang.String)[WebAppContext.addSystemClass(String)] for the common logging classes.
The technique used by this configuration is to provide an link:{JDURL}org/eclipse/jetty/deploy/AppLifeCycle.Binding.html[AppLifeCycle.Binding] against the link:{JDURL}/org/eclipse/jetty/deploy/AppLifeCycle.html[`"deploying"`node] that modifies the
link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#getSystemClasspathPattern()[WebAppContext.getSystemClasspathPattern().add(String)] for the common logging classes.
See https://github.com/jetty-project/jetty-webapp-logging/blob/master/src/main/java/org/eclipse/jetty/webapp/logging/CentralizedWebAppLoggingBinding.java[org.eclipse.jetty.logging.CentralizedWebAppLoggingBinding] for actual implementation.
A convenient replacement `logging` module has been created to bootstrap your `${jetty.base}` directory for capturing all Jetty server logging from multiple logging frameworks into a single logging output file managed by Logback.

View File

@ -94,9 +94,11 @@ From a context xml file, you reference the Server instance as a Ref:
[source, xml, subs="{sub-order}"]
----
<!-- Expose the jetty infinispan classes for session serialization -->
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.session.infinispan.</Arg>
</Call>
<Get name="serverClasspathPattern">
<Call name="add">
<Arg>-org.eclipse.jetty.session.infinispan.</Arg>
</Call>
</Get>
<!-- Get a reference to the InfinispanSessionIdManager -->
@ -132,10 +134,12 @@ From a `WEB-INF/jetty-web.xml` file, you can reference the Server instance direc
[source, xml, subs="{sub-order}"]
----
<!-- Expose the jetty infinispan classes for session serialization -->
<Call name="prependServerClass">
<!-- Expose the jetty infinispan classes for session serialization -->
<Get name="serverClasspathPattern">
<Call name="add">
<Arg>-org.eclipse.jetty.session.infinispan.</Arg>
</Call>
</Get>
<!-- Reference the server directly -->
<Get name="server">
@ -143,25 +147,25 @@ From a `WEB-INF/jetty-web.xml` file, you can reference the Server instance direc
</Get>
<!-- Get a reference to the Cache via the InfinispanSessionIdManager -->
<Ref id="idMgr">
<Get id="cache" name="cache"/>
</Ref>
<Ref id="idMgr">
<Get id="cache" name="cache"/>
</Ref>
<!-- Apply the SessionIdManager and Cache to the InfinispanSessionManager -->
<Set name="sessionHandler">
<New class="org.eclipse.jetty.server.session.SessionHandler">
<Arg>
<New id="mgr" class="org.eclipse.jetty.session.infinispan.InfinispanSessionManager">
<Set name="sessionIdManager">
<Ref id="idMgr"/>
</Set>
<Set name="cache">
<Ref id="cache">
</Ref>
</Set>
<Set name="scavengeInterval">600</Set>
</New>
</Arg>
<Arg>
<New id="mgr" class="org.eclipse.jetty.session.infinispan.InfinispanSessionManager">
<Set name="sessionIdManager">
<Ref id="idMgr"/>
</Set>
<Set name="cache">
<Ref id="cache">
</Ref>
</Set>
<Set name="scavengeInterval">600</Set>
</New>
</Arg>
</New>
</Set>
----
@ -178,7 +182,7 @@ staleIntervalSec::
===== Using HotRod
If you're using the hotrod client - where serialization will be required - you will need to ensure that the hotrod marshalling software works with Jetty classloading.
To do this, firstly ensure that you have included the lines containing the `prependServerClass` to your context xml file as shown above.
To do this, firstly ensure that you have included the lines containing the `getServerClasspathPattern().add(...)` to your context xml file as shown above.
Then, create the file `${jetty.base}/resources/hotrod-client.properties`.
Add the following line to this file:

View File

@ -79,7 +79,11 @@ Below is an example of implementing this feature using Jetty IoC XML format:
[[classloading-setting-system-classes]]
===== Setting System Classes
You can call the methods link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#setSystemClasses%28java.lang.String%5B%5D%29[org.eclipse.jetty.webapp.WebAppContext.setSystemClasses(String Array)] or link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#addSystemClass(java.lang.String)[org.eclipse.jetty.webapp.WebAppContext.addSystemClass(String)] to allow fine control over which classes are considered System classes.
You can call the methods
link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#setSystemClasses%28java.lang.String%5B%5D%29[WebAppContext.setSystemClasses(String[\])]
or
link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#getSystemClasspathPattern()[WebAppContext.getSystemClasspathPattern().add(String)]
to allow fine control over which classes are considered system classes.
* A web application can see a System class.
* A WEB-INF class cannot replace a System class.

View File

@ -4,20 +4,21 @@
<!-- Weld needs access to some internal classes. Same configuration as "cdi2" module provides on server. -->
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.util.Decorator</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.util.DecoratedObjectFactory</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler.</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
</Call>
<Call name="prependServerClass">
<Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
</Call>
<Get name="serverClasspathPattern">
<Call name="add">
<Arg>-org.eclipse.jetty.util.Decorator</Arg>
</Call>
<Call name="add">
<Arg>-org.eclipse.jetty.util.DecoratedObjectFactory</Arg>
</Call>
<Call name="add">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler.</Arg>
</Call>
<Call name="add">
<Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
</Call>
<Call name="add">
<Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
</Call>
</Get>
</Configure>

View File

@ -9,8 +9,10 @@ org.eclipse.jetty.servlet.WebApplicationContext object
-->
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Call name="prependServerClass"><Arg>-org.eclipse.jetty.util.</Arg></Call>
<Call name="prependServerClass"><Arg>-org.eclipse.jetty.servlets.</Arg></Call>
<Get name="serverClasspathPattern">
<Call name="add"><Arg>-org.eclipse.jetty.util.</Arg></Call>
<Call name="add"><Arg>-org.eclipse.jetty.servlets.</Arg></Call>
</Get>
<Get class="org.eclipse.jetty.util.log.Log" name="rootLogger">
<Call name="warn"><Arg>test webapp is deployed. DO NOT USE IN PRODUCTION!</Arg></Call>
</Get>