01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
46: WebServiceMessageReceiverObjectSupport implements
47: HandlerAdapter {
48:
49: public long getLastModified(HttpServletRequest request,
50: Object handler) {
51: return -1L;
52: }
53:
54: public ModelAndView handle(HttpServletRequest httpServletRequest,
55: HttpServletResponse httpServletResponse, Object handler)
56: throws Exception {
57: if ("POST".equals(httpServletRequest.getMethod())) {
58: WebServiceConnection connection = new HttpServletConnection(
59: httpServletRequest, httpServletResponse);
60: handleConnection(connection,
61: (WebServiceMessageReceiver) handler);
62: return null;
63: } else {
64: httpServletResponse
65: .setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
66: return null;
67: }
68: }
69:
70: public boolean supports(Object handler) {
71: return handler instanceof WebServiceMessageReceiver;
72: }
73:
74: }
|