2

I have a DXA Java 1.5 development environment with Web 8.1.1. In this environment I need to merge DXA with an existing Static Website. If my existing pages have a jsp extension when I request those directly the response returns with the page as I was hoping. If I request a page that has an html or htm extension DXA tries to get the page from the broker. I thought that if I created a filter then mapped it in the web.xml this would forward the request appropriately to the Static htm or html on the filesystem but, I end up with the same DXA Error Page as I did without the Filter that states:

"The page you were looking for cannot be found. This page may have been moved. We apologize for any inconvenience. "

I have 2 folders in the Static Website that contain htm and html files and I need to be able to have these files served as is. What can I do to enable this to happen?

2 Answers 2

4

SDL DXA, out of the box, has a PageController with the following Request Mapping

@RequestMapping(value = "/**", produces = {MediaType.TEXT_HTML_VALUE, MediaType.ALL_VALUE})

This is handling ALL request, regardless of extension

This could be updated to look like

@RequestMapping(value = { "/**/*.jsp", "/**/*.html", "/**/*.txt", "/**/*.xml" }, method = { GET })

However, you will also need to modify your web.xml, which tells Spring MVC which urls to dispatch to the dispatcher (usually further defined in dispatcher-servlet.xml), for example mine reads as below. It is telling Spring MVC to handle all of these requests

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/navigation/*</url-pattern>
    <url-pattern>/system/*</url-pattern>
    <url-pattern>*.html</url-pattern>
    <url-pattern>*.jsp</url-pattern>
    <url-pattern>*.txt</url-pattern>
    <url-pattern>*.dcp</url-pattern>
    <url-pattern>*.png</url-pattern>
    <url-pattern>*.jpg</url-pattern>
    <url-pattern>*.gif</url-pattern>
    <url-pattern>*.jpeg</url-pattern>
    <url-pattern>*.pdf</url-pattern>
    <url-pattern>*.vcf</url-pattern>
    <url-pattern>*.swf</url-pattern>
    <url-pattern>*.zip</url-pattern>
    <url-pattern>*.xls</url-pattern>
    <url-pattern>*.xlsx</url-pattern>
</servlet-mapping>

I also have, as I want to ignore some JSPs, this to tell String MVC NOT to handle JSPs in /WEB-INF/views/

<servlet-mapping>
   <servlet-name>default</servlet-name>
   <url-pattern>/WEB-INF/views/*</url-pattern>
</servlet-mapping>

I think in your situation just removing <url-pattern>*.html</url-pattern> would be enough to allow all HTML files to "pass through" and be resolved from the file-system.

Update following @Troy's comment

To exclude 2 folders of HTML files I'd try the following

Create web.xml file in your project - mine looks like this https://gist.github.com/chrismrgn/fdc1ec017664aeca0ef1ab70f72cc895

Then replace:

<servlet-mapping>
   <servlet-name>default</servlet-name>
   <url-pattern>/WEB-INF/views/*</url-pattern>
</servlet-mapping>

With:

<servlet-mapping>
   <servlet-name>default</servlet-name>
   <url-pattern>/html-folder-1/*</url-pattern>
   <url-pattern>/html-folder-2/*</url-pattern>
</servlet-mapping>

Hope that helps?

4
  • thanks for your input. Pages that are published from CM are by default .html pages so this poses a problem globally. I need to exclude 2 folders from being handled by the PageController or the Dispatcher. I tried configuring the Interceptors to exclude given paths but that did not work. I do not have a web.xml currently defined beyond having my filter (did not accomplish my goal)and there is only one xml file for the webapp (spring-context.xml). Commented Oct 27, 2016 at 14:56
  • Updated my answer Commented Oct 27, 2016 at 20:07
  • Thanks Chris. I will play around with things this way. For right now I have added some new validations in com.sdl.webapp.common.impl.localization.LocalizationImpl Commented Oct 27, 2016 at 20:20
  • These validations check for a set of configuration parameters I added in the Site Configuration component. If it matches any of the values from there it returns true for isStaticContent Commented Oct 27, 2016 at 20:38
1

I have seen a similar implementation in .NET using HTTPModules (extending System.Web.IHttpModule). We just load this before DXA StaticContent Module (Sdl.Web.Mvc.Statics.StaticContentModule - in DXA 1.2 we could not extend this) so we fall back to the broker if the request cannot be served by an item in the filesystem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.