View Javadoc

1   /*
2    * Copyright 2006 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.transport.http;
18  
19  import javax.servlet.http.HttpServletRequest;
20  import javax.servlet.http.HttpServletResponse;
21  
22  import org.springframework.web.servlet.HandlerAdapter;
23  import org.springframework.web.servlet.ModelAndView;
24  import org.springframework.ws.transport.WebServiceConnection;
25  import org.springframework.ws.transport.WebServiceMessageReceiver;
26  import org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport;
27  
28  /**
29   * Adapter to use the {@link WebServiceMessageReceiver} interface with the generic {@link
30   * org.springframework.web.servlet.DispatcherServlet}. Requires a {@link org.springframework.ws.WebServiceMessageFactory}
31   * which is used to convert the incoming <code>HttpServletRequest</code> into a <code>WebServiceMessage</code>, and
32   * passes that context to the mapped <code>WebServiceMessageReceiver</code>. If a response is created, that is sent via
33   * the <code>HttpServletResponse</code>.
34   * <p/>
35   * Note that the <code>MessageDispatcher</code> implements the <code>WebServiceMessageReceiver</code> interface,
36   * enabling this adapter to function as a gateway to further message handling logic.
37   *
38   * @author Arjen Poutsma
39   * @see #setMessageFactory(org.springframework.ws.WebServiceMessageFactory)
40   * @see org.springframework.ws.transport.WebServiceMessageReceiver
41   * @see org.springframework.ws.WebServiceMessageFactory
42   * @see org.springframework.ws.server.MessageDispatcher
43   * @since 1.0.0
44   */
45  public class WebServiceMessageReceiverHandlerAdapter extends WebServiceMessageReceiverObjectSupport
46          implements HandlerAdapter {
47  
48      public long getLastModified(HttpServletRequest request, Object handler) {
49          return -1L;
50      }
51  
52      public ModelAndView handle(HttpServletRequest httpServletRequest,
53                                 HttpServletResponse httpServletResponse,
54                                 Object handler) throws Exception {
55          if (HttpTransportConstants.METHOD_POST.equals(httpServletRequest.getMethod())) {
56              WebServiceConnection connection = new HttpServletConnection(httpServletRequest, httpServletResponse);
57              handleConnection(connection, (WebServiceMessageReceiver) handler);
58          }
59          else {
60              httpServletResponse.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
61          }
62          return null;
63      }
64  
65      public boolean supports(Object handler) {
66          return handler instanceof WebServiceMessageReceiver;
67      }
68  
69  }