Source Code Cross Referenced for UrlProcessor.java in  » Ajax » dwr » org » directwebremoting » servlet » 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.servlet 
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.servlet;
017:
018:        import java.io.IOException;
019:        import java.util.Collection;
020:        import java.util.HashMap;
021:        import java.util.Map;
022:        import java.util.Map.Entry;
023:
024:        import javax.servlet.http.HttpServletRequest;
025:        import javax.servlet.http.HttpServletResponse;
026:
027:        import org.apache.commons.logging.LogFactory;
028:        import org.apache.commons.logging.Log;
029:        import org.directwebremoting.Container;
030:        import org.directwebremoting.extend.Handler;
031:        import org.directwebremoting.extend.InitializingBean;
032:
033:        /**
034:         * This is the main servlet that handles all the requests to DWR.
035:         * <p>It is on the large side because it can't use technologies like JSPs etc
036:         * since it all needs to be deployed in a single jar file, and while it might be
037:         * possible to integrate Velocity or similar I think simplicity is more
038:         * important, and there are only 2 real pages both script heavy in this servlet
039:         * anyway.</p>
040:         * <p>There are 5 things to do, in the order that you come across them:</p>
041:         * <ul>
042:         * <li>The index test page that points at the classes</li>
043:         * <li>The class test page that lets you execute methods</li>
044:         * <li>The interface javascript that uses the engine to send requests</li>
045:         * <li>The engine javascript to form the iframe request and process replies</li>
046:         * <li>The exec 'page' that executes the method and returns data to the iframe</li>
047:         * </ul>
048:         * @author Joe Walker [joe at getahead dot ltd dot uk]
049:         */
050:        public class UrlProcessor implements  Handler, InitializingBean {
051:            /* (non-Javadoc)
052:             * @see org.directwebremoting.InitializingBean#afterPropertiesSet(Container)
053:             */
054:            public void afterContainerSetup(Container container) {
055:                Collection<String> beanNames = container.getBeanNames();
056:                for (String name : beanNames) {
057:                    if (name.startsWith(PathConstants.URL_PREFIX)) {
058:                        Object bean = container.getBean(name);
059:
060:                        if (bean instanceof  Handler) {
061:                            urlMapping.put(name
062:                                    .substring(PathConstants.URL_PREFIX
063:                                            .length()), bean);
064:                        } else {
065:                            log.error("Discarding non Handler for " + name);
066:                        }
067:                    }
068:                }
069:            }
070:
071:            /* (non-Javadoc)
072:             * @see org.directwebremoting.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
073:             */
074:            public void handle(HttpServletRequest request,
075:                    HttpServletResponse response) throws IOException {
076:                try {
077:                    String pathInfo = request.getPathInfo();
078:                    contextPath = request.getContextPath();
079:
080:                    if (pathInfo == null || pathInfo.length() == 0
081:                            || "/".equals(pathInfo)) {
082:                        response.sendRedirect(contextPath
083:                                + request.getServletPath() + indexHandlerUrl);
084:                    } else {
085:                        // Loop through all the known URLs
086:                        for (Entry<String, Object> entry : urlMapping
087:                                .entrySet()) {
088:                            String url = entry.getKey();
089:
090:                            // If this URL matches, call the handler
091:                            if (pathInfo.startsWith(url)) {
092:                                Handler handler = (Handler) entry.getValue();
093:                                handler.handle(request, response);
094:                                return;
095:                            }
096:                        }
097:
098:                        notFoundHandler.handle(request, response);
099:                    }
100:                } catch (Exception ex) {
101:                    exceptionHandler.setException(ex);
102:                    exceptionHandler.handle(request, response);
103:                }
104:            }
105:
106:            /**
107:             * The contextPath cached from the last HTTP servlet request
108:             * @return the contextPath
109:             */
110:            public String getContextPath() {
111:                return contextPath;
112:            }
113:
114:            /**
115:             * The URL for the {@link IndexHandler}
116:             * @param indexHandlerUrl the indexHandlerUrl to set
117:             */
118:            public void setIndexHandlerUrl(String indexHandlerUrl) {
119:                this .indexHandlerUrl = indexHandlerUrl;
120:            }
121:
122:            /**
123:             * The URL for the {@link IndexHandler}
124:             */
125:            protected String indexHandlerUrl;
126:
127:            /**
128:             * The mapping of URLs to {@link Handler}s
129:             */
130:            protected Map<String, Object> urlMapping = new HashMap<String, Object>();
131:
132:            /**
133:             * The default if we have no other action (HTTP-404)
134:             */
135:            protected Handler notFoundHandler = new NotFoundHandler();
136:
137:            /**
138:             * If execution fails, we do this (HTTP-501)
139:             */
140:            protected ExceptionHandler exceptionHandler = new ExceptionHandler();
141:
142:            /**
143:             * The contextPath cached from the last HTTP servlet request
144:             */
145:            protected String contextPath = null;
146:
147:            /**
148:             * The log stream
149:             */
150:            private static final Log log = LogFactory
151:                    .getLog(UrlProcessor.class);
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.