Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix some issues with the Undertow resource manager #5945

Closed
wants to merge 2 commits into from

3 participants

@stuartwdouglas

No description provided.

@wildfly-ci
Collaborator

Build 2748 is now running using a merge of 713010a

@wildfly-ci
Collaborator

Build 2748 outcome was SUCCESS using a merge of 713010a
Summary: Tests passed: 5592, ignored: 75 Build time: 1:36:02

@bstansberry
Owner

Other than the copyright header, looks good.

@bstansberry
Owner

I'm fixing the copyright header (and a bunch of other missing ones) as part of merging.

@bstansberry
Owner

Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
100 undertow/src/main/java/org/wildfly/extension/undertow/deployment/ServletResource.java
@@ -0,0 +1,100 @@
+package org.wildfly.extension.undertow.deployment;
+
+import io.undertow.io.IoCallback;
+import io.undertow.io.Sender;
+import io.undertow.server.HttpServerExchange;
+import io.undertow.server.handlers.resource.Resource;
+import io.undertow.util.ETag;
+import io.undertow.util.MimeMappings;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Date;
+import java.util.List;
+
+/**
+ *
+ * Resource implementation that wraps an underlying resource, and overrides the list() method to take overlays into account.
+ *
+ * @author Stuart Douglas
+ */
+public class ServletResource implements Resource {
+
+ private final ServletResourceManager resourceManager;
+ private final Resource underlying;
+
+ public ServletResource(ServletResourceManager resourceManager, Resource underlying) {
+ this.resourceManager = resourceManager;
+ this.underlying = underlying;
+ }
+
+ @Override
+ public String getPath() {
+ return underlying.getPath();
+ }
+
+ @Override
+ public Date getLastModified() {
+ return underlying.getLastModified();
+ }
+
+ @Override
+ public String getLastModifiedString() {
+ return underlying.getLastModifiedString();
+ }
+
+ @Override
+ public ETag getETag() {
+ return underlying.getETag();
+ }
+
+ @Override
+ public String getName() {
+ return underlying.getName();
+ }
+
+ @Override
+ public boolean isDirectory() {
+ return underlying.isDirectory();
+ }
+
+ @Override
+ public List<Resource> list() {
+ return resourceManager.list(getPath());
+ }
+
+ @Override
+ public String getContentType(MimeMappings mimeMappings) {
+ return underlying.getContentType(mimeMappings);
+ }
+
+ @Override
+ public void serve(Sender sender, HttpServerExchange exchange, IoCallback completionCallback) {
+ underlying.serve(sender, exchange, completionCallback);
+ }
+
+ @Override
+ public Long getContentLength() {
+ return underlying.getContentLength();
+ }
+
+ @Override
+ public String getCacheKey() {
+ return underlying.getCacheKey();
+ }
+
+ @Override
+ public File getFile() {
+ return underlying.getFile();
+ }
+
+ @Override
+ public File getResourceManagerRoot() {
+ return underlying.getResourceManagerRoot();
+ }
+
+ @Override
+ public URL getUrl() {
+ return underlying.getUrl();
+ }
+}
View
44 undertow/src/main/java/org/wildfly/extension/undertow/deployment/ServletResourceManager.java
@@ -1,7 +1,9 @@
package org.wildfly.extension.undertow.deployment;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import io.undertow.server.handlers.resource.FileResourceManager;
import io.undertow.server.handlers.resource.Resource;
@@ -30,17 +32,17 @@ public ServletResourceManager(final VirtualFile resourcesRoot, final Collection<
public Resource getResource(final String path) throws IOException {
Resource res = deploymentResourceManager.getResource(path);
if (res != null) {
- return res;
+ return new ServletResource(this, res);
}
String p = path;
if (p.startsWith("/")) {
p = p.substring(1);
}
- if(overlays != null) {
+ if (overlays != null) {
for (VirtualFile overlay : overlays) {
VirtualFile child = overlay.getChild(p);
if (child.exists()) {
- return new VirtualFileResource(child, path);
+ return new ServletResource(this, new VirtualFileResource(overlay.getPhysicalFile(), child, path));
}
}
}
@@ -66,4 +68,40 @@ public void removeResourceChangeListener(ResourceChangeListener listener) {
public void close() throws IOException {
deploymentResourceManager.close();
}
+
+ /**
+ * Lists all children of a particular path, taking overlays into account
+ * @param path The path
+ * @return The list of children
+ */
+ public List<Resource> list(String path) {
+ try {
+ final List<Resource> ret = new ArrayList<>();
+
+ Resource res = deploymentResourceManager.getResource(path);
+ if (res != null) {
+ for (Resource child : res.list()) {
+ ret.add(new ServletResource(this, child));
+ }
+ }
+ String p = path;
+ if (p.startsWith("/")) {
+ p = p.substring(1);
+ }
+ if (overlays != null) {
+ for (VirtualFile overlay : overlays) {
+ VirtualFile child = overlay.getChild(p);
+ if (child.exists()) {
+ VirtualFileResource vfsResource = new VirtualFileResource(overlay.getPhysicalFile(), child, path);
+ for (Resource c : vfsResource.list()) {
+ ret.add(new ServletResource(this, c));
+ }
+ }
+ }
+ }
+ return ret;
+ } catch (IOException e) {
+ throw new RuntimeException(e); //this method really should have thrown IOException
+ }
+ }
}
View
8 undertow/src/main/java/org/wildfly/extension/undertow/deployment/VirtualFileResource.java
@@ -29,10 +29,12 @@
*/
public class VirtualFileResource implements Resource {
+ private final File resourceManagerRoot;
private final VirtualFile file;
private final String path;
- public VirtualFileResource(final VirtualFile file, String path) {
+ public VirtualFileResource(File resourceManagerRoot, final VirtualFile file, String path) {
+ this.resourceManagerRoot = resourceManagerRoot;
this.file = file;
this.path = path;
}
@@ -75,7 +77,7 @@ public boolean isDirectory() {
public List<Resource> list() {
final List<Resource> resources = new ArrayList<Resource>();
for (VirtualFile child : file.getChildren()) {
- resources.add(new VirtualFileResource(child, path));
+ resources.add(new VirtualFileResource(resourceManagerRoot, child, path));
}
return resources;
}
@@ -226,7 +228,7 @@ public File getFile() {
@Override
public File getResourceManagerRoot() {
- return null;
+ return resourceManagerRoot;
}
@Override
Something went wrong with that request. Please try again.