485712 - Quickstart web.xml is absolute
This commit is contained in:
parent
a7b3a9f481
commit
e2a0794d91
|
@ -22,6 +22,9 @@ package org.eclipse.jetty.quickstart;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
|
@ -55,6 +58,7 @@ import org.eclipse.jetty.servlet.ServletMapping;
|
||||||
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.eclipse.jetty.util.security.Constraint;
|
import org.eclipse.jetty.util.security.Constraint;
|
||||||
import org.eclipse.jetty.webapp.MetaData;
|
import org.eclipse.jetty.webapp.MetaData;
|
||||||
import org.eclipse.jetty.webapp.MetaData.OriginInfo;
|
import org.eclipse.jetty.webapp.MetaData.OriginInfo;
|
||||||
|
@ -128,16 +132,16 @@ public class QuickStartDescriptorGenerator
|
||||||
// Set some special context parameters
|
// Set some special context parameters
|
||||||
|
|
||||||
// The location of the war file on disk
|
// The location of the war file on disk
|
||||||
String resourceBase = _webApp.getBaseResource().getFile().getCanonicalFile().getAbsoluteFile().toURI().toString();
|
AttributeNormalizer normalizer = new AttributeNormalizer(_webApp.getBaseResource());
|
||||||
|
|
||||||
// The library order
|
// The library order
|
||||||
addContextParamFromAttribute(out,ServletContext.ORDERED_LIBS);
|
addContextParamFromAttribute(out,ServletContext.ORDERED_LIBS);
|
||||||
//the servlet container initializers
|
//the servlet container initializers
|
||||||
addContextParamFromAttribute(out,AnnotationConfiguration.CONTAINER_INITIALIZERS);
|
addContextParamFromAttribute(out,AnnotationConfiguration.CONTAINER_INITIALIZERS);
|
||||||
//the tlds discovered
|
//the tlds discovered
|
||||||
addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_TLDS,resourceBase);
|
addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_TLDS,normalizer);
|
||||||
//the META-INF/resources discovered
|
//the META-INF/resources discovered
|
||||||
addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_RESOURCES,resourceBase);
|
addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_RESOURCES,normalizer);
|
||||||
|
|
||||||
|
|
||||||
// init params
|
// init params
|
||||||
|
@ -515,7 +519,27 @@ public class QuickStartDescriptorGenerator
|
||||||
*/
|
*/
|
||||||
private void addContextParamFromAttribute(XmlAppendable out, String attribute) throws IOException
|
private void addContextParamFromAttribute(XmlAppendable out, String attribute) throws IOException
|
||||||
{
|
{
|
||||||
addContextParamFromAttribute(out,attribute,null);
|
Object o = _webApp.getAttribute(attribute);
|
||||||
|
if (o == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Collection<?> c = (o instanceof Collection)? (Collection<?>)o:Collections.singletonList(o);
|
||||||
|
StringBuilder v=new StringBuilder();
|
||||||
|
for (Object i:c)
|
||||||
|
{
|
||||||
|
if (i!=null)
|
||||||
|
{
|
||||||
|
if (v.length()>0)
|
||||||
|
v.append(",\n ");
|
||||||
|
else
|
||||||
|
v.append("\n ");
|
||||||
|
QuotedStringTokenizer.quote(v,i.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.openTag("context-param")
|
||||||
|
.tag("param-name",attribute)
|
||||||
|
.tagCDATA("param-value",v.toString())
|
||||||
|
.closeTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -526,7 +550,7 @@ public class QuickStartDescriptorGenerator
|
||||||
* @param resourceBase
|
* @param resourceBase
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void addContextParamFromAttribute(XmlAppendable out, String attribute, String resourceBase) throws IOException
|
private void addContextParamFromAttribute(XmlAppendable out, String attribute, AttributeNormalizer normalizer) throws IOException
|
||||||
{
|
{
|
||||||
Object o = _webApp.getAttribute(attribute);
|
Object o = _webApp.getAttribute(attribute);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
|
@ -542,16 +566,14 @@ public class QuickStartDescriptorGenerator
|
||||||
v.append(",\n ");
|
v.append(",\n ");
|
||||||
else
|
else
|
||||||
v.append("\n ");
|
v.append("\n ");
|
||||||
if (resourceBase==null)
|
QuotedStringTokenizer.quote(v,normalizer.normalize(i));
|
||||||
QuotedStringTokenizer.quote(v,i.toString());
|
|
||||||
else
|
|
||||||
QuotedStringTokenizer.quote(v,i.toString().replace(resourceBase,"${WAR}/"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.openTag("context-param")
|
out.openTag("context-param")
|
||||||
.tag("param-name",attribute)
|
.tag("param-name",attribute)
|
||||||
.tagCDATA("param-value",v.toString())
|
.tagCDATA("param-value",v.toString())
|
||||||
.closeTag();
|
.closeTag();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -99,6 +99,7 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
values.add(value);
|
values.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AttributeNormalizer normalizer = new AttributeNormalizer(context.getBaseResource());
|
||||||
// handle values
|
// handle values
|
||||||
switch(name)
|
switch(name)
|
||||||
{
|
{
|
||||||
|
@ -125,15 +126,14 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
case MetaInfConfiguration.METAINF_TLDS:
|
case MetaInfConfiguration.METAINF_TLDS:
|
||||||
{
|
{
|
||||||
List<Object> tlds = new ArrayList<>();
|
List<Object> tlds = new ArrayList<>();
|
||||||
String war=context.getBaseResource().getURI().toString();
|
|
||||||
Object o=context.getAttribute(MetaInfConfiguration.METAINF_TLDS);
|
Object o=context.getAttribute(MetaInfConfiguration.METAINF_TLDS);
|
||||||
if (o instanceof Collection<?>)
|
if (o instanceof Collection<?>)
|
||||||
tlds.addAll((Collection<?>)o);
|
tlds.addAll((Collection<?>)o);
|
||||||
for (String i : values)
|
for (String i : values)
|
||||||
{
|
{
|
||||||
Resource r = Resource.newResource(i.replace("${WAR}/",war));
|
Resource r = Resource.newResource(normalizer.expand(i));
|
||||||
if (r.exists())
|
if (r.exists())
|
||||||
tlds.add(r.getURL());
|
tlds.add(r.getURI().toURL());
|
||||||
else
|
else
|
||||||
throw new IllegalArgumentException("TLD not found: "+r);
|
throw new IllegalArgumentException("TLD not found: "+r);
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,9 @@ public class QuickStartDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
|
|
||||||
case MetaInfConfiguration.METAINF_RESOURCES:
|
case MetaInfConfiguration.METAINF_RESOURCES:
|
||||||
{
|
{
|
||||||
String war=context.getBaseResource().getURI().toString();
|
|
||||||
for (String i : values)
|
for (String i : values)
|
||||||
{
|
{
|
||||||
Resource r = Resource.newResource(i.replace("${WAR}/",war));
|
Resource r = Resource.newResource(normalizer.expand(i));
|
||||||
if (r.exists())
|
if (r.exists())
|
||||||
visitMetaInfResource(context,r);
|
visitMetaInfResource(context,r);
|
||||||
else
|
else
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testAddPath() throws Exception
|
public void testAddPath() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
|
|
||||||
Path subdir = dir.resolve("sub");
|
Path subdir = dir.resolve("sub");
|
||||||
FS.ensureDirExists(subdir.toFile());
|
FS.ensureDirExists(subdir.toFile());
|
||||||
|
@ -240,7 +240,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testAddRootPath() throws Exception
|
public void testAddRootPath() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Path subdir = dir.resolve("sub");
|
Path subdir = dir.resolve("sub");
|
||||||
Files.createDirectories(subdir);
|
Files.createDirectories(subdir);
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testIsContainedIn() throws Exception
|
public void testIsContainedIn() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
Path foo = dir.resolve("foo");
|
Path foo = dir.resolve("foo");
|
||||||
Files.createFile(foo);
|
Files.createFile(foo);
|
||||||
|
@ -303,7 +303,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testIsDirectory() throws Exception
|
public void testIsDirectory() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
Path foo = dir.resolve("foo");
|
Path foo = dir.resolve("foo");
|
||||||
Files.createFile(foo);
|
Files.createFile(foo);
|
||||||
|
@ -324,7 +324,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testLastModified() throws Exception
|
public void testLastModified() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
File file = testdir.getFile("foo");
|
File file = testdir.getFile("foo");
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testLastModified_NotExists() throws Exception
|
public void testLastModified_NotExists() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
|
|
||||||
try (Resource base = newResource(dir.toFile()))
|
try (Resource base = newResource(dir.toFile()))
|
||||||
{
|
{
|
||||||
|
@ -352,7 +352,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testLength() throws Exception
|
public void testLength() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path file = dir.resolve("foo");
|
Path file = dir.resolve("foo");
|
||||||
|
@ -375,7 +375,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testLength_NotExists() throws Exception
|
public void testLength_NotExists() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
try (Resource base = newResource(dir.toFile()))
|
try (Resource base = newResource(dir.toFile()))
|
||||||
|
@ -388,7 +388,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception
|
public void testDelete() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
Path file = dir.resolve("foo");
|
Path file = dir.resolve("foo");
|
||||||
Files.createFile(file);
|
Files.createFile(file);
|
||||||
|
@ -408,7 +408,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testDelete_NotExists() throws Exception
|
public void testDelete_NotExists() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
try (Resource base = newResource(dir.toFile()))
|
try (Resource base = newResource(dir.toFile()))
|
||||||
|
@ -426,7 +426,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testName() throws Exception
|
public void testName() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
String expected = dir.toAbsolutePath().toString();
|
String expected = dir.toAbsolutePath().toString();
|
||||||
|
@ -440,7 +440,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testInputStream() throws Exception
|
public void testInputStream() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path file = dir.resolve("foo");
|
Path file = dir.resolve("foo");
|
||||||
|
@ -466,7 +466,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testReadableByteChannel() throws Exception
|
public void testReadableByteChannel() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path file = dir.resolve("foo");
|
Path file = dir.resolve("foo");
|
||||||
|
@ -495,7 +495,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testGetURI() throws Exception
|
public void testGetURI() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path file = dir.resolve("foo");
|
Path file = dir.resolve("foo");
|
||||||
|
@ -514,7 +514,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testGetURL() throws Exception
|
public void testGetURL() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path file = dir.resolve("foo");
|
Path file = dir.resolve("foo");
|
||||||
|
@ -532,7 +532,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testList() throws Exception
|
public void testList() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Files.createFile(dir.resolve("foo"));
|
Files.createFile(dir.resolve("foo"));
|
||||||
|
@ -561,7 +561,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testSymlink() throws Exception
|
public void testSymlink() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
|
|
||||||
Path foo = dir.resolve("foo");
|
Path foo = dir.resolve("foo");
|
||||||
Path bar = dir.resolve("bar");
|
Path bar = dir.resolve("bar");
|
||||||
|
@ -601,7 +601,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testNonExistantSymlink() throws Exception
|
public void testNonExistantSymlink() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path foo = dir.resolve("foo");
|
Path foo = dir.resolve("foo");
|
||||||
|
@ -644,7 +644,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testCaseInsensitiveAlias() throws Exception
|
public void testCaseInsensitiveAlias() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
Path path = dir.resolve("file");
|
Path path = dir.resolve("file");
|
||||||
Files.createFile(path);
|
Files.createFile(path);
|
||||||
|
@ -681,7 +681,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testCase8dot3Alias() throws Exception
|
public void testCase8dot3Alias() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path path = dir.resolve("TextFile.Long.txt");
|
Path path = dir.resolve("TextFile.Long.txt");
|
||||||
|
@ -718,7 +718,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testNTFSFileStreamAlias() throws Exception
|
public void testNTFSFileStreamAlias() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path path = dir.resolve("testfile");
|
Path path = dir.resolve("testfile");
|
||||||
|
@ -761,7 +761,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testNTFSFileDataStreamAlias() throws Exception
|
public void testNTFSFileDataStreamAlias() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path path = dir.resolve("testfile");
|
Path path = dir.resolve("testfile");
|
||||||
|
@ -806,7 +806,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testNTFSFileEncodedDataStreamAlias() throws Exception
|
public void testNTFSFileEncodedDataStreamAlias() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path path = dir.resolve("testfile");
|
Path path = dir.resolve("testfile");
|
||||||
|
@ -843,7 +843,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testSemicolon() throws Exception
|
public void testSemicolon() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -868,7 +868,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testSingleQuote() throws Exception
|
public void testSingleQuote() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -894,7 +894,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testSingleBackTick() throws Exception
|
public void testSingleBackTick() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -923,7 +923,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testBrackets() throws Exception
|
public void testBrackets() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -949,7 +949,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testBraces() throws Exception
|
public void testBraces() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -978,7 +978,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testCaret() throws Exception
|
public void testCaret() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -1007,7 +1007,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testPipe() throws Exception
|
public void testPipe() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -1040,13 +1040,13 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testExist_Normal() throws Exception
|
public void testExist_Normal() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path path = dir.resolve("a.jsp");
|
Path path = dir.resolve("a.jsp");
|
||||||
Files.createFile(path);
|
Files.createFile(path);
|
||||||
|
|
||||||
URI ref = testdir.getDir().toURI().resolve("a.jsp");
|
URI ref = testdir.getPath().toUri().resolve("a.jsp");
|
||||||
try (Resource fileres = newResource(ref))
|
try (Resource fileres = newResource(ref))
|
||||||
{
|
{
|
||||||
assertThat("Resource: " + fileres,fileres.exists(),is(true));
|
assertThat("Resource: " + fileres,fileres.exists(),is(true));
|
||||||
|
@ -1056,7 +1056,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testSingleQuoteInFileName() throws Exception
|
public void testSingleQuoteInFileName() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path fooA = dir.resolve("foo's.txt");
|
Path fooA = dir.resolve("foo's.txt");
|
||||||
|
@ -1121,7 +1121,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testExist_BadURINull() throws Exception
|
public void testExist_BadURINull() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path path = dir.resolve("a.jsp");
|
Path path = dir.resolve("a.jsp");
|
||||||
|
@ -1130,7 +1130,7 @@ public class FileSystemResourceTest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// request with null at end
|
// request with null at end
|
||||||
URI uri = testdir.getDir().toURI().resolve("a.jsp%00");
|
URI uri = testdir.getPath().toUri().resolve("a.jsp%00");
|
||||||
assertThat("Null URI",uri,notNullValue());
|
assertThat("Null URI",uri,notNullValue());
|
||||||
|
|
||||||
Resource r = newResource(uri);
|
Resource r = newResource(uri);
|
||||||
|
@ -1147,7 +1147,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testExist_BadURINullX() throws Exception
|
public void testExist_BadURINullX() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path path = dir.resolve("a.jsp");
|
Path path = dir.resolve("a.jsp");
|
||||||
|
@ -1156,7 +1156,7 @@ public class FileSystemResourceTest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// request with null and x at end
|
// request with null and x at end
|
||||||
URI uri = testdir.getDir().toURI().resolve("a.jsp%00x");
|
URI uri = testdir.getPath().toUri().resolve("a.jsp%00x");
|
||||||
assertThat("NullX URI",uri,notNullValue());
|
assertThat("NullX URI",uri,notNullValue());
|
||||||
|
|
||||||
Resource r = newResource(uri);
|
Resource r = newResource(uri);
|
||||||
|
@ -1173,7 +1173,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testEncoding() throws Exception
|
public void testEncoding() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
|
|
||||||
Path specials = dir.resolve("a file with,spe#ials");
|
Path specials = dir.resolve("a file with,spe#ials");
|
||||||
|
@ -1192,7 +1192,7 @@ public class FileSystemResourceTest
|
||||||
@Test
|
@Test
|
||||||
public void testUtf8Dir() throws Exception
|
public void testUtf8Dir() throws Exception
|
||||||
{
|
{
|
||||||
Path dir = testdir.getDir().toPath().normalize().toRealPath();
|
Path dir = testdir.getPath().normalize().toRealPath();
|
||||||
Path utf8Dir = dir.resolve("bãm");
|
Path utf8Dir = dir.resolve("bãm");
|
||||||
Files.createDirectories(utf8Dir);
|
Files.createDirectories(utf8Dir);
|
||||||
|
|
||||||
|
@ -1209,4 +1209,6 @@ public class FileSystemResourceTest
|
||||||
assertThat("Alias: " + r,r,hasNoAlias());
|
assertThat("Alias: " + r,r,hasNoAlias());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,10 @@ package org.eclipse.jetty.quickstart;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.NetworkConnector;
|
import org.eclipse.jetty.server.NetworkConnector;
|
||||||
|
@ -33,6 +35,7 @@ import org.eclipse.jetty.webapp.WebDescriptor;
|
||||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||||
import org.eclipse.jetty.xml.XmlParser.Node;
|
import org.eclipse.jetty.xml.XmlParser.Node;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class QuickStartTest
|
public class QuickStartTest
|
||||||
|
@ -176,4 +179,73 @@ public class QuickStartTest
|
||||||
|
|
||||||
server.stop();
|
server.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNormalize() throws Exception
|
||||||
|
{
|
||||||
|
String jetty_base=System.getProperty("jetty.base");
|
||||||
|
String jetty_home=System.getProperty("jetty.home");
|
||||||
|
String user_home=System.getProperty("user.home");
|
||||||
|
String user_dir=System.getProperty("user.dir");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
System.setProperty("jetty.home","/opt/jetty-distro");
|
||||||
|
System.setProperty("jetty.base","/opt/jetty-distro/demo.base");
|
||||||
|
System.setProperty("user.home","/home/user");
|
||||||
|
System.setProperty("user.dir","/etc/init.d");
|
||||||
|
AttributeNormalizer normalizer = new AttributeNormalizer(Resource.newResource("/opt/jetty-distro/demo.base/webapps/root"));
|
||||||
|
|
||||||
|
String[][] tests = {
|
||||||
|
{ "WAR", "/opt/jetty-distro/demo.base/webapps/root" },
|
||||||
|
{ "jetty.home", "/opt/jetty-distro" },
|
||||||
|
{ "jetty.base", "/opt/jetty-distro/demo.base" },
|
||||||
|
{ "user.home", "/home/user" },
|
||||||
|
{ "user.dir", "/etc/init.d" },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String[] test : tests)
|
||||||
|
{
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize("file:"+test[1]));
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize("file:"+test[1]+"/"));
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}/file",normalizer.normalize("file:"+test[1]+"/file"));
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize(new URI("file:"+test[1])));
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize(new URI("file:"+test[1]+"/")));
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}/file",normalizer.normalize(new URI("file:"+test[1]+"/file")));
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize(new URL("file:"+test[1])));
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize(new URL("file:"+test[1]+"/")));
|
||||||
|
Assert.assertEquals("file:${"+test[0]+"}/file",normalizer.normalize(new URL("file:"+test[1]+"/file")));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize("jar:file:"+test[1]+"!/file"));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize("jar:file:"+test[1]+"/!/file"));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}/file!/file",normalizer.normalize("jar:file:"+test[1]+"/file!/file"));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize(new URI("jar:file:"+test[1]+"!/file")));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize(new URI("jar:file:"+test[1]+"/!/file")));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}/file!/file",normalizer.normalize(new URI("jar:file:"+test[1]+"/file!/file")));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize(new URL("jar:file:"+test[1]+"!/file")));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize(new URL("jar:file:"+test[1]+"/!/file")));
|
||||||
|
Assert.assertEquals("jar:file:${"+test[0]+"}/file!/file",normalizer.normalize(new URL("jar:file:"+test[1]+"/file!/file")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (user_dir==null)
|
||||||
|
System.clearProperty("user.dir");
|
||||||
|
else
|
||||||
|
System.setProperty("user.dir",user_dir);
|
||||||
|
|
||||||
|
if (user_home==null)
|
||||||
|
System.clearProperty("user.home");
|
||||||
|
else
|
||||||
|
System.setProperty("user.home",user_home);
|
||||||
|
|
||||||
|
if (jetty_home==null)
|
||||||
|
System.clearProperty("jetty.home");
|
||||||
|
else
|
||||||
|
System.setProperty("jetty.home",jetty_home);
|
||||||
|
|
||||||
|
if (jetty_base==null)
|
||||||
|
System.clearProperty("jetty.base");
|
||||||
|
else
|
||||||
|
System.setProperty("jetty.base",jetty_base);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue