Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward compat API WebAppContext.getServerClassMatcher() is not updating the WebAppClassloader #11767

Closed
joakime opened this issue May 8, 2024 · 1 comment · Fixed by #11769
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@joakime
Copy link
Contributor

joakime commented May 8, 2024

Jetty version(s)
12.0.9

Jetty Environment
ee10 (but could be more)

Java version/vendor (use: java -version)
Any

OS type/version
Any

Description
If a project is using the old API WebAppContext.getServerClassMatcher() and then modifies the server classes, those changes are not applied to the WebAppClassloader of the WebAppContext.

This applies to Embedded usage and XML deployables.

If the deployable has, for example ...

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure class="org.eclipse.jetty.ee10.webapp.WebAppContext">
  <Set name="contextPath">/demo</Set>
  <Set name="war"><Property name="jetty.webapps" />/demo.war
  </Set>
  <Ref refid="Server">
    <Call id="lowResourceMonitor" name="getBean">
      <Arg>
        <Call class="java.lang.Class" name="forName">
          <Arg>org.eclipse.jetty.server.LowResourceMonitor</Arg>
        </Call>
      </Arg>
    </Call>
  </Ref>
  <Call name="setAttribute">
    <Arg>org.eclipse.jetty.server.LowResourceMonitor</Arg>
    <Arg>
      <Ref refid="lowResourceMonitor" />
    </Arg>
  </Call>
  <!-- tweak what classes from the Server this WebAppContext can see -->
  <Get name="serverClassMatcher">
    <Call name="add">
      <!-- needed for all example servlets to actually see LowResourceMonitor -->
      <Arg>-org.eclipse.jetty.server.LowResourceMonitor</Arg>
    </Call>
    <Call name="add">
      <!-- needed for example servlets that use Server.getBean().
           FromBaseRequestServlet
           and FromRequestAttributeChannelServlet
           and FromRequestAttributeConnectionServlet -->
      <Arg>-org.eclipse.jetty.server.Server</Arg>
    </Call>
    <Call name="add">
      <!-- needed for FromBaseRequestServlet -->
      <Arg>-org.eclipse.jetty.server.Request</Arg>
    </Call>
  </Get>
</Configure>

These changes are not applied to the WebAppClassloader.
To work, the project needs the following change.

diff --git a/standalone/lowresource-access/webapps/demo.xml b/standalone/lowresource-access/webapps/demo.xml
index c5cf4dc..4752183 100644
--- a/standalone/lowresource-access/webapps/demo.xml
+++ b/standalone/lowresource-access/webapps/demo.xml
@@ -20,7 +20,7 @@
     </Arg>
   </Call>
   <!-- tweak what classes from the Server this WebAppContext can see -->
-  <Get name="serverClassMatcher">
+  <Get name="hiddenClassMatcher">
     <Call name="add">
       <!-- needed for all example servlets to actually see LowResourceMonitor -->
       <Arg>-org.eclipse.jetty.server.LowResourceMonitor</Arg>

The project at https://github.com/jetty/jetty-examples/tree/12.0.x/standalone/lowresource-access can be used as an example.
Note: you will need to revert the commit jetty/jetty-examples@14d5c89 to replicate this bug.

@joakime joakime added the Bug For general bugs on Jetty side label May 8, 2024
@gregw
Copy link
Contributor

gregw commented May 8, 2024

Likely due to changes introduced in #11566 or #11722

gregw added a commit that referenced this issue May 8, 2024
Fix #11767 by making deprecated ClassMatcher class wrap the util ClassMatcher
gregw added a commit that referenced this issue May 21, 2024
Fix #11767 by making deprecated ClassMatcher class wrap the util ClassMatcher

Co-authored-by: Joakim Erdfelt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
No open projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants