Fixed #SWS-103: MessageDispatcherServlet does not transform WSDL locations

This commit is contained in:
Arjen Poutsma
2007-04-04 09:25:26 +00:00
parent 67aa09007f
commit 741aa3b8fe

View File

@@ -12,26 +12,31 @@ import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.FrameworkServlet;
import org.springframework.web.util.WebUtils;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.server.EndpointAdapter;
import org.springframework.ws.server.EndpointExceptionResolver;
import org.springframework.ws.server.EndpointMapping;
import org.springframework.ws.server.MessageDispatcher;
import org.springframework.ws.transport.WebServiceMessageReceiver;
import org.springframework.ws.transport.support.DefaultStrategiesHelper;
import org.springframework.ws.wsdl.WsdlDefinition;
/**
* Servlet for simplified dispatching of Web service messages. Delegates to a <code>MessageDispatcher</code> and a
* <code>WebServiceMessageReceiverHandlerAdapter</code>.
* Servlet for simplified dispatching of Web service messages. This servlet is a convenient alternative for a standard
* Spring-MVC {@link DispatcherServlet} with a separate {@link WebServiceMessageReceiverHandlerAdapter} and a {@link
* MessageDispatcher}, and a {@link WsdlDefinitionHandlerAdapter}.
* <p/>
* This servlet is a convenient alternative for a standard Spring-MVC <code>DispatcherServlet</code> with a separate
* <code>WebServiceMessageReceiverHandlerAdapter</code> and a <code>MessageDispatcher</code>.
* This servlet automatically detects {@link EndpointAdapter}s, {@link EndpointMapping}s, and {@link
* EndpointExceptionResolver}s by type.
* <p/>
* This servlet automatically detects <code>EndpointAdapter</code>s, <code>EndpointMapping</code>s, and
* <code>EndpointExceptionResolver</code>s, by type (when the corresponding detectAll* property is enabled) or by type
* (when the property is disabled). For instance, when the <code>detectAllEndpointAdapters</code> propery is
* <code>true</code> (the default), all endpoint adapters defined in the web application context are registered with the
* message dispatcher. When it is set to <code>false</code>, this servlet tries to find a bean with the
* "endpointAdapter" bean name in the context.
* This servlet also automatically detects any {@link WsdlDefinition} in its application context. This WSDL is exposed
* under the bean name (e.g. a {@link WsdlDefinition} bean named '<code>echo</code>' will be exposed as
* <code>echo.wsdl</code> in this servlet's context: http://localhost:8080/spring-ws/echo.wsdl). When the
* <code>transformWsdlLocations</code> property is set to <code>true</code> in the web.xml, all <code>location</code>
* attributes in the WSDL definitions will reflect the URL of the incoming request.
*
* @author Arjen Poutsma
* @see org.springframework.web.servlet.DispatcherServlet
@@ -40,14 +45,10 @@ import org.springframework.ws.wsdl.WsdlDefinition;
*/
public class MessageDispatcherServlet extends FrameworkServlet {
/**
* Well-known name for the <code>WebServiceMessageFactory</code> object in the bean factory for this namespace.
*/
/** Well-known name for the <code>WebServiceMessageFactory</code> object in the bean factory for this namespace. */
public static final String WEB_SERVICE_MESSAGE_FACTORY_BEAN_NAME = "messageFactory";
/**
* Well-known name for the <code>WebServiceMessageReceiver</code> object in the bean factory for this namespace.
*/
/** Well-known name for the <code>WebServiceMessageReceiver</code> object in the bean factory for this namespace. */
public static final String MESSAGE_RECEIVER_BEAN_NAME = "messageReceiver";
/**
@@ -56,45 +57,41 @@ public class MessageDispatcherServlet extends FrameworkServlet {
*/
private static final String DEFAULT_STRATEGIES_PATH = "MessageDispatcherServlet.properties";
/**
* Suffix of a WSDL request uri.
*/
/** Suffix of a WSDL request uri. */
private static final String WSDL_SUFFIX_NAME = ".wsdl";
private final DefaultStrategiesHelper defaultStrategiesHelper;
/**
* The <code>WebServiceMessageReceiverHandlerAdapter</code> used by this servlet.
*/
/** The <code>WebServiceMessageReceiverHandlerAdapter</code> used by this servlet. */
private WebServiceMessageReceiverHandlerAdapter messageReceiverHandlerAdapter =
new WebServiceMessageReceiverHandlerAdapter();
/**
* The <code>WsdlDefinitionHandlerAdapter</code> used by this servlet.
*/
/** The <code>WsdlDefinitionHandlerAdapter</code> used by this servlet. */
private WsdlDefinitionHandlerAdapter wsdlDefinitionHandlerAdapter = new WsdlDefinitionHandlerAdapter();
/**
* The <code>WebServiceMessageReceiver</code> used by this servlet.
*/
/** The <code>WebServiceMessageReceiver</code> used by this servlet. */
private WebServiceMessageReceiver messageReceiver;
/**
* Keys are bean names, values are <code>WsdlDefinition</code>s.
*/
/** Keys are bean names, values are <code>WsdlDefinition</code>s. */
private Map wsdlDefinitions;
/**
* Public constructor, necessary for some Web application servers.
*/
private boolean transformWsdlLocations = false;
/** Public constructor, necessary for some Web application servers. */
public MessageDispatcherServlet() {
defaultStrategiesHelper = new DefaultStrategiesHelper(
new ClassPathResource(DEFAULT_STRATEGIES_PATH, MessageDispatcherServlet.class));
}
/**
* Returns the <code>WebServiceMessageReceiver</code> used by this servlet.
* Sets whether relative address locations in the WSDL are to be transformed using the request URI of the incoming
* <code>HttpServletRequest</code>. Defaults to <code>false</code>.
*/
public void setTransformWsdlLocations(boolean transformWsdlLocations) {
this.transformWsdlLocations = transformWsdlLocations;
}
/** Returns the <code>WebServiceMessageReceiver</code> used by this servlet. */
protected WebServiceMessageReceiver getMessageReceiver() {
return messageReceiver;
}
@@ -190,6 +187,7 @@ public class MessageDispatcherServlet extends FrameworkServlet {
}
private void initWsdlDefinitions() {
wsdlDefinitionHandlerAdapter.setTransformLocations(transformWsdlLocations);
// Find all WsdlDefinitions in the ApplicationContext, incuding ancestor contexts.
wsdlDefinitions = BeanFactoryUtils
.beansOfTypeIncludingAncestors(getWebApplicationContext(), WsdlDefinition.class, true, false);