<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I appreciate the suggestion, but that sounded a bit indirect …<div class=""><br class=""></div><div class="">Instead I copied File/PathResource/Manager into new classes MappedPathResource/Manager, ripped out all the things that aren’t relevant in this case (like symlink support, case sensitivity, and watching the file system). The result is simpler than expected: the Resource class is basically identical to PathResource (minus pointer type back to the manager), and the new MappedPathResourceManager is just 150 lines or so. Here’s how to use it:</div><div class=""><br class=""></div><div class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String,Path&gt; mappings = new HashMap&lt;&gt;();</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; // insert some test data</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; mappings.put( "/foo", Paths.get( System.getProperty("user.home") + "/.bashrc" ));</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; Undertow server = Undertow.builder()</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addHttpListener(8080, "localhost")</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .setHandler(</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new ResourceHandler(</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new MappedPathResourceManager( mappings )))</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .build();</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; server.start();</div></div><div class=""><br class=""></div><div class="">and it seems to work and serve my purposes.</div><div class=""><br class=""></div><div class="">Code is here:&nbsp;<a href="https://github.com/jernst/undertow-mappedpathresource" class="">https://github.com/jernst/undertow-mappedpathresource</a></div><div class=""><br class=""></div><div class="">Q: Is that something that would be of use to anybody else? If so, I’d be happy to clean up the code and submit a PR.</div><div class=""><br class=""></div><div class="">P.S Ideally a bit a refactoring should be done so that PathResource and MappedPathResource share the same code (all these inner classes and threaded-related behavior) but that would require some kind of intermediate superclass that collects functionality common to PathResourceManager and MappedPathResourceManager.</div><div class=""><br class=""></div><div class="">P.S.2: I like Undertow. Give what kind of $%*&amp;WQ@)$^&amp; web servers there are in Java land …</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Johannes.</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 6, 2018, at 16:01, Stuart Douglas &lt;<a href="mailto:sdouglas@redhat.com" class="">sdouglas@redhat.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">You could possibly use&nbsp;io.undertow.server.handlers.resource.ResourceSupplier, and then use PathResourceManager under the hood to actually return a path resource. If all these files have a common root path you could basically create a PathResourceManager that maps to this, and then use Map&lt;String, Resource&gt; in the supplier.<div class=""><br class=""></div><div class="">Stuart</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Feb 6, 2018 at 9:06 PM, Johannes Ernst <span dir="ltr" class="">&lt;<a href="mailto:jernst@indiecomputing.com" target="_blank" class="">jernst@indiecomputing.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I’m attempting to serve a bunch of static files, which exist in the file system, but in various directories that do not correspond to the URL namespace. Example:<br class="">
<br class="">
<a href="http://example.com/foo/one" rel="noreferrer" target="_blank" class="">http://example.com/foo/one</a>&nbsp; =&gt;&nbsp; /var/lib/one/bar<br class="">
<a href="http://example.com/foo/two" rel="noreferrer" target="_blank" class="">http://example.com/foo/two</a>&nbsp; =&gt;&nbsp; /var/lib/two/bar<br class="">
<br class="">
I have the mapping from incoming request URL to File to be served in a Map&lt;String,File&gt;. Now I’m attempting to hook up Undertow so it can serve those files according to my mapping, and I’m not entirely sure where to best plug this in without having to write loads of code.<br class="">
<br class="">
As far as I can tell, I would need to implement my version of ResourceManager and Resource, sort of like File/PathResource/Manager, but there’s a lot of code there, not all of which I understand, and it would perhaps turn into a maintenance nightmare on my end.<br class="">
<br class="">
I cannot see a straightforward way of overriding those classes either to “slide in” an alternate mapping.<br class="">
<br class="">
Is there a better way of doing this?<br class="">
<br class="">
Thanks,<br class="">
<br class="">
<br class="">
<br class="">
Johannes.<br class="">
<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
undertow-dev mailing list<br class="">
<a href="mailto:undertow-dev@lists.jboss.org" class="">undertow-dev@lists.jboss.org</a><br class="">
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" rel="noreferrer" target="_blank" class="">https://lists.jboss.org/<wbr class="">mailman/listinfo/undertow-dev</a></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>