Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-124

Allow specifying names of message factory and message receiver in MessageDispatcherServlet

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0 M3
    • Fix Version/s: 1.0 RC2
    • Component/s: Core
    • Labels:
      None

      Description

      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...

        Activity

        Hide
        lexicore Aleksei Valikov added a comment -

        The modified servlet class.

        Show
        lexicore Aleksei Valikov added a comment - The modified servlet class.

          People

          • Assignee:
            arjen.poutsma Arjen Poutsma
            Reporter:
            lexicore Aleksei Valikov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: