/**
 * @license
 * Copyright 2019 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.nanos.servlet;

import foam.util.SafetyUtil;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.text.StringEscapeUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ResourceImageServlet
  extends ImageServlet
{
  @Override
  protected void service(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    System.out.println("ResourceImageServlet.service uri: "+req.getRequestURI());
    String request = req.getRequestURI().replaceFirst("/?images/?", "/");
    System.out.println("ResourceImageServlet.service request: "+request);
    // tried a few prefixes, /images, /webapp/images, images/, 
    InputStream is = getClass().getResourceAsStream("images/"+request);
    if ( is != null ) {
      String ext = EXTS.get(request.substring(request.lastIndexOf('.') +1));
      try ( BufferedInputStream bis = new BufferedInputStream(is) ) {
        resp.setContentType(!SafetyUtil.isEmpty(ext) ? ext : DEFAULT_EXT);
        resp.setHeader("Content-Disposition", "filename=\"" + StringEscapeUtils.escapeHtml4(request) + "\"");
        //resp.setContentLengthLong(src.length());

        IOUtils.copy(bis, resp.getOutputStream());
        return;
      }
    } else {
      System.out.println("ResourceImageServlet.service is: null");
    }
    resp.sendError(resp.SC_NOT_FOUND);
  }
}

@@ -253,24 +253,148 @@
 io.IOUtils;%0A
+/**%0A * @license%0A * Copyright 2019 The FOAM Authors. All Rights Reserved.%0A * http://www.apache.org/licenses/LICENSE-2.0%0A */%0A%0A
 import org.a
@@ -744,16 +744,329 @@
 l.Map;%0A%0A
+/**%0A   Image lookup assumes images are places at the root of the jar file.%0A   During build, generally output/copied to classes/%0A   HTTPServlet setups the resourcebase using webroot, but so far that%0A   setup requires explicit knowledge of the webroot folder name, which%0A   needs to be prepended to the request.%0A*/%0A
 public c
@@ -1090,16 +1090,17 @@
 eServlet
+ 
 %0A  exten
@@ -1116,16 +1116,18 @@
 ervlet%0A%7B
+  
 %0A  @Over
@@ -1255,90 +1255,8 @@
   %7B%0A
-    System.out.println(%22ResourceImageServlet.service uri: %22+req.getRequestURI());%0A
     
@@ -1295,46 +1295,16 @@
 RI()
-.replaceFirst(%22/?images/?%22, %22/%22)
 ;%0A    
+//
 Syst
@@ -1352,92 +1352,37 @@
 ice 
-request: %22+request);%0A    // tried a few prefixes, /images, /webapp/images, images/, 
+uri: %22+req.getRequestURI());%0A
 %0A   
@@ -1434,18 +1434,8 @@
 eam(
-%22images/%22+
 requ
@@ -1799,59 +1799,8 @@
 %22%22);
-%0A        //resp.setContentLengthLong(src.length());
 %0A%0A  
@@ -1875,16 +1875,19 @@
    %7D%0A   
+ //
  %7D else 
@@ -1892,16 +1892,18 @@
 e %7B%0A    
+//
   System
@@ -1949,16 +1949,32 @@
 ice 
-is: null
+'%22+request+%22' not found.
 %22);%0A

Remove explicit reference to webroot.