Skip to content

Commit

Permalink
Pull up as default method since it avoids API compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaucher committed Jun 28, 2023
1 parent c340b6a commit d1f0c34
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
22 changes: 21 additions & 1 deletion java/org/apache/catalina/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.apache.catalina;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;
import java.util.Map;
Expand All @@ -39,6 +41,7 @@
import org.apache.tomcat.util.descriptor.web.FilterMap;
import org.apache.tomcat.util.descriptor.web.LoginConfig;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.apache.tomcat.util.file.ConfigFileLoader;
import org.apache.tomcat.util.file.ConfigurationSource.Resource;
import org.apache.tomcat.util.http.CookieProcessor;

Expand Down Expand Up @@ -1982,5 +1985,22 @@ void setAllowMultipleLeadingForwardSlashInPath(
* @return the resource
* @throws IOException if an error occurs or if the resource does not exist
*/
Resource findConfigFileResource(String name) throws IOException;
default Resource findConfigFileResource(String name) throws IOException {
if (name.startsWith(WEBAPP_PROTOCOL)) {
String path = name.substring(WEBAPP_PROTOCOL.length());
WebResource resource = getResources().getResource(path);
if (resource.canRead()) {
InputStream stream = resource.getInputStream();
try {
return new Resource(stream, resource.getURL().toURI());
} catch (URISyntaxException e) {
stream.close();
}
}
return null;
} else {
return ConfigFileLoader.getSource().getResource(name);
}
}

}
22 changes: 0 additions & 22 deletions java/org/apache/catalina/core/StandardContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -128,8 +127,6 @@
import org.apache.tomcat.util.descriptor.web.MessageDestination;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.apache.tomcat.util.file.ConfigFileLoader;
import org.apache.tomcat.util.file.ConfigurationSource.Resource;
import org.apache.tomcat.util.http.CookieProcessor;
import org.apache.tomcat.util.http.Rfc6265CookieProcessor;
import org.apache.tomcat.util.scan.StandardJarScanner;
Expand Down Expand Up @@ -3500,25 +3497,6 @@ public String[] findWrapperListeners() {
}


@Override
public Resource findConfigFileResource(String name) throws IOException {
if (name.startsWith(WEBAPP_PROTOCOL)) {
String path = name.substring(WEBAPP_PROTOCOL.length());
WebResource resource = getResources().getResource(path);
if (resource.canRead()) {
InputStream stream = resource.getInputStream();
try {
return new Resource(stream, resource.getURL().toURI());
} catch (URISyntaxException e) {
stream.close();
}
}
return null;
} else {
return ConfigFileLoader.getSource().getResource(name);
}
}

/**
* Reload this web application, if reloading is supported.
* <p>
Expand Down
4 changes: 0 additions & 4 deletions java/org/apache/catalina/startup/FailedContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -62,7 +61,6 @@
import org.apache.tomcat.util.descriptor.web.FilterMap;
import org.apache.tomcat.util.descriptor.web.LoginConfig;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.apache.tomcat.util.file.ConfigurationSource.Resource;
import org.apache.tomcat.util.http.CookieProcessor;
import org.apache.tomcat.util.res.StringManager;

Expand Down Expand Up @@ -853,6 +851,4 @@ public void setDispatcherWrapsSameObject(boolean dispatcherWrapsSameObject) {}
@Override
public void setParallelAnnotationScanning(boolean parallelAnnotationScanning) {}

@Override
public Resource findConfigFileResource(String name) throws IOException { return null; }
}
4 changes: 0 additions & 4 deletions test/org/apache/tomcat/unittest/TesterContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -65,7 +64,6 @@
import org.apache.tomcat.util.descriptor.web.FilterMap;
import org.apache.tomcat.util.descriptor.web.LoginConfig;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.apache.tomcat.util.file.ConfigurationSource.Resource;
import org.apache.tomcat.util.http.CookieProcessor;

/**
Expand Down Expand Up @@ -1323,6 +1321,4 @@ public void setParallelAnnotationScanning(boolean parallelAnnotationScanning) {}
@Override
public void setMetadataComplete(boolean metadataComplete) { /* NO-OP */ }

@Override
public Resource findConfigFileResource(String name) throws IOException { return null; }
}

3 comments on commit d1f0c34

@michael-o
Copy link
Member

@michael-o michael-o commented on d1f0c34 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't this is required on main because we are still in dev mode (Mx), so API can break here, no? Just like the Java 21 requirement.

@ChristopherSchultz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still a good idea to provide default (especially if obvious/helpful) implementations when introducing new interface methods.

@michael-o
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still a good idea to provide default (especially if obvious/helpful) implementations when introducing new interface methods.

I agree on the default, but StandardContext should overrwrite to provide reasonable messages here. As we do with the rest.

Please sign in to comment.