[undertow-dev] Serving an Individual File

electrotype electrotype at gmail.com
Mon Oct 17 01:32:15 EDT 2016


I use a custom ResourceManager to serve a specific file from the classpath. Something like :

-------------------------------------

public class FileClassPathResourceManagerDefault implements ResourceManager {

     private final String filePath;

     public FileClassPathResourceManagerDefault(String filePath) {
         this.filePath = filePath;
     }

     protected String getFilePath() {
         return this.filePath;
     }

     @Override
     public Resource getResource(String path) throws IOException {

         final URL resource = getClass().getClassLoader().getResource(getFilePath());
         if(resource == null) {
             return null;
         } else {
             return new URLResource(resource, resource.openConnection(), getFilePath());
         }
     }

     @Override
     public boolean isResourceChangeListenerSupported() {
         return false;
     }

     @Override
     public void registerResourceChangeListener(ResourceChangeListener listener) {
         throw UndertowMessages.MESSAGES.resourceChangeListenerNotSupported();
     }

     @Override
     public void removeResourceChangeListener(ResourceChangeListener listener) {
         throw UndertowMessages.MESSAGES.resourceChangeListenerNotSupported();
     }

     @Override
     public void close() throws IOException {
     }
}

-------------------------------------


Hope it helps.


On 2016-10-16 21:54, Hicks, Matt wrote:
> The ResourceManager is great for serving directories, but if I have a very specific file I want to 
> serve up is there any built-in functionality to conveniently do so? I've looked through the 
> documentation and the examples and can't seem to find any references to doing this.  Help would be 
> greatly appreciated.
>
> Thanks
>
>
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20161017/75663fca/attachment.html 


More information about the undertow-dev mailing list