title: Spring MVC Web Services Dispatcher
body: <p>I'm trying to build web Service integrated in DispatcherServlet insted of MessageDispatcherServlet, according to Spring ws it's possible. I'm just tying to follow tutorials and implement code according to tutorials.</p>
  
  <p>Tomcat starts normally. However, I have page 404 when I'm trying to access web service using http://[host]/[project]/holidayService/ What I"m doing wrong? </p>
  
  <p>Here is my implementation:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;doolloop&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;doolloop&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.dlp&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;doolloop&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/index.dlp&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;doolloop&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/scene/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>The relevant part of doolloop-servlet.xml is the following:</p>
  
  <pre><code>&lt;tx:annotation-driven /&gt;
  &lt;mvc:annotation-driven /&gt;
  &lt;bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/&gt;
      &lt;bean class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter"&gt;
  &lt;property name="messageFactory" ref="messageFactory"/&gt;
  &lt;/bean&gt;
      &lt;bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
          &lt;property name="defaultHandler" ref="messageDispatcher"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="messageDispatcher" class="org.springframework.ws.server.MessageDispatcher"/&gt;
  
      &lt;bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/&gt;  
  &lt;bean id="holidayEndpoint" class="com.doolloop.services.HolidayEndpoint"&gt;
    &lt;constructor-arg ref="hrService" /&gt; 
    &lt;/bean&gt;
    &lt;bean id="hrService" class="com.doolloop.services.StubHumanResourceService" /&gt; 
    &lt;bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping"&gt;
    &lt;property name="mappings"&gt;
    &lt;props&gt;
    &lt;prop key="{http://mycompany.com/hr/schemas}HolidayRequest"&gt;holidayEndpoint&lt;/prop&gt; 
    &lt;/props&gt;
    &lt;/property&gt;
    &lt;property name="interceptors"&gt;
    &lt;bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" /&gt; 
    &lt;/property&gt;
    &lt;/bean&gt;
    &lt;bean id="holiday" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"&gt;
    &lt;property name="schema" ref="schema" /&gt; 
    &lt;property name="portTypeName" value="HumanResource" /&gt; 
    &lt;!--  we use a relative uri that will be transformed by spring-ws dep
    --&gt; 
    &lt;property name="locationUri" value="holidayService/" /&gt; 
    &lt;property name="targetNamespace" value="http://mycompany.com/hr/definitions" /&gt; 
    &lt;/bean&gt;
    &lt;bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema"&gt;
    &lt;property name="xsd" value="/WEB-INF/hr.xsd" /&gt; 
    &lt;/bean&gt;
  </code></pre>
  
  <p>Now the EndPoint looks like this:</p>
  
  <pre><code>public class HolidayEndpoint extends AbstractJDomPayloadEndpoint {
  
      private XPath startDateExpression;
      private XPath endDateExpression;
      private XPath nameExpression;
      private HumanResourceService humanResourceService;
  
      public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException {
          this.humanResourceService = humanResourceService;
          Namespace namespace = Namespace.getNamespace("hr", "http://mycompany.com/hr/schemas");
          startDateExpression = XPath.newInstance("//hr:StartDate");
          startDateExpression.addNamespace(namespace);
          endDateExpression = XPath.newInstance("//hr:EndDate");
          endDateExpression.addNamespace(namespace);
          nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)");
          nameExpression.addNamespace(namespace);
      }
  
      protected Element invokeInternal(Element holidayRequest) throws Exception {
          SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
          Date startDate = dateFormat.parse(startDateExpression.valueOf(holidayRequest));
          Date endDate = dateFormat.parse(endDateExpression.valueOf(holidayRequest));
          String name = nameExpression.valueOf(holidayRequest);
  
          humanResourceService.bookHoliday(startDate, endDate, name);
          return null;
      }
  }
  </code></pre>
  
  <p>beside it I have the service implementation, but I don't think it's relevant and I have a feeling it has something to do with Dispatcher servlet, but I have no idea what the problem is.</p>
  
  <p>I added the follow</p>
  
  <pre><code> &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;doolloop&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/holidayService/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>This is what my log4j file is showing:</p>
  
  <pre><code>2010-11-15 15:27:07,969 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'doolloop' processing GET request for [/dlp/holidayService/]
  2010-11-15 15:27:07,969 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Mapping [/] to HandlerExecutionChain with handler [org.springframework.ws.server.MessageDispatcher@68487fb7] and 2 interceptors
  2010-11-15 15:27:07,970 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Last-Modified value for [/dlp/holidayService/] is: -1
  2010-11-15 15:27:07,970 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name 'doolloop': assuming HandlerAdapter completed request handling
  2010-11-15 15:27:07,970 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request
  </code></pre>