-
Notifications
You must be signed in to change notification settings - Fork 834
WW-5514: Make ProxyUtil cache configurable via struts constants #1573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lukaszlenart
merged 2 commits into
release/struts-6-8-x
from
fix/WW-5514-proxy-cache-configurable
Feb 21, 2026
+265
−11
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
core/src/main/java/com/opensymphony/xwork2/ognl/ProxyCacheFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package com.opensymphony.xwork2.ognl; | ||
|
|
||
| /** | ||
| * A factory interface for ProxyUtil cache to be used with Struts DI mechanism. | ||
| * This allows the proxy detection cache type to be configurable via Struts constants. | ||
| * | ||
| * @param <Key> The type for the cache key entries | ||
| * @param <Value> The type for the cache value entries | ||
| * @since 6.9.0 | ||
| */ | ||
| public interface ProxyCacheFactory<Key, Value> extends OgnlCacheFactory<Key, Value> { | ||
|
|
||
| } |
44 changes: 44 additions & 0 deletions
44
core/src/main/java/com/opensymphony/xwork2/ognl/StrutsProxyCacheFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package com.opensymphony.xwork2.ognl; | ||
|
|
||
| import com.opensymphony.xwork2.inject.Inject; | ||
| import org.apache.commons.lang3.EnumUtils; | ||
| import org.apache.struts2.StrutsConstants; | ||
|
|
||
| /** | ||
| * Struts Proxy Cache factory implementation for ProxyUtil caches. | ||
| * <p> | ||
| * This factory is used to create caches for proxy detection in ProxyUtil. | ||
| * The cache type and size can be configured via Struts constants. | ||
| * | ||
| * @param <Key> The type for the cache key entries | ||
| * @param <Value> The type for the cache value entries | ||
| * @since 6.9.0 | ||
| */ | ||
| public class StrutsProxyCacheFactory<Key, Value> extends DefaultOgnlCacheFactory<Key, Value> | ||
| implements ProxyCacheFactory<Key, Value> { | ||
|
|
||
| @Inject | ||
| public StrutsProxyCacheFactory( | ||
| @Inject(value = StrutsConstants.STRUTS_PROXY_CACHE_MAXSIZE) String cacheMaxSize, | ||
| @Inject(value = StrutsConstants.STRUTS_PROXY_CACHE_TYPE) String defaultCacheType) { | ||
| super(Integer.parseInt(cacheMaxSize), EnumUtils.getEnumIgnoreCase(CacheType.class, defaultCacheType)); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
core/src/main/java/com/opensymphony/xwork2/util/LazyRef.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package com.opensymphony.xwork2.util; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * A thread-safe lazy reference that computes its value on first access using | ||
| * double-checked locking. The cached value can be invalidated via {@link #reset()}, | ||
| * causing the next {@link #get()} call to recompute the value. | ||
| * | ||
| * @param <T> the type of the lazily computed value | ||
| * @since 6.9.0 | ||
| */ | ||
| public class LazyRef<T> implements Supplier<T> { | ||
|
|
||
| private final Supplier<T> factory; | ||
| private volatile T value; | ||
|
|
||
| /** | ||
| * Creates a new LazyRef with the given factory supplier. | ||
| * | ||
| * @param factory the supplier used to compute the value; must not be null | ||
| */ | ||
| public LazyRef(Supplier<T> factory) { | ||
| this.factory = factory; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the cached value, computing it on first access or after a {@link #reset()}. | ||
| * | ||
| * @return the computed value | ||
| */ | ||
| @Override | ||
| public T get() { | ||
| T result = value; | ||
| if (result == null) { | ||
| synchronized (this) { | ||
| result = value; | ||
| if (result == null) { | ||
| result = factory.get(); | ||
| value = result; | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Invalidates the cached value so the next {@link #get()} call recomputes it. | ||
| */ | ||
| public void reset() { | ||
| value = null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
core/src/main/java/com/opensymphony/xwork2/util/StrutsProxyCacheFactoryBean.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package com.opensymphony.xwork2.util; | ||
|
|
||
| import com.opensymphony.xwork2.inject.Inject; | ||
| import com.opensymphony.xwork2.ognl.ProxyCacheFactory; | ||
|
|
||
| /** | ||
| * Bean that wires the ProxyCacheFactory to ProxyUtil during container initialization. | ||
| * <p> | ||
| * This bean is created by the container and receives the configured ProxyCacheFactory | ||
| * via dependency injection, then passes it to the static ProxyUtil class. | ||
| * | ||
| * @since 6.9.0 | ||
| */ | ||
| public class StrutsProxyCacheFactoryBean { | ||
|
|
||
| @Inject | ||
| public StrutsProxyCacheFactoryBean(ProxyCacheFactory<?, ?> proxyCacheFactory) { | ||
| ProxyUtil.setProxyCacheFactory(proxyCacheFactory); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should technically be
synchronizedbut anyway it's a super edge case so I wouldn't worry