RWS / dxa-web-application-java

SDL Digital Experience Accelerator Java Spring MVC web application
25 stars 37 forks source link

Each url stores its own Localization and is unable to be refresh or removed #132

Closed EBroersen closed 3 years ago

EBroersen commented 4 years ago

From the WebrequestContextImpl (https://github.com/sdl/dxa-web-application-java/blob/master/dxa-framework/dxa-common-api/src/main/java/com/sdl/webapp/common/impl/WebRequestContextImpl.java) it sends the full url to the LocalizationResolver

private Localization localization() {
    Localization resolveLocalization = null;
    String fullUrl = getFullUrl();
    try {
        resolveLocalization = localizationResolver.getLocalization(getFullUrl());
    } catch (LocalizationResolverException e) {

Within the GraphQLLocalizationResolver (https://github.com/sdl/dxa-web-application-java/blob/master/dxa-framework/dxa-tridion-provider/src/main/java/com/sdl/webapp/tridion/GraphQLLocalizationResolver.java) it uses this url that is passed as the key for the localizations:

public Localization getLocalization(String url) throws LocalizationResolverException {
    LOG.trace("getLocalization: {}", url);
    if (!localizations.containsKey(url)) {
        // truncating on first % because of TSI-1281
        String path = UriUtils.encodePath(url, "UTF-8").split("%")[0];
        PublicationMappingData data = getPublicationMappingData(path);

        if (data == null) {
            throw new LocalizationResolverException("Publication mapping is not resolved for URL: " + url);
        }

        localizations.put(url, createLocalization(data.id, data.path));
    }

    return localizations.get(url);
}

This actually shows that for each url that is passed to the localizationResolver, a localization is stored in memory with the url as key. It also shows that for each url a complete localization is stored in memory,

The thirdly, the option to refresh the localizations from the same GrapgQLLocalizationResolver:

public boolean refreshLocalization(Localization localization) {
    if (localization == null) {
        return false;
    }
    String localizationId = localization.getId();
    if (localizations.remove(localizationId) != null) {
        LOG.debug("Removed cached localization with id: {}", localizationId);
        return true;
    }
    return false;
}

The refresh tries to remove a localization, but uses the id of the localization to remove it, where the key actually is the url. Hence the localizations are not removed and refreshed.

neeteshnarvaria commented 3 years ago

Hi @rpannekoek This is a bug and impacting application, should be fixed

NIkonDSL commented 3 years ago

Fixed in 2.2.11

neeteshnarvaria commented 3 years ago

@NIkonDSL Thanks for the update, could you please let me know when 2.2.11 will be available on maven repository?

NIkonDSL commented 3 years ago

Started deploying to Maven Central, may take couple days till it's avalable

NIkonDSL commented 3 years ago

Note: it's been fixed with rewriting the 'refreshLocalization' method

P.S. DXA 2.2.11 published on MavenCentral and available