Skip to content

Commit ef0dd4e

Browse files
committed
Now using properties for loading defaults in (Soap)MessageDispatcherServlet. Necessary because of a tangle between the transport and server packages.
1 parent 460a22c commit ef0dd4e

File tree

11 files changed

+452
-398
lines changed

11 files changed

+452
-398
lines changed

core/src/main/java/org/springframework/ws/server/MessageDispatcher.java

Lines changed: 94 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@
1717
package org.springframework.ws.server;
1818

1919
import java.util.ArrayList;
20+
import java.util.Collections;
2021
import java.util.Iterator;
2122
import java.util.List;
23+
import java.util.Map;
2224

2325
import org.apache.commons.logging.Log;
2426
import org.apache.commons.logging.LogFactory;
27+
import org.springframework.beans.BeansException;
28+
import org.springframework.beans.factory.BeanFactoryUtils;
2529
import org.springframework.beans.factory.BeanNameAware;
30+
import org.springframework.context.ApplicationContext;
31+
import org.springframework.context.ApplicationContextAware;
32+
import org.springframework.core.OrderComparator;
33+
import org.springframework.core.io.ClassPathResource;
34+
import org.springframework.core.io.Resource;
35+
import org.springframework.util.ClassUtils;
2636
import org.springframework.util.ObjectUtils;
2737
import org.springframework.ws.NoEndpointFoundException;
2838
import org.springframework.ws.context.MessageContext;
29-
import org.springframework.ws.server.endpoint.MessageEndpointAdapter;
30-
import org.springframework.ws.server.endpoint.PayloadEndpointAdapter;
3139
import org.springframework.ws.transport.WebServiceMessageReceiver;
40+
import org.springframework.ws.transport.support.DefaultStrategiesHelper;
3241

3342
/**
3443
* Central dispatcher for use withing Spring-WS. Dispatches Web service messages to registered endoints.
@@ -50,7 +59,7 @@
5059
* @see EndpointExceptionResolver
5160
* @see org.springframework.web.servlet.DispatcherServlet
5261
*/
53-
public class MessageDispatcher implements WebServiceMessageReceiver, BeanNameAware {
62+
public class MessageDispatcher implements WebServiceMessageReceiver, BeanNameAware, ApplicationContextAware {
5463

5564
/**
5665
* Log category to use when no mapped endpoint is found for a request.
@@ -67,6 +76,8 @@ public class MessageDispatcher implements WebServiceMessageReceiver, BeanNameAwa
6776
*/
6877
protected final Log logger = LogFactory.getLog(getClass());
6978

79+
private final DefaultStrategiesHelper defaultStrategiesHelper;
80+
7081
/**
7182
* The registered bean name for this dispatcher.
7283
*/
@@ -91,7 +102,8 @@ public class MessageDispatcher implements WebServiceMessageReceiver, BeanNameAwa
91102
* Initializes a new instance of the <code>MessageDispatcher</code>.
92103
*/
93104
public MessageDispatcher() {
94-
initDefaultStrategies();
105+
Resource resource = new ClassPathResource(ClassUtils.getShortName(getClass()) + ".properties", getClass());
106+
defaultStrategiesHelper = new DefaultStrategiesHelper(resource);
95107
}
96108

97109
/**
@@ -140,6 +152,12 @@ public void setBeanName(String beanName) {
140152
this.beanName = beanName;
141153
}
142154

155+
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
156+
initEndpointAdapters(applicationContext);
157+
initEndpointExceptionResolvers(applicationContext);
158+
initEndpointMappings(applicationContext);
159+
}
160+
143161
public void receive(MessageContext messageContext) throws Exception {
144162
if (logger.isDebugEnabled()) {
145163
logger.debug("MessageDispatcher with name '" + beanName + "' received request [" +
@@ -260,21 +278,6 @@ protected boolean handleRequest(EndpointInvocationChain mappedEndpoint, MessageC
260278
return true;
261279
}
262280

263-
/**
264-
* Initialize the default implementations for the dispatcher's strategies: <code>MessageEndpointAdapter</code> and
265-
* <code>PayloadEndpointAdapter</code>.
266-
*
267-
* @see #setEndpointAdapters(java.util.List)
268-
* @see org.springframework.ws.server.endpoint.MessageEndpointAdapter
269-
* @see org.springframework.ws.server.endpoint.PayloadEndpointAdapter
270-
*/
271-
protected void initDefaultStrategies() {
272-
List defaultEndpointAdapters = new ArrayList();
273-
defaultEndpointAdapters.add(new MessageEndpointAdapter());
274-
defaultEndpointAdapters.add(new PayloadEndpointAdapter());
275-
setEndpointAdapters(defaultEndpointAdapters);
276-
}
277-
278281
/**
279282
* Determine an error <code>SOAPMessage</code> respone via the registered <code>EndpointExceptionResolvers</code>.
280283
* Most likely, the response contains a <code>SOAPFault</code>. If no suitable resolver was found, the exception is
@@ -323,4 +326,76 @@ protected void triggerHandleResponse(EndpointInvocationChain mappedEndpoint,
323326
}
324327
}
325328
}
329+
330+
/**
331+
* Initialize the <code>EndpointAdapters</code> used by this class. If no adapter beans are explictely set by using
332+
* the <code>endpointAdapters</code> property, we use the default strategies.
333+
*
334+
* @see #setEndpointAdapters(java.util.List)
335+
*/
336+
private void initEndpointAdapters(ApplicationContext applicationContext) throws BeansException {
337+
if (endpointAdapters == null) {
338+
Map matchingBeans = BeanFactoryUtils
339+
.beansOfTypeIncludingAncestors(applicationContext, EndpointAdapter.class, true, false);
340+
if (!matchingBeans.isEmpty()) {
341+
endpointAdapters = new ArrayList(matchingBeans.values());
342+
Collections.sort(endpointAdapters, new OrderComparator());
343+
}
344+
else {
345+
endpointAdapters =
346+
defaultStrategiesHelper.getDefaultStrategies(EndpointAdapter.class, applicationContext);
347+
if (logger.isInfoEnabled() && !endpointAdapters.isEmpty()) {
348+
logger.info("No EndpointAdapters found, using defaults");
349+
}
350+
}
351+
}
352+
}
353+
354+
/**
355+
* Initialize the <code>EndpointExceptionResolver</code> used by this class. If no resolver beans are explictely set
356+
* by using the <code>endpointExceptionResolvers</code> property, we use the default strategies.
357+
*
358+
* @see #setEndpointExceptionResolvers(java.util.List)
359+
*/
360+
private void initEndpointExceptionResolvers(ApplicationContext applicationContext) throws BeansException {
361+
if (endpointExceptionResolvers == null) {
362+
Map matchingBeans = BeanFactoryUtils
363+
.beansOfTypeIncludingAncestors(applicationContext, EndpointExceptionResolver.class, true, false);
364+
if (!matchingBeans.isEmpty()) {
365+
endpointExceptionResolvers = new ArrayList(matchingBeans.values());
366+
Collections.sort(endpointExceptionResolvers, new OrderComparator());
367+
}
368+
else {
369+
endpointExceptionResolvers = defaultStrategiesHelper
370+
.getDefaultStrategies(EndpointExceptionResolver.class, applicationContext);
371+
if (logger.isInfoEnabled() && !endpointExceptionResolvers.isEmpty()) {
372+
logger.info("No EndpointExceptionResolvers found, using defaults");
373+
}
374+
}
375+
}
376+
}
377+
378+
/**
379+
* Initialize the <code>EndpointMappings</code> used by this class. If no mapping beans are explictely set by using
380+
* the <code>endpointMappings</code> property, we use the default strategies.
381+
*
382+
* @see #setEndpointMappings(java.util.List)
383+
*/
384+
private void initEndpointMappings(ApplicationContext applicationContext) throws BeansException {
385+
if (endpointMappings == null) {
386+
Map matchingBeans = BeanFactoryUtils
387+
.beansOfTypeIncludingAncestors(applicationContext, EndpointMapping.class, true, false);
388+
if (!matchingBeans.isEmpty()) {
389+
endpointMappings = new ArrayList(matchingBeans.values());
390+
Collections.sort(endpointMappings, new OrderComparator());
391+
}
392+
else {
393+
endpointMappings = defaultStrategiesHelper
394+
.getDefaultStrategies(EndpointMapping.class, applicationContext);
395+
if (logger.isInfoEnabled() && !endpointMappings.isEmpty()) {
396+
logger.info("No EndpointMappings found, using defaults");
397+
}
398+
}
399+
}
400+
}
326401
}

core/src/main/java/org/springframework/ws/soap/server/SoapMessageDispatcher.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.ws.soap.server;
1818

1919
import java.util.ArrayList;
20-
import java.util.Collections;
2120
import java.util.Iterator;
2221
import java.util.List;
2322
import java.util.Locale;
@@ -36,7 +35,6 @@
3635
import org.springframework.ws.soap.SoapHeaderElement;
3736
import org.springframework.ws.soap.SoapMessage;
3837
import org.springframework.ws.soap.SoapVersion;
39-
import org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver;
4038
import org.springframework.ws.soap.soap12.Soap12Header;
4139

4240
/**
@@ -76,19 +74,6 @@ public void setMustUnderstandFaultLocale(Locale mustUnderstandFaultLocale) {
7674
this.mustUnderstandFaultLocale = mustUnderstandFaultLocale;
7775
}
7876

79-
/**
80-
* Initialize the default implementations for the dispatcher's strategies, in addition to the strategies defined in
81-
* the base class: a <code>SimpleSoapExceptionResolver</code> as exception resolver.
82-
*
83-
* @see org.springframework.ws.server.MessageDispatcher#initDefaultStrategies()
84-
* @see #setEndpointExceptionResolvers(java.util.List)
85-
* @see org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver
86-
*/
87-
protected void initDefaultStrategies() {
88-
super.initDefaultStrategies();
89-
setEndpointExceptionResolvers(Collections.singletonList(new SimpleSoapExceptionResolver()));
90-
}
91-
9277
/**
9378
* Process the <code>MustUnderstand</code> headers in the incoming SOAP request message. Iterates over all SOAP
9479
* headers which should be understood, and determines whether these are supported. Generates a SOAP MustUnderstand

0 commit comments

Comments
 (0)