cancel
Showing results for 
Search instead for 
Did you mean: 

Static Pages

tonyc
Champ in-the-making
Champ in-the-making
Hello,

I'm trying to bypass the wcmqs URL inteceptor and allow the page requested to be handled by surf.

In handlerMappings there is a defaultHandler property that seems to allow for this but I cannot get it to work

<property name="staticPages">
     <set>
          <value>\/messages\.js</value>
     </set>
</property>

I have a page called test.xml that I want to load through surf

I have tried adding..


<value>\/test.xml</value>
<value>\/test</value>
<value>\/page\/test.xml</value>
<value>\/page\/test</value>

With no luck, anyone have any ideas?

Thanks
4 REPLIES 4

bremmington
Champ on-the-rise
Champ on-the-rise
The pattern that you need is "\/test\.xml" (the '.' needs escaping in a regular expression), but there is another adjustment needed for this to work.

In the file "wcmqs-webapp-context.xml" (or in an overriding context file), remove the suffix property from the "staticPageViewResolver" bean so it looks like this:

    <bean id="staticPageViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/"/>
    </bean>

and then alter the "exceptionResolver" bean so that its defaultErrorView property becomes "500page.html" and its errorPageSuffix property becomes "page.html":

<bean id="exceptionResolver" class="org.alfresco.wcm.client.exceptionresolver.RepositoryExceptionResolver">
        <property name="serviceRegistry" ref="webframework.service.registry"/>
        <property name="modelDecorator" ref="modelDecorator"/>
        <property name="assetFactory" ref="assetFactory"/>
        <property name="errorPageSuffix" value="page.html"/>
        <property name="defaultErrorView" value="500page.html"/>
</bean>

We'll make those adjustments in a future release.

bremmington
Champ on-the-rise
Champ on-the-rise
Just to be clear, you should place your test.xml file in the WEB-INF folder, and it should then be delivered when "http://localhost:8080/wcmqs/test.xml" is requested.

tonyc
Champ in-the-making
Champ in-the-making
So this will only work to load a static resource I take it.  This will not allow us to bypass the wqs interceptor and use the regular surf inteceptor?

bremmington
Champ on-the-rise
Champ on-the-rise
I'm not entirely sure whether you really mean interceptor or controller. I've no idea what experience you have with Spring MVC, so forgive me if the rest of this post is all obvious to you.

In Spring MVC, controllers are typically mapped to URLs. Controllers are also referred to as handlers, and are responsible for doing the necessary processing of the received request prior to Spring then trying to determine which view to use to render the response. Surf sets up a number of controller mappings by default which are defined in an abstract bean named "webframeworkHandlerMappings" in the Surf context file "spring-surf-mvc-context.xml". WQS defines another bean named "handlerMappings" that extends the default Surf bean. This does a couple of things such as include a couple of interceptors to set up WQS-specific data prior to the controller being invoked and defines the WQS controller as the default one. The interceptors act a little like servlet filters - you can configure any number of them on each controller-mapping bean, and Spring will invoke them before invoking the relevant controller.

The default WQS controller is a basic extension of the normal Surf default controller. It checks whether the WQS interceptor has been able to resolve the URL to an asset in the repo. If it hasn't then it then checks to see if the requested URL matches any of the patterns defined as "static". These are regular expressions, so you can be fairly creative with them. If the controller finds a match with any of these then it simply defers processing to the default Surf controller, otherwise it returns a 404.

The default Surf controller doesn't really do very much (it is basically a standard Spring UrlFilenameViewController). It is the view resolvers that do the magic.

If your "test.xml" file is a Surf page definition, then simply change the entry in the "staticPages" to be simply "\/test" and make a request to "http://localhost:8080/wcmqs/test". The correct view resolver should kick in (the Surf PageViewResolver in this case), because it should recognise "test" as the id of a Surf page. You should then see your test page render.

To extend that a little, let's say you want any request for a URI starting "/mysurfpages/" to map to your custom Surf pages (so "/mysurfpages/abcdefg" should render a Surf page with the id "abcdefg"). There are a couple of steps needed to make that happen. First of all you need to add a new pattern to the staticPages property of the default controller:

        <property name="defaultHandler">
           <bean class="org.alfresco.wcm.client.controller.GenericTemplateAssetController">
               <!–  List of pages which we don't want to look up in the repository. These will be handled by Surf instead. –>           
               <property name="staticPages">
                  <set>
                       <value>\/messages\.js</value>
                       <value>\/mysurfpages\/.*</value>
                  </set>
               </property>
           </bean>           
       </property>

Secondly (and finally) you need to add a URI template to the Surf config file (surf.xml in the WEB-INF folder):

    <config evaluator="string-compare" condition="UriTemplate">
      <uri-templates>
        <uri-template id="mysurfpages">/mysurfpages/{pageid}</uri-template>
      </uri-templates>
    </config>

If, after a restart, you then make a request for "/wcmqs/mysurfpages/test" then you should see your test page render (assuming, again, that "test" is the id of your Surf page).

Hope this helps.