[MAGNOLIA-5656] MutliSite applicable regex based VirtualURIMapping needed. Created: 06/Feb/14  Updated: 06/May/14  Resolved: 28/Feb/14

Status: Closed
Project: Magnolia
Component/s: core
Affects Version/s: 4.5.15, 5.2.2
Fix Version/s: 4.5.17, 5.2.3

Type: Improvement Priority: Neutral
Reporter: Christian Ringele Assignee: Roman Kovařík
Resolution: Fixed Votes: 0
Labels: maintenance, support
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
causality
is causing MAGNOLIA-5731 HostBasedVirtualURIMapping does not w... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

Situation:
In a multi site system using domain mappings the possibility of regular

The RegexpVirtualURIMapping implementation is not very applicable, as no selector in the URL can be used for applying the pattern only for a certain site. The handle prefix is mapped away by the domain.
Therefore the pattern would apply to all sites with the same paths detected.

The possibility of using a HostBasedVirtualURIMapping solves the problem of reacting to the mapped domain as selector. But the HostBasedVirtualURIMapping is not regex capable. So fort redirecting the parameters as described in this support ticket SUPPORT-3223 is not a usable solution.

A new kind of VirtualURIMApping which is either hostbased & regex capable or uses some other sort of site definition mapping/selector would help in many multi site situations.



 Comments   
Comment by Jan Haderka [ 06/Feb/14 ]

HostBasedVirtualURIMapping:

    public void setFromURI(String fromURI) {
        this.fromURI = fromURI;
        this.pattern = new SimpleUrlPattern(fromURI);
    }

    public MappingResult mapURI(String uri) {
        String destination = toURI;
        if (pattern != null && pattern.match(uri)) {
...

SimpleUrlPattern:

    /**
     * @see info.magnolia.cms.util.UrlPattern#match(java.lang.String)
     */
    @Override
    public boolean match(String str) {
        return this.pattern.matcher(str).matches();
    }

SimpleUrlPattern compiles fromURI into a pattern and performs regex matching. So I'm not sure what is the perceived shortcoming.
Can you please provide example of what can't be matched but should be?

Do you want to be able to match multiple domain names w/ pattern? That is indeed not available, you need to list all domain names for which you want mapping to be applied.

Comment by Christian Ringele [ 06/Feb/14 ]

HostBasedVirtualURIMapping:

 public MappingResult mapURI(String uri)

The uri does not contain parameters.

The RegexpVirtualURIMapping provides for this a second method with the parameter queryString which contains the parameters.

@Override
public MappingResult mapURI(final String uri, String queryString) {

Where the queryString is used for the matcher:

if(queryString != null){
    matcher = regexp.matcher(uri + "?" + queryString);
}

In HostBasedVirtualURIMapping the matcher of the pattern won't take parameters into account:

boolean match = pattern.match(uri);

-> The HostBasedVirtualURIMapping should be queryString aware as the RegexpVirtualURIMapping is.
Then needs of SUPPORT-3223 would be covered.

Even with this addition of queryString awareness I think using the HostBasedVirtualURIMapping is not as flexible for multisite behavior:
Imagine:

  • you have multiple domains in multiple site definitions mapped to the same site.
  • you have more than one domain mapped in the same site definition
  • different domains for author and publics in combination with different languages (sub domains)
    This will lead to a huge hosts configuration, and every time a new domain is added it must be known to which HostBasedVirtualURIMapping it has to be added.
    A SiteDefintion driven VirtualURIMapping would help there much more.
Comment by Joerg von Frantzius [ 13/Feb/14 ]

BTW the same problem exists with DefaultVirtualURIMapping: it's not possible to define a mapping that matches only for a given site.

If e.g. you have two sites greatshoes.com and greatshirts.com, and you want to have two different VirtualURIMappings greatshoes.com/offer and greatshirts.com/offer that each map to a different page within their respective sites, you have to program a custom VirtualURIMapping.

Comment by Jan Haderka [ 13/Feb/14 ]

@Joerg this should be doable with HostBasedVirtualURIMapping out of the box.

Comment by Joerg von Frantzius [ 13/Feb/14 ]

@Jan yes you're totally right, thanks!

Comment by Roman Kovařík [ 19/Feb/14 ]

Commited on 4.5.x branch for review.

Comment by Richard Unger [ 29/Apr/14 ]

After looking over these solutions, I coded a solution by subclassing MultiSiteFilter.

Doing it in multisitefilter has several advantages:

  • you can serve error pages from the individual sites without having to add configuration per site.
  • one forward less happens while processing the request
    (virtual uri method has original request + 2 forwards, filter solution has orig request + 1 forward)

I will try to share the solution on the wiki.

Generated at Mon Feb 12 04:07:10 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.