INT-3458: Compatibility with Spring Framework 4.1

JIRA: https://jira.spring.io/browse/INT-3458

* Change Spring AMQP to `1.3.5.RELEASE`
* `HttpRequestHandlingEndpointSupport`: remove `MappingJacksonHttpMessageConverter` registration
* `IntegrationRequestMappingHandlerMapping`: add 'fake' `name()` attribute to the inline `RequestMapping` annotation
* `StoredProcJmxManagedBeanTests`: remove `context.stop();` code, Since `MBeanExporter` deregister MBeans on `stop()` now
* `StoredProcPollingChannelAdapterParserTests`: change deprecated `ParameterizedSingleColumnRowMapper` to the `SingleColumnRowMapper`
* `Jms`: comment out the reflection code to check the value for the `recoveryInterval`, because it is removed already in favor of `backOff`
* `NotificationListeningMessageProducer`: move the start-up listener registration to the `onApplicationEvent`,
because `MBeanExporter` moved `registerBeans()` to the `start()` now.
The same `phase` might cause the issue, that MBeans aren't registered yet for `NotificationListeningMessageProducer`
* `JpaOutboundGatewayTests`: change `@TransactionConfiguration` to the `@Transactional`. Don't know why the first doesn't work now.

**Cherry-pick to 4.0.x**

INT-3458: Addressing PR comments

`NotificationListeningMessageProducer`: defer listener registration until `onApplicationEvent()`
This commit is contained in:
Artem Bilan
2014-06-30 19:38:03 +03:00
committed by Gary Russell
parent 5aee3c85ba
commit c92d7a5da9
15 changed files with 170 additions and 163 deletions

View File

@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Source;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -75,23 +76,29 @@ import org.springframework.web.servlet.HandlerMapping;
/**
* Base class for HTTP request handling endpoints.
* <p>
* By default GET and POST requests are accepted via a supplied default instance of {@link RequestMapping}.
* By default GET and POST requests are accepted via a supplied default instance
* of {@link RequestMapping}.
* 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)}.
* 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)}.
* <p>
* To customize the mapping of request headers to the MessageHeaders, provide a
* reference to a {@code HeaderMapper<HttpHeaders>} implementation
* to the {@link #setHeaderMapper(HeaderMapper)} method.
* <p>
* The behavior is "request/reply" by default. Pass {@code 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.messaging.MessageChannel) request channel}, a response will be
* generated. Subclasses determine how that response is generated (e.g. simple status response or rendering a View).
* The behavior is "request/reply" by default. Pass {@code 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.messaging.MessageChannel) request channel},
* a response will be generated. Subclasses determine how that response is generated
* (e.g. simple status response or rendering a View).
* <p>
* 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
* {@code false}.
* 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 {@code false}.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
@@ -144,7 +151,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
this(true);
}
@SuppressWarnings("deprecation")
public HttpRequestHandlingEndpointSupport(boolean expectReply) {
this.expectReply = expectReply;
this.defaultMessageConverters.add(new MultipartAwareFormHttpMessageConverter());
@@ -153,8 +159,7 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
stringHttpMessageConverter.setWriteAcceptCharset(false);
this.defaultMessageConverters.add(stringHttpMessageConverter);
this.defaultMessageConverters.add(new ResourceHttpMessageConverter());
@SuppressWarnings("rawtypes")
SourceHttpMessageConverter<?> sourceConverter = new SourceHttpMessageConverter();
SourceHttpMessageConverter<Source> sourceConverter = new SourceHttpMessageConverter<Source>();
this.defaultMessageConverters.add(sourceConverter);
if (jaxb2Present) {
this.defaultMessageConverters.add(new Jaxb2RootElementHttpMessageConverter());
@@ -168,12 +173,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
logger.debug("'MappingJackson2HttpMessageConverter' was added to the 'defaultMessageConverters'.");
}
}
else if (JacksonJsonUtils.isJacksonPresent()) {
this.defaultMessageConverters.add(new org.springframework.http.converter.json.MappingJacksonHttpMessageConverter());
if (logger.isDebugEnabled()) {
logger.debug("'MappingJacksonHttpMessageConverter' was added to the 'defaultMessageConverters'.");
}
}
if (romePresent) {
this.defaultMessageConverters.add(new AtomFeedHttpMessageConverter());
this.defaultMessageConverters.add(new RssChannelHttpMessageConverter());
@@ -191,29 +190,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
return expectReply;
}
/**
* Set the path template for which this endpoint expects requests.
* May include path variable {keys} to match against.
*
* @param path The path.
*
* @deprecated since 3.0 in favor of {@linkplain #requestMapping}
*/
@Deprecated
public void setPath(String path) {
this.requestMapping.setPathPatterns(path);
}
/**
* @return The path.
* @deprecated since 3.0 in favor of {@linkplain #requestMapping}
*/
@Deprecated
String getPath() {
String[] pathPatterns = this.requestMapping.getPathPatterns();
return !ObjectUtils.isEmpty(pathPatterns) ? pathPatterns[0] : null;
}
/**
* Specifies a SpEL expression to evaluate in order to generate the Message payload.
* The EvaluationContext will be populated with an HttpEntity instance as the root object,
@@ -226,7 +202,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
* <li><code>#matrixVariables</code></li>
* <li><code>#cookies</code>
* </ul>
*
* @param payloadExpression The payload expression.
*/
public void setPayloadExpression(Expression payloadExpression) {
@@ -246,7 +221,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
* <li><code>#matrixVariables</code></li>
* <li><code>#cookies</code>
* </ul>
*
* @param headerExpressions The header expressions.
*/
public void setHeaderExpressions(Map<String, Expression> headerExpressions) {
@@ -256,7 +230,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
/**
* Set the message body converters to use. These converters are used to convert from and to HTTP requests and
* responses.
*
* @param messageConverters The message converters.
*/
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
@@ -277,7 +250,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
/**
* Flag which determines if the default converters should be available after
* custom converters.
*
* @param mergeWithDefaultConverters true to merge, false to replace.
*/
public void setMergeWithDefaultConverters(boolean mergeWithDefaultConverters) {
@@ -286,7 +258,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
/**
* Set the {@link HeaderMapper} to use when mapping between HTTP headers and MessageHeaders.
*
* @param headerMapper The header mapper.
*/
public void setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper) {
@@ -296,7 +267,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
/**
* Set the {@link RequestMapping} which allows you to specify a flexible RESTFul-mapping for this endpoint.
*
* @param requestMapping The request mapping.
*/
public void setRequestMapping(RequestMapping requestMapping) {
@@ -308,24 +278,10 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
return requestMapping;
}
/**
* Specify the supported request methods for this gateway. By default, only GET and POST are supported.
*
* @param supportedMethods The supported methods.
*
* @deprecated since 3.0 in favor to {@linkplain #requestMapping}
*/
@Deprecated
public void setSupportedMethods(HttpMethod... supportedMethods) {
Assert.notEmpty(supportedMethods, "at least one supported method is required");
this.requestMapping.setMethods(supportedMethods);
}
/**
* Specify the type of payload to be generated when the inbound HTTP request content is read by the
* {@link HttpMessageConverter}s. By default this value is null which means at runtime any "text" Content-Type will
* result in String while all others default to <code>byte[].class</code>.
*
* @param requestPayloadType The payload type.
*/
public void setRequestPayloadType(Class<?> requestPayloadType) {
@@ -335,7 +291,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
/**
* Specify whether only the reply Message's payload should be passed in the response. If this is set to 'false', the
* entire Message will be used to generate the response. The default is 'true'.
*
* @param extractReplyPayload true to extract the reply payload.
*/
public void setExtractReplyPayload(boolean extractReplyPayload) {
@@ -346,7 +301,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
* Specify the {@link MultipartResolver} to use when checking requests. If no resolver is provided, the
* "multipartResolver" bean in the context will be used as a fallback. If that is not available either, this
* endpoint will not support multipart requests.
*
* @param multipartResolver The multipart resolver.
*/
public void setMultipartResolver(MultipartResolver multipartResolver) {
@@ -394,13 +348,13 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
/**
* Handles the HTTP request by generating a Message and sending it to the request channel. If this gateway's
* 'expectReply' property is true, it will also generate a response from the reply Message once received.
*
* @param servletRequest The servlet request.
* @param servletResponse The servlet response.
* @return The response Message.
* @throws IOException Any IOException.
*/
protected final Message<?> doHandleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException {
protected final Message<?> doHandleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
throws IOException {
if (this.isShuttingDown()) {
return createServiceUnavailableResponse();
}
@@ -410,7 +364,8 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
}
@SuppressWarnings({"rawtypes", "unchecked"})
private Message<?> actualDoHandleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException {
private Message<?> actualDoHandleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
throws IOException {
this.activeCount.incrementAndGet();
try {
ServletServerHttpRequest request = this.prepareRequest(servletRequest);
@@ -451,7 +406,8 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
}
Map<String, MultiValueMap<String, String>> matrixVariables =
(Map<String, MultiValueMap<String, String>>) servletRequest.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
(Map<String, MultiValueMap<String, String>>) servletRequest
.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
if (!CollectionUtils.isEmpty(matrixVariables)) {
if (logger.isDebugEnabled()) {
@@ -488,16 +444,20 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
AbstractIntegrationMessageBuilder<?> messageBuilder = null;
if (payload instanceof Message<?>) {
messageBuilder = this.getMessageBuilderFactory().fromMessage((Message<?>) payload).copyHeadersIfAbsent(headers);
messageBuilder = this.getMessageBuilderFactory().fromMessage((Message<?>) payload)
.copyHeadersIfAbsent(headers);
}
else {
messageBuilder = this.getMessageBuilderFactory().withPayload(payload).copyHeaders(headers);
}
Message<?> message = messageBuilder
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL, request.getURI().toString())
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD, request.getMethod().toString())
.setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL, servletRequest.getUserPrincipal())
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_URL,
request.getURI().toString())
.setHeader(org.springframework.integration.http.HttpHeaders.REQUEST_METHOD,
request.getMethod().toString())
.setHeader(org.springframework.integration.http.HttpHeaders.USER_PRINCIPAL,
servletRequest.getUserPrincipal())
.build();
Message<?> reply = null;
@@ -527,7 +487,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
/**
* Converts the reply message to the appropriate HTTP reply object and
* sets up the {@link ServletServerHttpResponse}.
*
* @param response The ServletServerHttpResponse.
* @param replyMessage The reply message.
* @return The message payload (if {@link #extractReplyPayload}) otherwise the message.
@@ -549,8 +508,9 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
}
/**
* Prepares an instance of {@link ServletServerHttpRequest} from the raw {@link HttpServletRequest}. Also converts
* the request into a multipart request to make multiparts available if necessary. If no multipart resolver is set,
* Prepares an instance of {@link ServletServerHttpRequest} from the raw
* {@link HttpServletRequest}. Also converts the request into a multipart request to
* make multiparts available if necessary. If no multipart resolver is set,
* simply returns the existing request.
* @param servletRequest current HTTP request
* @return the processed request (multipart wrapper if necessary)
@@ -576,7 +536,6 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
/**
* Clean up any resources used by the given multipart request (if any).
*
* @param request current HTTP request
* @see MultipartResolver#cleanupMultipart
*/
@@ -638,10 +597,11 @@ public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewa
private void validateSupportedMethods() {
if (this.requestPayloadType != null
&& CollectionUtils.containsAny(nonReadableBodyHttpMethods, Arrays.asList(this.requestMapping.getMethods()))) {
&& CollectionUtils.containsAny(nonReadableBodyHttpMethods,
Arrays.asList(this.requestMapping.getMethods()))) {
if (logger.isWarnEnabled()) {
logger.warn("The 'requestPayloadType' attribute will have no relevance for one of the specified HTTP methods '" +
nonReadableBodyHttpMethods + "'");
logger.warn("The 'requestPayloadType' attribute will have no relevance for one " +
"of the specified HTTP methods '" + nonReadableBodyHttpMethods + "'");
}
}
}

View File

@@ -36,31 +36,37 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
/**
* The {@link org.springframework.web.servlet.HandlerMapping} implementation that
* detects and registers {@link RequestMappingInfo}s for {@link HttpRequestHandlingEndpointSupport}
* from a Spring Integration HTTP configuration of
* {@code <inbound-channel-adapter/>} and {@code <inbound-gateway/>} elements.
* detects and registers {@link RequestMappingInfo}s for
* {@link HttpRequestHandlingEndpointSupport} from a Spring Integration HTTP configuration
* of {@code <inbound-channel-adapter/>} and {@code <inbound-gateway/>} elements.
* <p>
* This class is automatically configured as a bean in the application context during the parsing phase of
* the {@code <inbound-channel-adapter/>} and {@code <inbound-gateway/>} elements, if there is none registered, yet.
* However it can be configured as a regular bean with appropriate configuration for
* {@link RequestMappingHandlerMapping}. It is recommended to have only one similar bean in the application context
* using the 'id' {@link org.springframework.integration.http.support.HttpContextUtils#HANDLER_MAPPING_BEAN_NAME}.
* This class is automatically configured as a bean in the application context during the
* parsing phase of the {@code <inbound-channel-adapter/>} and {@code <inbound-gateway/>}
* elements, if there is none registered, yet. However it can be configured as a regular
* bean with appropriate configuration for {@link RequestMappingHandlerMapping}.
* It is recommended to have only one similar bean in the application context using the 'id'
* {@link org.springframework.integration.http.support.HttpContextUtils#HANDLER_MAPPING_BEAN_NAME}.
* <p>
* In most cases, Spring MVC offers to configure Request Mapping via {@code org.springframework.stereotype.Controller}
* and {@link org.springframework.web.bind.annotation.RequestMapping}.
* That's why Spring MVC's Handler Mapping infrastructure relies on {@link org.springframework.web.method.HandlerMethod},
* as different methods at the same {@code org.springframework.stereotype.Controller} user-class may have their own
* {@link org.springframework.web.bind.annotation.RequestMapping}. On the other side, all Spring Integration HTTP Inbound
* Endpoints are configured on the basis of the same {@link HttpRequestHandlingEndpointSupport} class and there is no
* single {@link RequestMappingInfo} configuration without {@link org.springframework.web.method.HandlerMethod} in Spring MVC.
* Accordingly {@link IntegrationRequestMappingHandlerMapping} is a {@link org.springframework.web.servlet.HandlerMapping}
* compromise implementation between method-level annotations and component-level (e.g. Spring Integration XML) configurations.
* In most cases, Spring MVC offers to configure Request Mapping via
* {@code org.springframework.stereotype.Controller} and
* {@link org.springframework.web.bind.annotation.RequestMapping}.
* That's why Spring MVC's Handler Mapping infrastructure relies on
* {@link org.springframework.web.method.HandlerMethod}, as different methods at the same
* {@code org.springframework.stereotype.Controller} user-class may have their own
* {@link org.springframework.web.bind.annotation.RequestMapping}.
* On the other side, all Spring Integration HTTP Inbound Endpoints are configured on
* the basis of the same {@link HttpRequestHandlingEndpointSupport} class and there is no
* single {@link RequestMappingInfo} configuration without
* {@link org.springframework.web.method.HandlerMethod} in Spring MVC.
* Accordingly {@link IntegrationRequestMappingHandlerMapping} is a
* {@link org.springframework.web.servlet.HandlerMapping}
* compromise implementation between method-level annotations and component-level
* (e.g. Spring Integration XML) configurations.
*
* @author Artem Bilan
* @since 3.0
* @see RequestMapping
* @see RequestMappingHandlerMapping
*
* @since 3.0
*/
public final class IntegrationRequestMappingHandlerMapping extends RequestMappingHandlerMapping
implements ApplicationListener<ContextRefreshedEvent> {
@@ -96,8 +102,8 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin
}
/**
* Created a {@link RequestMappingInfo} from a 'Spring Integration HTTP Inbound Endpoint' {@link RequestMapping}.
*
* Created a {@link RequestMappingInfo} from a
* 'Spring Integration HTTP Inbound Endpoint' {@link RequestMapping}.
* @see RequestMappingHandlerMapping#getMappingForMethod
*/
private RequestMappingInfo getMappingForEndpoint(HttpRequestHandlingEndpointSupport endpoint) {
@@ -109,6 +115,12 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin
org.springframework.web.bind.annotation.RequestMapping requestMappingAnnotation =
new org.springframework.web.bind.annotation.RequestMapping() {
//TODO consider add 'name' support when SF 4.1 will be minimal
public String name() {
return null;
}
@Override
public String[] value() {
return requestMapping.getPathPatterns();
@@ -157,7 +169,6 @@ public final class IntegrationRequestMappingHandlerMapping extends RequestMappin
* {@link HttpRequestHandlingEndpointSupport}s may depend on auto-created
* {@code requestChannel}s, so MVC Handlers detection should be postponed
* as late as possible.
*
* @see RequestMappingHandlerMapping#afterPropertiesSet()
*/
@Override