1

How to redirect to a static (present in the file system) 404 error page in DXA 1.5 (Java), When we did custom static folder path request filter based on the request path (Ex: http://localhost:9080/cp/test/fafd) in DXA 1.5 (Java)

/*  Ex - in core.json 
   "existingPaths":"/css/,/cp/,/media/,/components/"
*/

As per my client requrement, We have implemneted the static file path request filter based on the request path (Ex: http://localhost:9080/cp/test/fafd) it shoud show custom error 404 page which is available in file system but it's showing blank screen

The scope of the implementation is; if any of the request path match with the "existingPaths" in core.json those request will not check the pages in Broker DB. the static request filter is working fine but when I request invalid path it's showing blank screen instead of custom 404 page

our implementation in com.sdl.webapp.common.impl.localization:

public class LocalizationImpl implements Localization
{
//...

    /* We have implemented the static folder request filter based on the request path after domain (Ex: )
        // Ex - in core.json 
       "existingPaths":"/css/,/cp/,/media/,/components/"
    */

    public boolean isStaticContent(String url)
       {
            if (!url.startsWith(path)) {
               return false;
             }
             if (url.startsWith(mediaRoot)) {
              return true;
           }

        int endIndex = url.indexOf("/", url.indexOf("/") + 1);
         if (endIndex > 0) {
          String folderPath = url.substring(0, endIndex + 1);
           List<String> existingPaths = getExistingPath();
           if (existingPaths.contains(folderPath)) {
            LOG.trace("LocalizationImpl: isStaticContent : folderPath - {} ", folderPath);
             return true;
           }
         }

        String p = path.equals("/") ? url : url.substring(path.length());
        return (p.equals("/favicon.ico")) || (SYSTEM_ASSETS_PATTERN.matcher(p).matches());
   }

    public List<String> getExistingPath()
       {
        String[] straExistingPath = getConfiguration("core.existingPaths").split("(\\s*)?,(\\s*)?");

        List<String> listExistingPath = Arrays.asList(straExistingPath);
         return listExistingPath;
       }

//...

}

The related implementation reference - How to redirect to a static (present in file system) 404 error page in DXA 1.5 Java instead of error-404.html

I'm getting the blank screen when I request invalid page: EX- enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.