Use of RequestDispatcherForwardAction in a Site Pre-Controller

Options
Can anyone confirm that the RequestDispatcherForwardAction when used in a site pre-controller will allow a forward to a static piece of content only?

When I put in a .page file (or an alias URL) to be forwarded to, I'm getting a 404. If I put in a static image it works perfectly.

Interestingly, the site pre-controller appears to be firing AFTER validating the .page file. For example if you go to http://server:1776/site/invalidpage.page throws a 404 before initiating the site pre-controller class.method. I would think that the controller would fire before anything is processed for the site.

Comments

  • Forward to a page should work, what does your code look like?
    I don't have a way to test right now but I think the code is something like this:

    new URLRedirectForwardAction(context, context.getPageLink(page));
    I agree with you on the behavior of site controllers, they only get invoked when you hit a valid page.
  • I just trimmed down our pre-controller to redirect all LiveSite pages to what is stored in the controller's parameter 'redirectTo'.

    (Please note I give this code, which I believe works, as an example for others to get their feet wet. This pre-controller does not work in preview mode because of it's over simplicity and brute force approach.)

    [PHP]
    package com.company.livesite.precontrollers;

    import com.interwoven.livesite.common.web.ForwardAction;
    import com.interwoven.livesite.runtime.RequestContext;
    import com.interwoven.livesite.common.web.forward.target.ContextRelativeTarget;
    import com.interwoven.livesite.common.web.RequestDispatcherForwardAction;

    public class SitePreControllers {
    public ForwardAction redirect(RequestContext context) {
    String redirectUrl = context.getParameterString("redirectTo");
    ContextRelativeTarget crt = new ContextRelativeTarget(redirectUrl);
    ForwardAction faction = new RequestDispatcherForwardAction(crt);
    return faction;
    }
    }
    [/PHP]

    If I put /images/smiley_face.gif as the redirectTo parameter, I get the smiley face.
    If I put /site/abc.page as the redirectTo parameter, I get a 404 - /site/abc.page not found (yes it's there and does work without the controller in place.) Adding the context.getPageLink(...) doesn't help the situation.

    So back to my original statement - it appears that pre-controllers can not 'ForwardAction' using a RequestDispatcherForwardAction object to a different .page page. It works just fine to static content (.pdf, images, .html...) but not to dynamic pages. Does anyone know differently?

    Also I disagree - if the .page file is not found I would like to pre-controller to be called, maybe the pre-controller can 'fix the issue'. An added bonus would be to add something to the context indicating the validity of the page being requested.
  • Also I disagree - if the .page file is not found I would like to pre-controller to be called, maybe the pre-controller can 'fix the issue'. An added bonus would be to add something to the context indicating the validity of the page being requested.
    A precontroller on your error page could be configured to do this.
  • Ok - so the "it doesn't fire on error pages" is a minor issue that putting the controller on the error page will fix it.

    The real issue I'm trying to solve is redirecting, without a 302, to a .page file.
  • Maybe try having your precontroller method return a ContextRedirectForwardAction with fullRedirect=false. That triggers a RequestDispatcher.forward(request, response), which *should* internally come back in as any other request and trigger all layers of the code.
  • ContextRedirectForwardAction has been deprecated in v7.2.1
  • Gah! Sorry. My experience getting LS to do crazy things is dated (LS3.1).
    / I've got nothin you couldn't figure out on your own then
  • Balamurugan Jayabalan
    edited November 4, 2019 #9
    Options

    @Denise, any luck of using RequestDispatcherForwardAction in pre-controllers for .pages/friendly URLS?

TeamSite Developer Resources

  • Docker Automation

  • LiveSite Content Services (LSCS) REST API

  • Single Page Application (SPA) Modules

  • TeamSite Add-ons

If you are interested in gaining full access to the content, you can register for a My Support account here.
image
OpenText CE Products
TeamSite
APIs