Source Code Cross Referenced for DwrSpringServlet.java in  » Ajax » dwr » org » directwebremoting » spring » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » dwr » org.directwebremoting.spring 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Joe Walker
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.directwebremoting.spring;
017:
018:        import java.io.IOException;
019:        import java.util.ArrayList;
020:        import java.util.List;
021:
022:        import javax.servlet.ServletConfig;
023:        import javax.servlet.ServletContext;
024:        import javax.servlet.ServletException;
025:        import javax.servlet.http.HttpServlet;
026:        import javax.servlet.http.HttpServletRequest;
027:        import javax.servlet.http.HttpServletResponse;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:        import org.directwebremoting.WebContextFactory.WebContextBuilder;
032:        import org.directwebremoting.extend.Configurator;
033:        import org.directwebremoting.impl.ContainerUtil;
034:        import org.directwebremoting.impl.StartupUtil;
035:        import org.directwebremoting.servlet.UrlProcessor;
036:        import org.springframework.beans.factory.NoSuchBeanDefinitionException;
037:        import org.springframework.context.ApplicationContext;
038:        import org.springframework.web.context.support.WebApplicationContextUtils;
039:
040:        /**
041:         * The servlet that handles all calls to DWR. <br>
042:         * It retrieves its configuration from the Spring IoC container. This is done in two ways:
043:         * <ol>
044:         *   <li>Use the Spring namespace. When using the Spring namespace for DWR, the confgiuration for DWR is
045:         *       automatically picked up by this servlet.</li>
046:         *   <li>Explicitly specify which configurations to pick up. When explicitly defining the DWR configuration in
047:         *       Spring yourself, you can explicitely specify them in the init parameters.</li>
048:         * </ol>
049:         * Same as with the <code>DwrServlet</code>, you can specify a <code>debug</code> init parameter on this servlet
050:         * to put DWR in debug mode (allowing access to the very handy debug pages).
051:         *
052:         * @see org.directwebremoting.servlet.DwrServlet
053:         *
054:         * @author Bram Smeets
055:         * @author Joe Walker [joe at getahead dot ltd dot uk]
056:         */
057:        public class DwrSpringServlet extends HttpServlet {
058:            /**
059:             * Setter for use by the Spring IoC container to tell us what Configurators
060:             * exist for us to configure ourselves.
061:             * @param configurators
062:             */
063:            public void setConfigurators(List<Configurator> configurators) {
064:                this .configurators = configurators;
065:            }
066:
067:            /**
068:             * Do we prefix the list of Configurators with a default to read the system
069:             * dwr.xml file?
070:             * @param includeDefaultConfig the includeDefaultConfig to set
071:             */
072:            public void setIncludeDefaultConfig(boolean includeDefaultConfig) {
073:                this .includeDefaultConfig = includeDefaultConfig;
074:            }
075:
076:            /**
077:             * Use provided application context rather than the default.
078:             *
079:             * @param applicationContext
080:             */
081:            public void setApplicationContext(
082:                    ApplicationContext applicationContext) {
083:                this .applicationContext = applicationContext;
084:            }
085:
086:            /* (non-Javadoc)
087:             * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
088:             */
089:            @Override
090:            public void init(ServletConfig servletConfig)
091:                    throws ServletException {
092:                super .init(servletConfig);
093:                ServletContext servletContext = servletConfig
094:                        .getServletContext();
095:
096:                try {
097:                    ApplicationContext appContext = getApplicationContext(servletContext);
098:
099:                    container = new SpringContainer();
100:                    container.setBeanFactory(appContext);
101:                    ContainerUtil.setupDefaultContainer(container,
102:                            servletConfig);
103:
104:                    StartupUtil.initContainerBeans(servletConfig,
105:                            servletContext, container);
106:                    webContextBuilder = container
107:                            .getBean(WebContextBuilder.class);
108:
109:                    ContainerUtil.prepareForWebContextFilter(servletContext,
110:                            servletConfig, container, webContextBuilder, this );
111:                    ContainerUtil.publishContainer(container, servletConfig);
112:
113:                    // retrieve the configurators from Spring (loaded by the ContextLoaderListener)
114:                    try {
115:                        configurators
116:                                .add((Configurator) appContext
117:                                        .getBean(DwrNamespaceHandler.DEFAULT_SPRING_CONFIGURATOR_ID));
118:                    } catch (NoSuchBeanDefinitionException ex) {
119:                        throw new ServletException(
120:                                "No DWR configuration was found in your application context, make sure to define one",
121:                                ex);
122:                    }
123:
124:                    if (includeDefaultConfig) {
125:                        ContainerUtil.configureFromSystemDwrXml(container);
126:                    }
127:
128:                    ContainerUtil.configureFromInitParams(container,
129:                            servletConfig);
130:                    ContainerUtil.configure(container, configurators);
131:                } catch (Exception ex) {
132:                    log.fatal("init failed", ex);
133:                    throw new ServletException(ex);
134:                } finally {
135:                    webContextBuilder.unset();
136:                }
137:            }
138:
139:            /**
140:             * Allow easy override when retrieving the application context. 
141:             *
142:             * @param servletContext
143:             * @return the default application context.
144:             */
145:            protected ApplicationContext getApplicationContext(
146:                    ServletContext servletContext) {
147:                return this .applicationContext == null ? WebApplicationContextUtils
148:                        .getRequiredWebApplicationContext(servletContext)
149:                        : this .applicationContext;
150:            }
151:
152:            /* (non-Javadoc)
153:             * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
154:             */
155:            @Override
156:            protected void doGet(HttpServletRequest req,
157:                    HttpServletResponse resp) throws IOException,
158:                    ServletException {
159:                doPost(req, resp);
160:            }
161:
162:            /* (non-Javadoc)
163:             * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
164:             */
165:            @Override
166:            protected void doPost(HttpServletRequest request,
167:                    HttpServletResponse response) throws IOException,
168:                    ServletException {
169:                try {
170:                    webContextBuilder.set(request, response,
171:                            getServletConfig(), getServletContext(), container);
172:
173:                    UrlProcessor processor = container
174:                            .getBean(UrlProcessor.class);
175:                    processor.handle(request, response);
176:                } finally {
177:                    webContextBuilder.unset();
178:                }
179:            }
180:
181:            /**
182:             * The application context that has the configuration. If null,
183:             * the default application context will be used.
184:             */
185:            private ApplicationContext applicationContext = null;
186:
187:            /**
188:             * DWRs IoC container (that passes stuff to Spring in this case)
189:             */
190:            private SpringContainer container;
191:
192:            /**
193:             * The WebContext that keeps http objects local to a thread
194:             */
195:            protected WebContextBuilder webContextBuilder;
196:
197:            /**
198:             * Do we prefix the list of Configurators with a default to read the system
199:             * dwr.xml file?
200:             */
201:            private boolean includeDefaultConfig = true;
202:
203:            /**
204:             * What Configurators exist for us to configure ourselves.
205:             */
206:            private List<Configurator> configurators = new ArrayList<Configurator>();
207:
208:            /**
209:             * The log stream
210:             */
211:            private static final Log log = LogFactory
212:                    .getLog(DwrSpringServlet.class);
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.