01: /*
02: * Copyright 2002-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.web.context.support;
18:
19: import java.io.IOException;
20:
21: import javax.servlet.ServletException;
22: import javax.servlet.http.HttpServlet;
23: import javax.servlet.http.HttpServletRequest;
24: import javax.servlet.http.HttpServletResponse;
25:
26: import org.springframework.web.HttpRequestHandler;
27: import org.springframework.web.context.WebApplicationContext;
28:
29: /**
30: * Simple HttpServlet that delegates to an HttpRequestHandler bean defined
31: * in Spring's root web application context. The bean name must match the
32: * HttpRequestHandlerServlet servlet-name as defined in <code>web.xml</code>.
33: *
34: * <p>This can for example be used to expose a single Spring remote exporter,
35: * such as HttpInvokerServiceExporter and HessianServiceExporter, per
36: * HttpRequestHandlerServlet definition. This is an alternative to defining
37: * remote exporters as beans in a DispatcherServlet context, leveraging
38: * the advanced mapping and interception facilities there.
39: *
40: * @author Juergen Hoeller
41: * @since 2.0
42: * @see org.springframework.web.HttpRequestHandler
43: * @see org.springframework.web.servlet.DispatcherServlet
44: */
45: public class HttpRequestHandlerServlet extends HttpServlet {
46:
47: private HttpRequestHandler target;
48:
49: public void init() throws ServletException {
50: WebApplicationContext wac = WebApplicationContextUtils
51: .getRequiredWebApplicationContext(getServletContext());
52: this .target = (HttpRequestHandler) wac.getBean(
53: getServletName(), HttpRequestHandler.class);
54: }
55:
56: protected void service(HttpServletRequest request,
57: HttpServletResponse response) throws ServletException,
58: IOException {
59:
60: this.target.handleRequest(request, response);
61: }
62:
63: }
|