You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/08/28 20:04:31 UTC

[isis] branch master updated: ISIS-1901: slash prefix is mandatory

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 435cc59  ISIS-1901: slash prefix is mandatory
435cc59 is described below

commit 435cc59c39f104147693e78992de4ae4696d621d
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Aug 28 22:04:28 2018 +0200

    ISIS-1901: slash prefix is mandatory
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1901
---
 .../isis/core/webapp/content/ResourceServlet.java  | 29 ++++++++++++----------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/core/metamodel/src/main/java/org/apache/isis/core/webapp/content/ResourceServlet.java b/core/metamodel/src/main/java/org/apache/isis/core/webapp/content/ResourceServlet.java
index 9cbc215..7220aa8 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/webapp/content/ResourceServlet.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/webapp/content/ResourceServlet.java
@@ -20,6 +20,7 @@
 package org.apache.isis.core.webapp.content;
 
 import static org.apache.isis.commons.internal.base._Strings.pair;
+import static org.apache.isis.commons.internal.base._Strings.prefix;
 import static org.apache.isis.commons.internal.base._With.ifPresentElse;
 import static org.apache.isis.commons.internal.base._With.ifPresentElseGet;
 
@@ -51,20 +52,22 @@ import org.apache.isis.core.commons.lang.StringExtensions;
 @WebServlet(
         urlPatterns = { 
                 "*.css", "*.png", "*.jpg", "*.jpeg", "*.gif", "*.svg", "*.js", "*.html", "*.swf" }
-)
+        )
 public class ResourceServlet extends HttpServlet {
 
     private static final Logger LOG = LoggerFactory.getLogger(ResourceServlet.class);
     private static final long serialVersionUID = 1L;
     private ResourceServlet_HtmlTemplateVariables templateVariables;
-    
+
     @Override
     public void init(ServletConfig config) throws ServletException {
         super.init(config);
-        
+
         final String restfulPath = ifPresentElse(_Resource.getRestfulPathIfAny(), "restful");
         final String restfulBase = _Resource.prependContextPathIfPresent(restfulPath);
-        templateVariables = new ResourceServlet_HtmlTemplateVariables(pair("restful-base", restfulBase));
+        templateVariables = new ResourceServlet_HtmlTemplateVariables(
+                pair("restful-base", prefix(restfulBase, "/"))
+                );
     }
 
     @Override
@@ -76,7 +79,7 @@ public class ResourceServlet extends HttpServlet {
     protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
         processRequest(request, response);
     }
-    
+
     // -- HELPER
 
     private void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
@@ -86,10 +89,10 @@ public class ResourceServlet extends HttpServlet {
         final InputStream is = ifPresentElseGet(
                 ResourceUtil.getResourceAsStream(request), // try to load from file-system first 
                 ()->ResourceUtil.getResourceAsStream(servletPath)); // otherwise, try to load from class-path  
-        
+
         if (is != null) {
             LOG.debug("request: {} loaded from classpath", servletPath );
-            
+
             try {
                 writeContentType(request, response);
                 processContent(is, request, response);
@@ -107,19 +110,19 @@ public class ResourceServlet extends HttpServlet {
             final HttpServletRequest request, 
             final HttpServletResponse response) 
                     throws IOException {
-        
+
         if(request.getServletPath().endsWith(".template.html")) {
-            
+
             final String templateContent = _Strings.ofBytes(_Bytes.of(is), StandardCharsets.UTF_8);
             final String htmlContent = templateVariables.applyTo(templateContent);
-                        
+
             response.getWriter().append(htmlContent);
-            
+
         } else {
-            
+
             // direct copy
             InputStreamExtensions.copyTo(is, response.getOutputStream());
-            
+
         }
     }