From 2f746dd6bb1b35a1b4ae57abea52c13b2a2d67ab Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 27 Jul 2010 04:35:40 +0000 Subject: [PATCH] INT-1245, INT-1256 renamed conversionTargetType to requestPayloadType and added javadoc --- .../HttpRequestHandlingEndpointSupport.java | 43 ++++++++++++++----- .../config/HttpInboundEndpointParser.java | 2 +- .../config/spring-integration-http-2.0.xsd | 4 +- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/HttpRequestHandlingEndpointSupport.java b/spring-integration-http/src/main/java/org/springframework/integration/http/HttpRequestHandlingEndpointSupport.java index 47db8eaefd..52f96ef5c9 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/HttpRequestHandlingEndpointSupport.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/HttpRequestHandlingEndpointSupport.java @@ -54,6 +54,29 @@ import org.springframework.web.servlet.DispatcherServlet; /** * Base class for HTTP request handling endpoints. + *

+ * By default GET and POST requests are accepted, but the 'supportedMethods' + * property may be set to include others or limit the options (e.g. POST only). + * A GET request will generate a payload containing its 'parameterMap' while + * a POST request will be converted to a Message payload according to + * the registered {@link HttpMessageConverter}s. Several are registered + * by default, but the list can be explicitly set via {@link #setMessageConverters(List)}. + *

+ * To customize the mapping of request headers to the MessageHeaders, provide + * a reference to a {@link HeaderMapper HeaderMapper} implementation + * to the {@link #setHeaderMapper(HeaderMapper)} method. + *

+ * The behavior is "request/reply" by default. Pass false + * to the constructor to force send-only as opposed to sendAndReceive. + * Send-only means that as soon as the Message is created and passed to the + * {@link #setRequestChannel(org.springframework.integration.core.MessageChannel) request channel}, + * a response will be generated. Subclasses determine how that response is + * generated (e.g. simple status response or rendering a View). + *

+ * In a request-reply scenario, the reply Message's payload will be + * extracted prior to generating a response by default. To have the entire + * serialized Message available for the response, switch the + * {@link #extractReplyPayload} value to false. * * @author Mark Fisher * @since 2.0 @@ -71,10 +94,10 @@ abstract class HttpRequestHandlingEndpointSupport extends AbstractMessagingGatew ClassUtils.isPresent("com.sun.syndication.feed.WireFeed", HttpRequestHandlingEndpointSupport.class.getClassLoader()); - private volatile Class conversionTargetType = null; - private volatile List supportedMethods = Arrays.asList(HttpMethod.GET, HttpMethod.POST); + private volatile Class requestPayloadType = null; + private volatile List> messageConverters = new ArrayList>(); private volatile HeaderMapper headerMapper = new DefaultHttpHeaderMapper(); @@ -162,8 +185,8 @@ abstract class HttpRequestHandlingEndpointSupport extends AbstractMessagingGatew * means at runtime any "text" Content-Type will result in String while all others * default to byte[].class. */ - public void setConversionTargetType(Class conversionTargetType) { - this.conversionTargetType = conversionTargetType; + public void setRequestPayloadType(Class requestPayloadType) { + this.requestPayloadType = requestPayloadType; } /** @@ -322,17 +345,17 @@ abstract class HttpRequestHandlingEndpointSupport extends AbstractMessagingGatew @SuppressWarnings("unchecked") private Object generatePayloadFromRequestBody(ServletServerHttpRequest request) throws IOException { MediaType contentType = request.getHeaders().getContentType(); - Class targetType = this.conversionTargetType; - if (targetType == null) { - targetType = ("text".equals(contentType.getType())) ? String.class : byte[].class; + Class expectedType = this.requestPayloadType; + if (expectedType == null) { + expectedType = ("text".equals(contentType.getType())) ? String.class : byte[].class; } for (HttpMessageConverter converter : this.messageConverters) { - if (converter.canRead(targetType, contentType)) { - return converter.read((Class) targetType, request); + if (converter.canRead(expectedType, contentType)) { + return converter.read((Class) expectedType, request); } } throw new MessagingException("Could not convert request: no suitable HttpMessageConverter found for expected type [" + - targetType.getName() + "] and content type [" + contentType + "]"); + expectedType.getName() + "] and content type [" + contentType + "]"); } } diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java index 8054f54db1..51a30cdb32 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java @@ -86,7 +86,7 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse builder, element, "send-timeout", "requestTimeout"); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "supported-methods", "supportedMethodNames"); - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "conversion-target-type"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-payload-type"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "view-name"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper"); diff --git a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.0.xsd b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.0.xsd index 78ee5fac5b..8887c95731 100644 --- a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.0.xsd +++ b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.0.xsd @@ -34,7 +34,7 @@ - + Target type for payload that is the conversion result of the request. @@ -88,7 +88,7 @@ - + Target type for payload that is the conversion result of the request.