forked from spring-projects/spring-webflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ActionPropertyAccessor on Spring Framework 6.2
Prior to this commit, if a Spring Expression Language (SpEL) expression did not include parentheses for a MultiAction method that does not accept a RequestContext argument, the flow would pass on Spring Framework versions prior to 6.2, but the same flow would fail on Spring Framework 6.2 M1 or later. The following is such an expression and is effectively a property reference which must be handled by a registered PropertyAccessor: "reportActions.evaluateReport". The reason for the change in behavior is that Spring Framework 6.2 M1 includes a bug fix for ordering SpEL PropertyAccessors. That bug fix correctly results in Spring Web Flow's ActionPropertyAccessor being evaluated before SpEL's ReflectivePropertyAccessor. Consequently, an expression such as "reportActions.evaluateReport" is now handled by ActionPropertyAccessor which indirectly requires that the action method accept a RequestContext argument. When the method does not accept a RequestContext argument, the flow fails with a NoSuchMethodException. To address that, this commit revises the implementation of canRead(...) in ActionPropertyAccessor so that it only returns `true` if the action method accepts a RequestContext argument. When ActionPropertyAccessor's canRead(...) method returns `false`, the generic ReflectivePropertyAccessor will be used instead, which restores the pre-6.2 behavior for such expressions. The test suite passes for the following Spring Framework versions. - ./gradlew -PspringFrameworkVersion=6.0.23 --rerun-tasks clean check - ./gradlew -PspringFrameworkVersion=6.1.14 --rerun-tasks clean check - ./gradlew -PspringFrameworkVersion=6.2.0-RC3 --rerun-tasks clean check See spring-projects/spring-framework#33861 See spring-projects/spring-framework#33862 Closes spring-projectsgh-1802
- Loading branch information
Showing
4 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
131 changes: 131 additions & 0 deletions
131
...webflow/src/test/java/org/springframework/webflow/action/MultiActionIntegrationTests.java
This file contains 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,131 @@ | ||
/* | ||
* Copyright 2004-2024 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 org.springframework.webflow.action; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; | ||
import org.springframework.webflow.config.AbstractFlowConfiguration; | ||
import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; | ||
import org.springframework.webflow.execution.Event; | ||
import org.springframework.webflow.execution.RequestContext; | ||
import org.springframework.webflow.executor.FlowExecutor; | ||
import org.springframework.webflow.test.MockExternalContext; | ||
|
||
/** | ||
* Integration tests for {@link MultiAction}. | ||
* | ||
* @author Sam Brannen | ||
* @since 3.0.1 | ||
* @see <a href="https://github.com/spring-projects/spring-webflow/issues/1802">gh-1802</a> | ||
*/ | ||
@SpringJUnitConfig | ||
@DirtiesContext | ||
class MultiActionIntegrationTests { | ||
|
||
private static final String WITH_REQUEST_CONTEXT = "withRequestContext"; | ||
|
||
private static final String WITHOUT_REQUEST_CONTEXT = "withoutRequestContext"; | ||
|
||
|
||
@Autowired | ||
FlowExecutor flowExecutor; | ||
|
||
@Autowired | ||
CountingMultiAction multiAction; | ||
|
||
|
||
@BeforeEach | ||
void resetCounters() { | ||
multiAction.counterWithRequestContext = 0; | ||
multiAction.counterWithoutRequestContext = 0; | ||
} | ||
|
||
@Test | ||
void spelExpressionsWithRequestContext() { | ||
assertCounters(0, 0); | ||
launchFlowExecution(WITH_REQUEST_CONTEXT); | ||
assertCounters(2, 0); | ||
} | ||
|
||
@Test | ||
void spelExpressionsWithoutRequestContext() { | ||
assertCounters(0, 0); | ||
launchFlowExecution(WITHOUT_REQUEST_CONTEXT); | ||
assertCounters(0, 2); | ||
} | ||
|
||
private void launchFlowExecution(String flowId) { | ||
flowExecutor.launchExecution(flowId, null, new MockExternalContext()); | ||
} | ||
|
||
private void assertCounters(int counterWithRequestContext, int counterWithoutRequestContext) { | ||
assertEquals(counterWithRequestContext, multiAction.counterWithRequestContext, "counterWithRequestContext"); | ||
assertEquals(counterWithoutRequestContext, multiAction.counterWithoutRequestContext, "counterWithoutRequestContext"); | ||
} | ||
|
||
|
||
|
||
@Configuration | ||
static class WebFlowConfig extends AbstractFlowConfiguration { | ||
|
||
@Bean | ||
CountingMultiAction countingMultiAction() { | ||
return new CountingMultiAction(); | ||
} | ||
|
||
@Bean | ||
FlowExecutor flowExecutor() { | ||
return getFlowExecutorBuilder(flowRegistry()).build(); | ||
} | ||
|
||
@Bean | ||
FlowDefinitionRegistry flowRegistry() { | ||
return getFlowDefinitionRegistryBuilder() | ||
.setBasePath("classpath:/org/springframework/webflow/action") | ||
.addFlowLocation("multi-action-with-request-context.xml", WITH_REQUEST_CONTEXT) | ||
.addFlowLocation("multi-action-without-request-context.xml", WITHOUT_REQUEST_CONTEXT) | ||
.build(); | ||
} | ||
} | ||
|
||
@Component("countingMultiAction") | ||
static class CountingMultiAction extends MultiAction { | ||
|
||
int counterWithRequestContext = 0; | ||
|
||
int counterWithoutRequestContext = 0; | ||
|
||
public Event incrementWithRequestContext(RequestContext context) { | ||
counterWithRequestContext++; | ||
return success(); | ||
} | ||
|
||
public Event incrementWithoutRequestContext() { | ||
counterWithoutRequestContext++; | ||
return success(); | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...c/test/resources/org/springframework/webflow/action/multi-action-with-request-context.xml
This file contains 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,15 @@ | ||
<flow xmlns="http://www.springframework.org/schema/webflow" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/webflow https://www.springframework.org/schema/webflow/spring-webflow.xsd"> | ||
|
||
<on-start> | ||
<!-- Property Access: handled by org.springframework.webflow.expression.spel.ActionPropertyAccessor --> | ||
<evaluate expression="countingMultiAction.incrementWithRequestContext" /> | ||
|
||
<!-- Method Invocation: handled by org.springframework.expression.spel.ast.MethodReference --> | ||
<evaluate expression="countingMultiAction.incrementWithRequestContext(#requestContext)" /> | ||
</on-start> | ||
|
||
<end-state id="end" /> | ||
|
||
</flow> |
15 changes: 15 additions & 0 deletions
15
...est/resources/org/springframework/webflow/action/multi-action-without-request-context.xml
This file contains 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,15 @@ | ||
<flow xmlns="http://www.springframework.org/schema/webflow" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/webflow https://www.springframework.org/schema/webflow/spring-webflow.xsd"> | ||
|
||
<on-start> | ||
<!-- Property Access: handled by org.springframework.expression.spel.support.ReflectivePropertyAccessor --> | ||
<evaluate expression="countingMultiAction.incrementWithoutRequestContext" /> | ||
|
||
<!-- Method Invocation: handled by org.springframework.expression.spel.ast.MethodReference --> | ||
<evaluate expression="countingMultiAction.incrementWithoutRequestContext()" /> | ||
</on-start> | ||
|
||
<end-state id="end" /> | ||
|
||
</flow> |