use of io.undertow.server.handlers.resource.Resource in project undertow by undertow-io.
the class ServletPathMatches method getServletHandlerByPath.
public ServletPathMatch getServletHandlerByPath(final String path) {
ServletPathMatch existing = pathMatchCache.get(path);
if (existing != null) {
return existing;
}
ServletPathMatch match = getData().getServletHandlerByPath(path);
if (!match.isRequiredWelcomeFileMatch()) {
pathMatchCache.add(path, match);
return match;
}
try {
String remaining = match.getRemaining() == null ? match.getMatched() : match.getRemaining();
Resource resource = resourceManager.getResource(remaining);
if (resource == null || !resource.isDirectory()) {
pathMatchCache.add(path, match);
return match;
}
boolean pathEndsWithSlash = remaining.endsWith("/");
final String pathWithTrailingSlash = pathEndsWithSlash ? remaining : remaining + "/";
ServletPathMatch welcomePage = findWelcomeFile(pathWithTrailingSlash, !pathEndsWithSlash);
if (welcomePage != null) {
pathMatchCache.add(path, welcomePage);
return welcomePage;
} else {
welcomePage = findWelcomeServlet(pathWithTrailingSlash, !pathEndsWithSlash);
if (welcomePage != null) {
pathMatchCache.add(path, welcomePage);
return welcomePage;
} else if (pathEndsWithSlash) {
pathMatchCache.add(path, match);
return match;
} else {
ServletPathMatch redirect = new ServletPathMatch(match.getServletChain(), match.getMatched(), match.getRemaining(), REDIRECT, "/");
pathMatchCache.add(path, redirect);
return redirect;
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.undertow.server.handlers.resource.Resource in project undertow by undertow-io.
the class ServletPathMatches method findWelcomeFile.
private ServletPathMatch findWelcomeFile(final String path, boolean requiresRedirect) {
if (File.separatorChar != '/' && path.contains(File.separator)) {
return null;
}
StringBuilder sb = new StringBuilder();
for (String i : welcomePages) {
try {
sb.append(path);
sb.append(i);
final String mergedPath = sb.toString();
sb.setLength(0);
Resource resource = resourceManager.getResource(mergedPath);
if (resource != null) {
final ServletPathMatch handler = data.getServletHandlerByPath(mergedPath);
return new ServletPathMatch(handler.getServletChain(), mergedPath, null, requiresRedirect ? REDIRECT : REWRITE, mergedPath);
}
} catch (IOException e) {
}
}
return null;
}
use of io.undertow.server.handlers.resource.Resource in project undertow by undertow-io.
the class FilePredicate method resolve.
@Override
public boolean resolve(final HttpServerExchange value) {
String location = this.location.readAttribute(value);
ServletRequestContext src = value.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (src == null) {
return false;
}
ResourceManager manager = src.getDeployment().getDeploymentInfo().getResourceManager();
if (manager == null) {
return false;
}
try {
Resource resource = manager.getResource(location);
if (resource == null) {
return false;
}
return !resource.isDirectory();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.undertow.server.handlers.resource.Resource in project undertow by undertow-io.
the class DirectoryPredicate method resolve.
@Override
public boolean resolve(final HttpServerExchange value) {
String location = this.location.readAttribute(value);
ServletRequestContext src = value.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (src == null) {
return false;
}
ResourceManager manager = src.getDeployment().getDeploymentInfo().getResourceManager();
if (manager == null) {
return false;
}
try {
Resource resource = manager.getResource(location);
if (resource == null) {
return false;
}
return resource.isDirectory();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.undertow.server.handlers.resource.Resource in project spring-boot by spring-projects.
the class JarResourceManagerTests method resourceIsFoundInJarFileWithoutLeadingSlash.
@Test
public void resourceIsFoundInJarFileWithoutLeadingSlash() throws IOException {
Resource resource = this.resourceManager.getResource("hello.txt");
assertThat(resource).isNotNull();
assertThat(resource.isDirectory()).isFalse();
assertThat(resource.getContentLength()).isEqualTo(5);
}
Aggregations