Skip to content

WW-5766 Support struts.scopedConstantProvider in Java-based configuration - #2006

Merged
lukaszlenart merged 1 commit into
mainfrom
WW-5766-scoped-constant-provider-java-config
Oct 12, 2026
Merged

lukaszlenart merged 1 commit into
mainfrom
WW-5766-scoped-constant-provider-java-config

Conversation

@lukaszlenart

Copy link
Copy Markdown
Member

Fixes WW-5766

Summary

Java-based configuration (StrutsJavaConfiguration) can now select a custom ScopedConstantProvider. Before this change the only way was to subclass ConstantConfig and override getAllAsStringsMap().

ConstantConfig gets a scopedConstantProvider field, mapped to struts.scopedConstantProvider in getAllAsStringsMap(). It has a getter and two setters, following the localizedTextProvider mapping. The class setter takes Class<? extends ScopedConstantProvider> rather than the file's usual Class<?>, so a wrong class is caught at compile time.

Tests

  • ConstantConfigTest.testScopedConstantProviderToString: the key is absent until set, then maps to the bean name from either setter.
  • StrutsJavaConfigurationProviderTest.testScopedConstantProviderSelectedThroughConstantConfig: a custom provider registered through beans() and selected through ConstantConfig is the one the container returns.
  • StrutsJavaConfigurationProviderTest.testScopableConstantsBeanSatisfiesScopedConstantValidation: a ScopableConstants bean registered through beans() lets an XML package's <scoped-constant> pass startup validation. This already worked and had no test.

The two integration tests load providers in the same order as Dispatcher: default properties, struts-default.xml, the Java config, then StrutsBeanSelectionProvider. They don't use StrutsDefaultConfigurationProvider, because it binds ScopedConstantProvider under the default name. With that binding, alias() skips the constant, so the test could never see the mapping.

I checked that the tests aren't vacuous. With the map.put line removed, both mapping tests fail. With the ScopableConstants bean removed, the validation test fails with "declares scoped constant [sample.scopable], which is not scopable". The full core suite passes: 3446 tests, 0 failures.

Out of scope

  • Package-level overrides in Java config. StrutsJavaConfiguration has no package concept.
  • Other bean-selection constants that ConstantConfig doesn't map either (parameterAuthorizer, ognlGuard, proxyService, ...).

🤖 Generated with Claude Code

…nfig

Java-based configuration can now select a custom ScopedConstantProvider
through ConstantConfig instead of overriding getAllAsStringsMap().

The selection tests load providers in the Dispatcher's order rather than
through StrutsDefaultConfigurationProvider: that bootstrap binds
ScopedConstantProvider under the default name, so alias() skips the
constant and the test could never observe the mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukaszlenart
lukaszlenart marked this pull request as ready for review October 12, 2026 09:25
@sonarqubecloud

Copy link
Copy Markdown

@lukaszlenart
lukaszlenart merged commit 3355548 into main Oct 12, 2026
16 checks passed
@lukaszlenart
lukaszlenart deleted the WW-5766-scoped-constant-provider-java-config branch October 12, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant