Source Code Cross Referenced for RemoteHttpServlet.java in  » Groupware » hipergate » com » oreilly » 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 » Groupware » hipergate » com.oreilly.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (C) 1998-2001 by Jason Hunter <jhunter_AT_acm_DOT_org>.
002:        // All rights reserved.  Use of this class is limited.
003:        // Please see the LICENSE for more information.
004:
005:        package com.oreilly.servlet;
006:
007:        import java.io.*;
008:        import java.net.*;
009:        import java.rmi.*;
010:        import java.rmi.server.*;
011:        import java.rmi.registry.*;
012:        import java.util.*;
013:        import javax.servlet.*;
014:        import javax.servlet.http.*;
015:
016:        /** 
017:         * A superclass for any HTTP servlet that wishes to act as an RMI server.
018:         * RemoteHttpServlet begins listening for RMI calls in its 
019:         * <tt>init()</tt> method and stops listening in its <tt>destroy()</tt> 
020:         * method.  To register itself it uses the registry on the local machine 
021:         * on the port determined by <tt>getRegistryPort()</tt>.  It registers
022:         * under the name determined by <tt>getRegistryName()</tt>.  
023:         *
024:         * @see com.oreilly.servlet.RemoteDaemonHttpServlet
025:         *
026:         * @author <b>Jason Hunter</b>, Copyright &#169; 1998
027:         * @version 1.0, 98/09/18
028:         */
029:        public abstract class RemoteHttpServlet extends HttpServlet implements 
030:                Remote {
031:            /**
032:             * The registry for the servlet
033:             */
034:            protected Registry registry;
035:
036:            /**
037:             * Begins the servlet's RMI operations.  Causes the servlet to export
038:             * itself and then bind itself to the registry.  Logs any errors.
039:             * Subclasses that override this method must be sure to first call 
040:             * <tt>super.init(config)</tt>.
041:             * 
042:             * @param config the servlet config
043:             * @exception ServletException if a servlet exception occurs
044:             */
045:            public void init(ServletConfig config) throws ServletException {
046:                super .init(config);
047:                try {
048:                    UnicastRemoteObject.exportObject(this );
049:                    bind();
050:                } catch (RemoteException e) {
051:                    log("Problem binding to RMI registry: " + e.getMessage());
052:                }
053:            }
054:
055:            /**
056:             * Halts the servlet's RMI operations.  Causes the servlet to
057:             * unbind itself from the registry.  Logs any errors.  Subclasses that 
058:             * override this method must be sure to first call <tt>super.destroy()</tt>.
059:             */
060:            public void destroy() {
061:                unbind();
062:            }
063:
064:            /**
065:             * Returns the name under which the servlet should be bound in the
066:             * registry.  By default the name is the servlet's class name.  This
067:             * can be overridden with the <tt>registryName</tt> init parameter.
068:             *
069:             * @return the name under which the servlet should be bound in the registry
070:             */
071:            protected String getRegistryName() {
072:                // First name choice is the "registryName" init parameter
073:                String name = getInitParameter("registryName");
074:                if (name != null)
075:                    return name;
076:
077:                // Fallback choice is the name of this class
078:                return this .getClass().getName();
079:            }
080:
081:            /**
082:             * Returns the port where the registry should be running.  By default 
083:             * the port is the default registry port (1099).  This can be 
084:             * overridden with the <tt>registryPort</tt> init parameter.
085:             *
086:             * @return the port for the registry
087:             */
088:            protected int getRegistryPort() {
089:                // First port choice is the "registryPort" init parameter
090:                try {
091:                    return Integer.parseInt(getInitParameter("registryPort"));
092:                }
093:
094:                // Fallback choice is the default registry port (1099)
095:                catch (NumberFormatException e) {
096:                    return Registry.REGISTRY_PORT;
097:                }
098:            }
099:
100:            /**
101:             * Binds the servlet to the registry.  Creates the registry if necessary.
102:             * Logs any errors.
103:             */
104:            protected void bind() {
105:                // Try to find the appropriate registry already running
106:                try {
107:                    registry = LocateRegistry.getRegistry(getRegistryPort());
108:                    registry.list(); // Verify it's alive and well
109:                } catch (Exception e) {
110:                    // Couldn't get a valid registry
111:                    registry = null;
112:                }
113:
114:                // If we couldn't find it, we need to create it.
115:                // (Equivalent to running "rmiregistry")
116:                if (registry == null) {
117:                    try {
118:                        registry = LocateRegistry
119:                                .createRegistry(getRegistryPort());
120:                    } catch (Exception e) {
121:                        log("Could not get or create RMI registry on port "
122:                                + getRegistryPort() + ": " + e.getMessage());
123:                        return;
124:                    }
125:                }
126:
127:                // If we get here, we must have a valid registry.
128:                // Now register this servlet instance with that registry.
129:                try {
130:                    registry.rebind(getRegistryName(), this );
131:                } catch (Exception e) {
132:                    log("Could not bind to RMI registry: " + e.getMessage());
133:                    return;
134:                }
135:            }
136:
137:            /**
138:             * Unbinds the servlet from the registry.
139:             * Logs any errors.
140:             */
141:            protected void unbind() {
142:                try {
143:                    if (registry != null)
144:                        registry.unbind(getRegistryName());
145:                } catch (Exception e) {
146:                    log("Problem unbinding from RMI registry: "
147:                            + e.getMessage());
148:                }
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.