Jetty 12 : Rename resourceBase to baseResource (#8310)

* rename to baseResource
This commit is contained in:
Greg Wilkins 2022-08-15 12:24:13 +10:00 committed by GitHub
parent e0a9c21615
commit af5fecd18d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 189 additions and 123 deletions

View File

@ -94,17 +94,17 @@
* gzip content encoded if a matching resource is
* found ending with ".gz"
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -54,7 +54,7 @@ public class AllowedResourceAliasChecker extends AbstractLifeCycle implements Co
*/
public AllowedResourceAliasChecker(ContextHandler contextHandler)
{
this(contextHandler, contextHandler::getResourceBase);
this(contextHandler, contextHandler::getBaseResource);
}
public AllowedResourceAliasChecker(ContextHandler contextHandler, Resource baseResource)

View File

@ -88,7 +88,7 @@ public class ContextHandler extends Handler.Wrapper implements Attributes, Grace
private String _displayName;
private String _contextPath = "/";
private Resource _resourceBase;
private Resource _baseResource;
private ClassLoader _classLoader;
private Request.Processor _errorProcessor;
private boolean _allowNullPathInContext;
@ -675,9 +675,9 @@ public class ContextHandler extends Handler.Wrapper implements Attributes, Grace
* @return Returns the base resource as a string.
*/
@ManagedAttribute("document root for context")
public Resource getResourceBase()
public Resource getBaseResource()
{
return _resourceBase;
return _baseResource;
}
/**
@ -689,10 +689,9 @@ public class ContextHandler extends Handler.Wrapper implements Attributes, Grace
{
if (isStarted())
throw new IllegalStateException(getState());
_resourceBase = resourceBase;
_baseResource = resourceBase;
}
// TODO inline this ???
public void setBaseResource(Path path)
{
setBaseResource(path == null ? null : ResourceFactory.root().newResource(path));
@ -740,7 +739,7 @@ public class ContextHandler extends Handler.Wrapper implements Attributes, Grace
if (getDisplayName() != null)
b.append(getDisplayName()).append(',');
b.append(getContextPath());
b.append(",b=").append(getResourceBase());
b.append(",b=").append(getBaseResource());
b.append(",a=").append(_availability.get());
if (!vhosts.isEmpty())
@ -833,7 +832,7 @@ public class ContextHandler extends Handler.Wrapper implements Attributes, Grace
@Override
public Resource getBaseResource()
{
return _resourceBase;
return _baseResource;
}
@Override

View File

@ -123,7 +123,7 @@ public class ResourceHandler extends Handler.Wrapper
/**
* @return Returns the resourceBase.
*/
public Resource getResourceBase()
public Resource getBaseResource()
{
return _resourceBase;
}

View File

@ -13,7 +13,6 @@
package org.eclipse.jetty.server.jmx;
import java.io.IOException;
import java.util.List;
import org.eclipse.jetty.jmx.ObjectMBean;
@ -71,8 +70,8 @@ public class AbstractHandlerMBean extends ObjectMBean
name = "ROOT";
}
if (name == null && context.getResourceBase() != null)
name = context.getResourceBase().getPath().getFileName().toString();
if (name == null && context.getBaseResource() != null)
name = context.getBaseResource().getPath().getFileName().toString();
List<String> vhosts = context.getVirtualHosts();
if (vhosts.size() > 0)

View File

@ -1810,7 +1810,7 @@ public class ResourceHandlerTest
_rootResourceHandler.stop();
_rootResourceHandler.setBaseResource(Resource.combine(
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer0/")),
_rootResourceHandler.getResourceBase()));
_rootResourceHandler.getBaseResource()));
_rootResourceHandler.start();
HttpTester.Response response = HttpTester.parseResponse(
@ -1872,7 +1872,7 @@ public class ResourceHandlerTest
_rootResourceHandler.setBaseResource(Resource.combine(
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer0/")),
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePathDir("layer1/")),
_rootResourceHandler.getResourceBase()));
_rootResourceHandler.getBaseResource()));
_rootResourceHandler.start();
HttpTester.Response response = HttpTester.parseResponse(

View File

@ -102,17 +102,17 @@
* If set to a boolean True, then a default set of compressed formats
* will be used, otherwise no precompressed formats.
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -16,7 +16,7 @@ detected.
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- + war OR baseResource -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test.war</Set>

View File

@ -10,7 +10,7 @@ Configure and deploy the test web application
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- + war OR baseResource -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/ee10-test</Set>
<Set name="war"><Property name="jetty.webapps" default="." />/ee10-demo-jetty.war

View File

@ -126,7 +126,7 @@ public abstract class AbstractUnassembledWebAppMojo extends AbstractWebAppMojo
//The first time we run, remember the original base dir
if (originalBaseResource == null)
{
if (webApp.getResourceBase() == null)
if (webApp.getBaseResource() == null)
{
//Use the default static resource location
if (!webAppSourceDirectory.exists())
@ -134,7 +134,7 @@ public abstract class AbstractUnassembledWebAppMojo extends AbstractWebAppMojo
originalBaseResource = ResourceFactory.of(webApp).newResource(webAppSourceDirectory.getCanonicalPath());
}
else
originalBaseResource = webApp.getResourceBase();
originalBaseResource = webApp.getBaseResource();
}
//On every subsequent re-run set it back to the original base dir before
@ -175,11 +175,11 @@ public abstract class AbstractUnassembledWebAppMojo extends AbstractWebAppMojo
}
//Still don't have a web.xml file: try the resourceBase of the webapp, if it is set
if (webApp.getDescriptor() == null && webApp.getResourceBase() != null)
if (webApp.getDescriptor() == null && webApp.getBaseResource() != null)
{
// TODO: should never return from WEB-INF/lib/foo.jar!/WEB-INF/web.xml
// TODO: should also never return from a META-INF/versions/#/WEB-INF/web.xml location
Resource r = webApp.getResourceBase().resolve("WEB-INF/web.xml");
Resource r = webApp.getBaseResource().resolve("WEB-INF/web.xml");
if (r.exists() && !r.isDirectory())
{
webApp.setDescriptor(r.toString());

View File

@ -46,7 +46,7 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
//Iterate over all of the resource bases and ignore any that were original bases, just
//deleting the overlays
Resource res = context.getResourceBase();
Resource res = context.getBaseResource();
if (res instanceof ResourceCollection)
{
for (Resource r : ((ResourceCollection)res).getResources())

View File

@ -47,21 +47,21 @@ public class OverlayManager
for (Overlay o : getOverlays())
{
//can refer to the current project in list of overlays for ordering purposes
if (o.getConfig() != null && o.getConfig().isCurrentProject() && webApp.getResourceBase().exists())
if (o.getConfig() != null && o.getConfig().isCurrentProject() && webApp.getBaseResource().exists())
{
resourceBases.add(webApp.getResourceBase());
resourceBases.add(webApp.getBaseResource());
continue;
}
//add in the selectively unpacked overlay in the correct order to the webapp's resource base
resourceBases.add(unpackOverlay(o));
}
if (!resourceBases.contains(webApp.getResourceBase()) && webApp.getResourceBase().exists())
if (!resourceBases.contains(webApp.getBaseResource()) && webApp.getBaseResource().exists())
{
if (webApp.getBaseAppFirst())
resourceBases.add(0, webApp.getResourceBase());
resourceBases.add(0, webApp.getBaseResource());
else
resourceBases.add(webApp.getResourceBase());
resourceBases.add(webApp.getBaseResource());
}
webApp.setBaseResource(Resource.combine(resourceBases));

View File

@ -105,11 +105,11 @@ public class WebAppPropertyConverter
props.put(TMP_DIR_PERSIST, Boolean.toString(webApp.isPersistTempDirectory()));
//send over the calculated resource bases that includes unpacked overlays
Resource baseResource = webApp.getResourceBase();
Resource baseResource = webApp.getBaseResource();
if (baseResource instanceof ResourceCollection)
props.put(BASE_DIRS, toCSV(((ResourceCollection)webApp.getResourceBase()).getResources()));
props.put(BASE_DIRS, toCSV(((ResourceCollection)webApp.getBaseResource()).getResources()));
else if (baseResource instanceof Resource)
props.put(BASE_DIRS, webApp.getResourceBase().toString());
props.put(BASE_DIRS, webApp.getBaseResource().toString());
//if there is a war file, use that
if (webApp.getWar() != null)

View File

@ -152,9 +152,9 @@ public class TestWebAppPropertyConverter
assertEquals(true, webApp.isPersistTempDirectory());
assertEquals(war.getAbsolutePath(), webApp.getWar());
assertEquals(webXml.getAbsolutePath(), webApp.getDescriptor());
assertThat(webApp.getResourceBase(), instanceOf(ResourceCollection.class));
assertThat(webApp.getBaseResource(), instanceOf(ResourceCollection.class));
ResourceCollection resourceCollection = (ResourceCollection)webApp.getResourceBase();
ResourceCollection resourceCollection = (ResourceCollection)webApp.getBaseResource();
List<URI> actual = resourceCollection.getResources().stream().filter(Objects::nonNull).map(Resource::getURI).toList();
URI[] expected = new URI[]{base1.toURI(), base2.toURI()};
assertThat(actual, containsInAnyOrder(expected));

View File

@ -94,17 +94,17 @@
* gzip content encoded if a matching resource is
* found ending with ".gz"
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -18,7 +18,6 @@ import java.nio.file.Files;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jetty.ee10.annotations.AnnotationConfiguration;
import org.eclipse.jetty.ee10.annotations.AnnotationDecorator;
import org.eclipse.jetty.ee10.webapp.AbstractConfiguration;
import org.eclipse.jetty.ee10.webapp.Configuration;
@ -96,7 +95,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
//check that webapp is suitable for quick start - it is not a packed war
String war = context.getWar();
if (war == null || war.length() <= 0 || !context.getResourceBase().isDirectory())
if (war == null || war.length() <= 0 || !context.getBaseResource().isDirectory())
throw new IllegalStateException("Bad Quickstart location");
//look for quickstart-web.xml in WEB-INF of webapp
@ -233,7 +232,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
Resource webInf = context.getWebInf();
if (webInf == null || !webInf.exists())
{
Files.createDirectories(context.getResourceBase().getPath().resolve("WEB-INF"));
Files.createDirectories(context.getBaseResource().getPath().resolve("WEB-INF"));
webInf = context.getWebInf();
}

View File

@ -151,7 +151,7 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
default -> values.add(value);
}
AttributeNormalizer normalizer = new AttributeNormalizer(context.getResourceBase());
AttributeNormalizer normalizer = new AttributeNormalizer(context.getBaseResource());
// handle values
switch (name)
{
@ -240,7 +240,7 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
//also add to base resource of webapp
List<Resource> collection = new ArrayList<>();
collection.add(context.getResourceBase());
collection.add(context.getBaseResource());
collection.addAll(metaInfResources);
context.setBaseResource(Resource.combine(collection));
}

View File

@ -142,7 +142,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
_originAttribute = DEFAULT_ORIGIN_ATTRIBUTE_NAME;
context.getMetaData().getOrigins();
if (context.getResourceBase() == null)
if (context.getBaseResource() == null)
throw new IllegalArgumentException("No base resource for " + this);
MetaData md = context.getMetaData();
@ -166,7 +166,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
// Set some special context parameters
// The location of the war file on disk
AttributeNormalizer normalizer = new AttributeNormalizer(context.getResourceBase());
AttributeNormalizer normalizer = new AttributeNormalizer(context.getBaseResource());
// The library order
addContextParamFromAttribute(context, out, ServletContext.ORDERED_LIBS);

View File

@ -16,7 +16,7 @@ detected.
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- + war OR baseResource -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/test</Set>

View File

@ -73,6 +73,9 @@ import org.eclipse.jetty.util.resource.ResourceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* TODO restore javadoc
*/
public class DefaultServlet extends HttpServlet
{
private static final Logger LOG = LoggerFactory.getLogger(DefaultServlet.class);
@ -94,8 +97,8 @@ public class DefaultServlet extends HttpServlet
_resourceService = new ServletResourceService(servletContextHandler);
_resourceService.setWelcomeFactory(_resourceService);
_baseResource = servletContextHandler.getResourceBase();
String rb = getInitParameter("resourceBase");
_baseResource = servletContextHandler.getBaseResource();
String rb = getInitParameter("baseResource", "resourceBase");
if (rb != null)
{
try
@ -105,7 +108,7 @@ public class DefaultServlet extends HttpServlet
}
catch (Exception e)
{
LOG.warn("Unable to create resourceBase from {}", rb, e);
LOG.warn("Unable to create baseResource from {}", rb, e);
throw new UnavailableException(e.toString());
}
}
@ -225,6 +228,25 @@ public class DefaultServlet extends HttpServlet
LOG.debug("base resource = {}", _baseResource);
}
private String getInitParameter(String name, String... deprecated)
{
String value = super.getInitParameter(name);
if (value != null)
return value;
for (String d : deprecated)
{
value = super.getInitParameter(d);
if (value != name)
{
LOG.warn("Deprecated {} used instead of {}", d, name);
return value;
}
}
return null;
}
@Override
public void destroy()
{

View File

@ -853,7 +853,7 @@ public class ServletContextHandler extends ContextHandler implements Graceful
if (pathInContext == null || !pathInContext.startsWith(URIUtil.SLASH))
throw new MalformedURLException(pathInContext);
Resource baseResource = getResourceBase();
Resource baseResource = getBaseResource();
if (baseResource == null)
return null;
@ -1235,7 +1235,7 @@ public class ServletContextHandler extends ContextHandler implements Graceful
if (getContextPath() == null)
throw new IllegalStateException("Null contextPath");
Resource baseResource = getResourceBase();
Resource baseResource = getBaseResource();
if (baseResource != null && baseResource.isAlias())
LOG.warn("BaseResource {} is aliased to {} in {}. May not be supported in future releases.",
baseResource, baseResource.getAlias(), this);

View File

@ -197,7 +197,7 @@ public class ServletTester extends ContainerLifeCycle
public Resource getResourceBase()
{
return _context.getResourceBase();
return _context.getBaseResource();
}
public void setResourceBase(Resource base)

View File

@ -29,7 +29,7 @@
<Item>
<New id="defcontext" class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/tests</Set>
<Set name="ResourceBase"><Property name="test.docroot.base"/>/default
<Set name="baseResource"><Property name="test.docroot.base"/>/default
</Set>
<Set name="Handler">
<New id="reshandler" class="org.eclipse.jetty.server.handler.ResourceHandler"/>

View File

@ -47,7 +47,7 @@
<Item>VirtualHost</Item>
</Array>
</Set>
<Set name="ResourceBase"><Property name="test.docroot.base"/>/virtualhost</Set>
<Set name="BaseResource"><Property name="test.docroot.base"/>/virtualhost</Set>
<Set name="Handler"><New id="reshandler1" class="org.eclipse.jetty.server.handler.ResourceHandler"/></Set>
<Set name="DisplayName">virtual</Set>
</New>
@ -55,7 +55,7 @@
<Item>
<New id="defcontext" class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/tests</Set>
<Set name="ResourceBase"><Property name="test.docroot.base"/>/default</Set>
<Set name="BaseResource"><Property name="test.docroot.base"/>/default</Set>
<Set name="Handler"><New id="reshandler2" class="org.eclipse.jetty.server.handler.ResourceHandler"/></Set>
<Set name="DisplayName">default</Set>
</New>

View File

@ -94,17 +94,17 @@
* gzip content encoded if a matching resource is
* found ending with ".gz"
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -94,17 +94,17 @@
* If set to a boolean True, then a default set of compressed formats
* will be used, otherwise no precompressed formats.
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -264,7 +264,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
if (resources != null && !resources.isEmpty())
{
List<Resource> collection = new ArrayList<>();
collection.add(context.getResourceBase());
collection.add(context.getBaseResource());
collection.addAll(resources);
context.setBaseResource(Resource.combine(collection));
}

View File

@ -786,7 +786,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
/**
* @return Returns the war as a file or URL string (Resource).
* The war may be different to the @link {@link #getResourceBase()}
* The war may be different to the @link {@link #getBaseResource()}
* if the war has been expanded and/or copied.
*/
@ManagedAttribute(value = "war file location", readonly = true)
@ -794,9 +794,9 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
{
if (_war == null)
{
if (getResourceBase() != null)
if (getBaseResource() != null)
{
Path warPath = getResourceBase().getPath();
Path warPath = getBaseResource().getPath();
if (warPath != null)
_war = warPath.toUri().toASCIIString();
}
@ -806,7 +806,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
public Resource getWebInf() throws IOException
{
if (getResourceBase() == null)
if (getBaseResource() == null)
return null;
// Is there a WEB-INF directory anywhere in the Resource Base?
@ -814,7 +814,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
// The result could be a ResourceCollection with multiple WEB-INF directories
// Can return from WEB-INF/lib/foo.jar!/WEB-INF
// Can also never return from a META-INF/versions/#/WEB-INF location
Resource webInf = getResourceBase().resolve("WEB-INF/");
Resource webInf = getBaseResource().resolve("WEB-INF/");
if (!webInf.exists() || !webInf.isDirectory())
return null;
@ -929,9 +929,9 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
else
name = _war;
}
else if (getResourceBase() != null)
else if (getBaseResource() != null)
{
name = getResourceBase().getURI().toASCIIString();
name = getBaseResource().getURI().toASCIIString();
int webapps = name.indexOf("/webapps/");
if (webapps >= 0)
name = name.substring(webapps + 8);

View File

@ -281,9 +281,9 @@ public class WebInfConfiguration extends AbstractConfiguration
public void unpack(WebAppContext context) throws IOException
{
Resource webApp = context.getResourceBase();
Resource webApp = context.getBaseResource();
_resourceFactory = ResourceFactory.closeable();
_preUnpackBaseResource = context.getResourceBase();
_preUnpackBaseResource = context.getBaseResource();
if (webApp == null)
{
@ -291,7 +291,7 @@ public class WebInfConfiguration extends AbstractConfiguration
if (war != null && war.length() > 0)
webApp = context.newResource(war);
else
webApp = context.getResourceBase();
webApp = context.getBaseResource();
if (webApp == null)
throw new IllegalStateException("No resourceBase or war set for context");
@ -516,7 +516,7 @@ public class WebInfConfiguration extends AbstractConfiguration
// Resource base
try
{
Resource resource = context.getResourceBase();
Resource resource = context.getBaseResource();
if (resource == null)
{
if (context.getWar() == null || context.getWar().length() == 0)

View File

@ -16,7 +16,7 @@ detected.
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- + war OR baseResource -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/ee9-demo-jetty.war</Set>

View File

@ -10,7 +10,7 @@ Configure and deploy the test web application
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- + war OR baseResource -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/ee8-test</Set>
<Set name="war"><Property name="jetty.webapps" default="." />/ee8-demo-jetty.war

View File

@ -102,17 +102,17 @@
* If set to a boolean True, then a default set of compressed formats
* will be used, otherwise no precompressed formats.
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -102,17 +102,17 @@
* If set to a boolean True, then a default set of compressed formats
* will be used, otherwise no precompressed formats.
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -16,7 +16,7 @@ detected.
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- + war OR baseResource -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/ee9-demo-jetty.war</Set>

View File

@ -10,7 +10,7 @@ Configure and deploy the test web application
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- + war OR baseResource -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/ee9-test</Set>
<Set name="war"><Property name="jetty.webapps" default="." />/ee9-demo-jetty.war

View File

@ -61,7 +61,7 @@ public class AllowedResourceAliasChecker extends AbstractLifeCycle implements Co
protected void initialize()
{
_base = _contextHandler.getCoreContextHandler().getResourceBase().getPath();
_base = _contextHandler.getCoreContextHandler().getBaseResource().getPath();
if (_base == null)
return;

View File

@ -1144,7 +1144,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
*/
public Resource getBaseResource()
{
return _coreContextHandler.getResourceBase();
return _coreContextHandler.getBaseResource();
}
/**
@ -1153,7 +1153,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
@ManagedAttribute("document root for context")
public String getResourceBase()
{
Resource resourceBase = _coreContextHandler.getResourceBase();
Resource resourceBase = _coreContextHandler.getBaseResource();
return resourceBase == null ? null : resourceBase.toString();
}
@ -1168,12 +1168,25 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
_coreContextHandler.setBaseResource(base);
}
/**
* Set the base resource for this context.
*
* @param base The resource used as the base for all static content of this context.
* @see #setResourceBase(String)
*/
public void setBaseResource(Path base)
{
_coreContextHandler.setBaseResource(base);
}
/**
* Set the base resource for this context.
*
* @param resourceBase A string representing the base resource for the context. Any string accepted by {@link ResourceFactory#newResource(String)} may be passed and the
* call is equivalent to <code>setBaseResource(newResource(resourceBase));</code>
* @deprecated use #setBaseResource
*/
@Deprecated
public void setResourceBase(String resourceBase)
{
try
@ -1398,7 +1411,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
if (pathInContext == null || !pathInContext.startsWith(URIUtil.SLASH))
throw new MalformedURLException(pathInContext);
Resource baseResource = _coreContextHandler.getResourceBase();
Resource baseResource = _coreContextHandler.getBaseResource();
if (baseResource == null)
return null;

View File

@ -15,6 +15,7 @@ package org.eclipse.jetty.ee9.nested;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -193,6 +194,7 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory,
/**
* @return Returns the base resource as a string.
*/
@Deprecated
public String getResourceBase()
{
if (_baseResource == null)
@ -319,6 +321,15 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory,
_baseResource = base;
}
/**
* @param basePath The resourceBase to server content from. If null the
* context resource base is used.
*/
public void setBaseResource(Path basePath)
{
setBaseResource(ResourceFactory.root().newResource(basePath));
}
/**
* @param cacheControl the cacheControl header to set on all static content.
*/
@ -395,7 +406,9 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory,
/**
* @param resourceBase The base resource as a string.
* @deprecated use {@link #setBaseResource(Resource)}
*/
@Deprecated
public void setResourceBase(String resourceBase)
{
try

View File

@ -94,17 +94,17 @@
* gzip content encoded if a matching resource is
* found ending with ".gz"
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -125,7 +125,7 @@ public class PreconfigureQuickStartWar
XmlConfiguration xmlConfiguration = new XmlConfiguration(xml);
xmlConfiguration.configure(webapp);
}
webapp.setResourceBase(dir.getPath().toAbsolutePath().toString());
webapp.setBaseResource(dir.getPath().toAbsolutePath());
server.setHandler(webapp);
try
{

View File

@ -16,7 +16,7 @@ detected.
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Required minimal context configuration : -->
<!-- + contextPath -->
<!-- + war OR resourceBase -->
<!-- + war OR baseResource -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Set name="contextPath">/test</Set>

View File

@ -83,17 +83,17 @@ import org.slf4j.LoggerFactory;
* If set to a boolean True, then a default set of compressed formats
* will be used, otherwise no precompressed formats.
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.
@ -136,7 +136,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc
private boolean _welcomeServlets = false;
private boolean _welcomeExactServlets = false;
private Resource _resourceBase;
private Resource _baseResource;
private CachedContentFactory _cache;
private MimeTypes _mimeTypes;
@ -144,7 +144,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc
private ResourceFactory.Closeable _resourceFactory;
private Resource _stylesheet;
private boolean _useFileMappedBuffer = false;
private String _relativeResourceBase;
private String _relativeBaseResource;
private ServletHandler _servletHandler;
public DefaultServlet(ResourceService resourceService)
@ -188,20 +188,20 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc
_useFileMappedBuffer = getInitBoolean("useFileMappedBuffer", _useFileMappedBuffer);
_relativeResourceBase = getInitParameter("relativeResourceBase");
_relativeBaseResource = getInitParameter("relativeBaseResource", "relativeResourceBase");
String rb = getInitParameter("resourceBase");
if (rb != null)
String br = getInitParameter("baseResource", "resourceBase");
if (br != null)
{
if (_relativeResourceBase != null)
throw new UnavailableException("resourceBase & relativeResourceBase");
if (_relativeBaseResource != null)
throw new UnavailableException("baseResource & relativeBaseResource");
try
{
_resourceBase = _contextHandler.newResource(rb);
_baseResource = _contextHandler.newResource(br);
}
catch (Exception e)
{
LOG.warn("Unable to create resourceBase from {}", rb, e);
LOG.warn("Unable to create baseResource from {}", br, e);
throw new UnavailableException(e.toString());
}
}
@ -248,7 +248,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc
{
if (maxCacheSize != -1 || maxCachedFileSize != -2 || maxCachedFiles != -2)
LOG.debug("ignoring resource cache configuration, using resourceCache attribute");
if (_relativeResourceBase != null || _resourceBase != null)
if (_relativeBaseResource != null || _baseResource != null)
throw new UnavailableException("resourceCache specified with resource bases");
_cache = (CachedContentFactory)_servletContext.getAttribute(resourceCache);
}
@ -305,7 +305,26 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc
_servletHandler = _contextHandler.getChildHandlerByClass(ServletHandler.class);
if (LOG.isDebugEnabled())
LOG.debug("resource base = {}", _resourceBase);
LOG.debug("resource base = {}", _baseResource);
}
private String getInitParameter(String name, String... deprecated)
{
String value = super.getInitParameter(name);
if (value != null)
return value;
for (String d : deprecated)
{
value = super.getInitParameter(d);
if (value != name)
{
LOG.warn("Deprecated {} used instead of {}", d, name);
return value;
}
}
return null;
}
private CompressedContentFormat[] parsePrecompressedFormats(String precompressed, Boolean gzip, CompressedContentFormat[] dft)
@ -431,14 +450,14 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc
subUriPath = URIUtil.encodePath(subUriPath);
Resource r = null;
if (_relativeResourceBase != null)
subUriPath = URIUtil.addPaths(_relativeResourceBase, subUriPath);
if (_relativeBaseResource != null)
subUriPath = URIUtil.addPaths(_relativeBaseResource, subUriPath);
try
{
if (_resourceBase != null)
if (_baseResource != null)
{
r = _resourceBase.resolve(subUriPath);
r = _baseResource.resolve(subUriPath);
if (!_contextHandler.checkAlias(subUriPath, r))
r = null;
}

View File

@ -203,11 +203,13 @@ public class ServletTester extends ContainerLifeCycle
_context.setBaseResource(resource);
}
@Deprecated
public String getResourceBase()
{
return _context.getResourceBase();
}
@Deprecated
public void setResourceBase(String resourceBase)
{
_context.setResourceBase(resourceBase);

View File

@ -94,7 +94,7 @@ public class DispatcherTest
_contextHandler.setContextPath("/context");
_contextCollection.addHandler(_contextHandler);
_resourceHandler = new ResourceHandler();
_resourceHandler.setResourceBase(MavenTestingUtils.getTargetFile("test-classes/dispatchResourceTest").getAbsolutePath());
_resourceHandler.setBaseResource(MavenTestingUtils.getTargetFile("test-classes/dispatchResourceTest").toPath());
_resourceHandler.setPathInfoOnly(true);
ContextHandler resourceContextHandler = new ContextHandler("/resource");
resourceContextHandler.setHandler(_resourceHandler);

View File

@ -29,7 +29,7 @@
<Item>
<New id="defcontext" class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/tests</Set>
<Set name="ResourceBase"><Property name="test.docroot.base"/>/default
<Set name="baseResource"><Property name="test.docroot.base"/>/default
</Set>
<Set name="Handler">
<New id="reshandler" class="org.eclipse.jetty.server.handler.ResourceHandler"/>

View File

@ -47,7 +47,7 @@
<Item>VirtualHost</Item>
</Array>
</Set>
<Set name="ResourceBase"><Property name="test.docroot.base"/>/virtualhost</Set>
<Set name="BaseResource"><Property name="test.docroot.base"/>/virtualhost</Set>
<Set name="Handler"><New id="reshandler1" class="org.eclipse.jetty.server.handler.ResourceHandler"/></Set>
<Set name="DisplayName">virtual</Set>
</New>
@ -55,7 +55,7 @@
<Item>
<New id="defcontext" class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/tests</Set>
<Set name="ResourceBase"><Property name="test.docroot.base"/>/default</Set>
<Set name="baseResource"><Property name="test.docroot.base"/>/default</Set>
<Set name="Handler"><New id="reshandler2" class="org.eclipse.jetty.server.handler.ResourceHandler"/></Set>
<Set name="DisplayName">default</Set>
</New>

View File

@ -94,17 +94,17 @@
* gzip content encoded if a matching resource is
* found ending with ".gz"
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -102,17 +102,17 @@
* If set to a boolean True, then a default set of compressed formats
* will be used, otherwise no precompressed formats.
*
* resourceBase Set to replace the context resource base
* baseResource Set to replace the context resource base
*
* resourceCache If set, this is a context attribute name, which the servlet
* will use to look for a shared ResourceCache instance.
*
* relativeResourceBase
* relativeBaseResource
* Set with a pathname relative to the base of the
* servlet context root. Useful for only serving static content out
* of only specific subdirectories.
*
* pathInfoOnly If true, only the path info will be applied to the resourceBase
* pathInfoOnly If true, only the path info will be applied to the baseResource
*
* stylesheet Set with the location of an optional stylesheet that will be used
* to decorate the directory listing html.

View File

@ -100,7 +100,7 @@ public class WSServer extends LocalServer implements LocalFuzzer.Provider
context = new WebAppContext();
context.setContextPath("/" + contextName);
context.setInitParameter("org.eclipse.jetty.ee9.servlet.Default.dirAllowed", "false");
context.setResourceBase(contextDir.toAbsolutePath().toString());
context.setBaseResource(contextDir.toAbsolutePath());
context.setAttribute("org.eclipse.jetty.websocket.jakarta", Boolean.TRUE);
context.addConfiguration(new JakartaWebSocketConfiguration());
}