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 580fc23955..fdb1a9dab7 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 @@ -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. @@ -159,6 +159,10 @@ abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewaySuppor public void setPath(String path) { this.path = path; } + + String getPath() { + return path; + } public void setPayloadExpression(Expression payloadExpression) { this.payloadExpression = payloadExpression; diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/UriPathHandlerMapping.java b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/UriPathHandlerMapping.java new file mode 100644 index 0000000000..a6ad65e857 --- /dev/null +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/inbound/UriPathHandlerMapping.java @@ -0,0 +1,65 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://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.integration.http.inbound; + +import java.util.Collections; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactoryUtils; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.util.ObjectUtils; +import org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping; + +/** + * @author Oleg Zhurakousky + * @since 2.1 + */ +public class UriPathHandlerMapping extends AbstractDetectingUrlHandlerMapping implements InitializingBean { + + protected void detectHandlers() throws BeansException { + if (logger.isDebugEnabled()) { + logger.debug("Looking for URL mappings in application context: " + getApplicationContext()); + } + + String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(getApplicationContext(), Object.class); + + for (String beanName : beanNames) { + String[] urls = determineUrlsForHandler(beanName); + if (!ObjectUtils.isEmpty(urls)) { + // URL paths found: Let's consider it a handler. + registerHandler(urls, beanName); + } + else { + if (logger.isDebugEnabled()) { + logger.debug("Rejected bean name '" + beanName + "': no URL paths identified"); + } + } + } + } + + @Override + protected String[] determineUrlsForHandler(String beanName) { + ApplicationContext context = this.getApplicationContext(); + HttpRequestHandlingEndpointSupport handler = context.getBean(beanName, HttpRequestHandlingEndpointSupport.class); + String path = handler.getPath(); + return Collections.singletonList(path).toArray(new String[]{}); + } + + public void afterPropertiesSet() throws Exception { + this.setOrder(Integer.MIN_VALUE); + } +}