From 2607b7a87723ec0652be738f94330742f135b767 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 23 Aug 2012 11:47:35 +0300 Subject: [PATCH] INT-2717: add 'view-expression' to * XSD: add 'view-expression' attribute to the http:inbound-channel-adapter since `HttpRequestHandlingController` supports it. * Parser test for 'view-expression' attribute JIRA: https://jira.springsource.org/browse/INT-2717 INT-2717: Polishing based on PR comments Polishing - add mutual exlusivity to schema doc. --- .../config/spring-integration-http-2.2.xsd | 18 ++++++++++++++++++ ...nboundChannelAdapterParserTests-context.xml | 16 +++++++++------- .../HttpInboundChannelAdapterParserTests.java | 16 ++++++++++++++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.2.xsd b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.2.xsd index 63abaae351..bb6190f11a 100644 --- a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.2.xsd +++ b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.2.xsd @@ -67,6 +67,22 @@ View name to be resolved when rendering a response. + This attribute is not allowed if there is a 'view-expression' attribute. + + + + + + + SpEL expression that resolves to a view to be resolved when rendering a response. + The expression can resolve to a view name or View object. + However, because there is no reply message, the + 'evaluationContext' for this expression is rather lightweight; it has a + 'BeanResolver' but no variables, + so the usage of this attribute is somewhat limited. + An example might be to resolve, at runtime, some scoped Bean that returns a + view name or View object. + This attribute is not allowed if there is a 'view-name' attribute. @@ -199,6 +215,7 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re View name to be resolved when rendering a response. + This attribute is not allowed if there is a 'view-expression' attribute. @@ -208,6 +225,7 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re SpEL expression that resolves to a view to be resolved when rendering a response. The expression can resolve to a view name or View object. The root object of the evaluation context is the reply message. + This attribute is not allowed if there is a 'view-name' attribute. diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml index 5ffa7f9453..546fdbb6e2 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml @@ -23,27 +23,29 @@ - + + + - -
- -
- - diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java index 1626d990e3..785ac66445 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java @@ -36,6 +36,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.expression.Expression; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -58,6 +59,7 @@ import org.springframework.util.MultiValueMap; * @author Oleg Zhurakousky * @author Gary Russell * @author Gunnar Hillert + * @author Artem Bilan */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -92,6 +94,9 @@ public class HttpInboundChannelAdapterParserTests { @Autowired private HttpRequestHandlingController inboundController; + @Autowired + private HttpRequestHandlingController inboundControllerViewExp; + @Autowired private MessageChannel autoChannel; @@ -268,9 +273,16 @@ public class HttpInboundChannelAdapterParserTests { @Test public void testController() throws Exception { - DirectFieldAccessor accessor = new DirectFieldAccessor(inboundController); - String errorCode = (String) accessor.getPropertyValue("errorCode"); + String errorCode = TestUtils.getPropertyValue(inboundController, "errorCode", String.class); assertEquals("oops", errorCode); + Expression viewExpression = TestUtils.getPropertyValue(inboundController, "viewExpression", Expression.class); + assertEquals("foo", viewExpression.getExpressionString()); + } + + @Test + public void testInt2717ControllerWithViewExpression() throws Exception { + Expression viewExpression = TestUtils.getPropertyValue(inboundControllerViewExp, "viewExpression", Expression.class); + assertEquals("'foo'", viewExpression.getExpressionString()); } @Test