Description
Aleksei Valikov opened SWS-124 and commented
Currently, MessageDispatcherServlet only uses standard bean names for message factory and message receiver.
This is problematic since there is may be name collisions. Another problem is that if I want to use the same application context with two servlerts mapped on different URIs, there is no way I can tell them which message receivers they have to use.
Both problems can be solved with separate application context per servlet, but this rather complicated.
Why not allow these bean names to be configured, with pre-configured names set by default?
I mean, we could add:
private String messageReceiverBeanName = MESSAGE_RECEIVER_BEAN_NAME;
public String getMessageReceiverBeanName() {
return messageReceiverBeanName;
}
public void setMessageReceiverBeanName(String messageReceiverBeanName) {
this.messageReceiverBeanName = messageReceiverBeanName;
}
And then:
private void initMessageReceiver() {
try {
messageReceiver = (WebServiceMessageReceiver) getWebApplicationContext()
.getBean(getMessageReceiverBeanName(), WebServiceMessageReceiver.class);
}
catch (NoSuchBeanDefinitionException ex) {
messageReceiver = (WebServiceMessageReceiver) defaultStrategiesHelper
.getDefaultStrategy(WebServiceMessageReceiver.class, getWebApplicationContext());
if (messageReceiver instanceof BeanNameAware) {
((BeanNameAware) messageReceiver).setBeanName(getServletName());
}
if (logger.isInfoEnabled()) {
logger.info("Unable to locate MessageDispatcher with name '" + getMessageReceiverBeanName() +
"': using default [" + messageReceiver + "]");
}
}
}
The name will be MESSAGE_RECEIVER_BEAN_NAME (as usual) by default. But in case the someone need to access the bean with another name, it can be done as simple as:
<servlet>
<servlet-name>spring-ws-csw</servlet-name>
<servlet-class>de.disy.preludio2.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>messageReceiverBeanName</param-name>
<param-value>cswMessageReceiver</param-value>
</init-param>
</servlet>
I will also attach the modified class I use in my project.
Had to copy-paste instead of subclassing since all the init* methods are private, not protected...
Affects: 1.0 M3
Attachments:
- MessageDispatcherServlet.java (9.72 kB)
Referenced from: commits 6ebb764