From 581f21f3ebf510bb957e392bd61b68bca653dd98 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 2 Sep 2011 12:17:21 -0400 Subject: [PATCH] INT-1677 changed uriVariables to pathVariables, added parameterMap and parameters as well as HttpEntity to the EvauationContext --- .../HttpRequestHandlingEndpointSupport.java | 29 +++++++++++++++---- ...gMessagingGatewayWithPathMappingTests.java | 4 +-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java index e88d8a7317..09b385e8b4 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/HttpRequestHandlingEndpointSupport.java @@ -33,6 +33,7 @@ import org.springframework.core.convert.ConversionService; import org.springframework.expression.Expression; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeConverter; +import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -285,7 +286,23 @@ abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewaySuppor } Map uriVariableMappings = null; // - StandardEvaluationContext evaluationContext = this.prepareAndGetEvaluationContext(); + StandardEvaluationContext evaluationContext = this.createEvaluationContext(); + + Object requestBody = null; + if (this.isReadable(request)) { + requestBody = this.extractRequestBody(request); + evaluationContext.setVariable("requestBody", requestBody); + } + + HttpEntity httpEntity = new HttpEntity(requestBody, request.getHeaders()); + evaluationContext.setRootObject(httpEntity); + + LinkedMultiValueMap requestParameterMap = this.convertParameterMap(servletRequest.getParameterMap()); + evaluationContext.setVariable("requestParameterMap", uriVariableMappings);// bind the whole map + + for (String parameterName : requestParameterMap.keySet()) { // bind individual parameters + evaluationContext.setVariable(parameterName, requestParameterMap.get(parameterName)); + } if (StringUtils.hasText(this.path)){ UriTemplate template = new UriTemplate(this.path); @@ -296,7 +313,7 @@ abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewaySuppor } // set the whole map - evaluationContext.setVariable("uriVariables", uriVariableMappings); + evaluationContext.setVariable("pathVariables", uriVariableMappings); for (Object key : uriVariableMappings.keySet()) { // add individual elements evaluationContext.setVariable((String) key, uriVariableMappings.get(key)); @@ -326,11 +343,11 @@ abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewaySuppor if (payload == null){ if (this.isReadable(request)) { - payload = this.extractRequestBody(request); + //payload = this.extractRequestBody(request); + payload = requestBody; } else { - payload = this.convertParameterMap(servletRequest.getParameterMap()); - + payload = requestParameterMap; } } @@ -453,7 +470,7 @@ abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewaySuppor return httpStatus; } - private StandardEvaluationContext prepareAndGetEvaluationContext(){ + private StandardEvaluationContext createEvaluationContext(){ StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); evaluationContext.addPropertyAccessor(new MapAccessor()); BeanFactory beanFactory = this.getBeanFactory(); diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayWithPathMappingTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayWithPathMappingTests.java index 81fd205e06..1071a98c9b 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayWithPathMappingTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayWithPathMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -121,7 +121,7 @@ public class HttpRequestHandlingMessagingGatewayWithPathMappingTests { HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true); gateway.setPath("/fname/{f}/lname/{l}"); gateway.setRequestChannel(echoChannel); - gateway.setPayloadExpression(PARSER.parseExpression("#uriVariables")); + gateway.setPayloadExpression(PARSER.parseExpression("#pathVariables")); Object result = gateway.doHandleRequest(request, response); assertEquals("bill", ((Map)result).get("f"));