KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > context > support > HttpRequestHandlerServlet


1 /*
2  * Copyright 2002-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.web.context.support;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.ServletException JavaDoc;
22 import javax.servlet.http.HttpServlet JavaDoc;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc {
46
47     private HttpRequestHandler target;
48
49
50     public void init() throws ServletException JavaDoc {
51         WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
52         this.target = (HttpRequestHandler) wac.getBean(getServletName(), HttpRequestHandler.class);
53     }
54
55
56     protected void service(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
57             throws ServletException JavaDoc, IOException JavaDoc {
58
59         this.target.handleRequest(request, response);
60     }
61
62 }
63
Popular Tags