Source Code Cross Referenced for HttpServerConnection.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » rmi » transport » proxy » 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 » Apache Harmony Java SE » org package » org.apache.harmony.rmi.transport.proxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        /**
020:         * @author  Mikhail A. Markov
021:         * @version $Revision: 1.1.2.3 $
022:         */package org.apache.harmony.rmi.transport.proxy;
023:
024:        import java.io.DataInputStream;
025:        import java.io.DataOutputStream;
026:        import java.io.IOException;
027:        import java.net.Socket;
028:        import java.rmi.RemoteException;
029:        import java.rmi.UnmarshalException;
030:        import java.rmi.server.UID;
031:
032:        import org.apache.harmony.rmi.common.RMILog;
033:        import org.apache.harmony.rmi.internal.nls.Messages;
034:        import org.apache.harmony.rmi.server.ServerConnection;
035:        import org.apache.harmony.rmi.server.ServerConnectionManager;
036:
037:        /**
038:         * Http extension of ServerConnection.
039:         *
040:         * @author  Mikhail A. Markov
041:         * @version $Revision: 1.1.2.3 $
042:         */
043:        public class HttpServerConnection extends ServerConnection implements 
044:                ProxyConstants {
045:
046:            // If true then this connection was closed.
047:            private boolean isClosed = false;
048:
049:            /**
050:             * Constructs HttpServerConnection working through socket specified.
051:             *
052:             * @param s Socket connected to the client
053:             * @param mgr ConnectionManager managing this connection
054:             *
055:             * @throws IOException if an I/O error occurred during getting
056:             *         input/output streams from specified socket
057:             */
058:            public HttpServerConnection(Socket s, ServerConnectionManager mgr)
059:                    throws IOException {
060:                super (s, mgr);
061:            }
062:
063:            /**
064:             * @see ServerConnection.clientProtocolAck()
065:             */
066:            protected int clientProtocolAck() throws IOException {
067:                byte data;
068:                DataInputStream din = new DataInputStream(in);
069:
070:                try {
071:                    // read RMI header
072:                    int header = din.readInt();
073:
074:                    if (header != RMI_HEADER) {
075:                        // rmi.82=Unknown header: {0}
076:                        throw new UnmarshalException(Messages.getString(
077:                                "rmi.82", header)); //$NON-NLS-1$
078:                    }
079:
080:                    // read RMI protocol version
081:                    short ver = din.readShort();
082:
083:                    if (ver != PROTOCOL_VER) {
084:                        // rmi.83=Unknown RMI protocol version: {0}
085:                        throw new UnmarshalException(Messages.getString(
086:                                "rmi.83", ver));//$NON-NLS-1$
087:                    }
088:                } catch (IOException ioe) {
089:                    // rmi.84=Unable to read RMI protocol header
090:                    throw new UnmarshalException(Messages.getString("rmi.84"), //$NON-NLS-1$
091:                            ioe);
092:                }
093:
094:                if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
095:                    // rmi.85=Using protocol version {0}
096:                    proxyTransportLog.log(RMILog.VERBOSE, Messages.getString(
097:                            "rmi.85", //$NON-NLS-1$
098:                            PROTOCOL_VER));
099:                }
100:
101:                // read protocol type
102:                if (din.readByte() == SINGLEOP_PROTOCOL) {
103:
104:                    if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
105:                        // rmi.86=Using singleop RMI protocol
106:                        proxyTransportLog.log(RMILog.VERBOSE, Messages
107:                                .getString("rmi.86")); //$NON-NLS-1$
108:                    }
109:                } else {
110:                    return -1;
111:                }
112:
113:                // protocol is agreed
114:                return SINGLEOP_PROTOCOL;
115:            }
116:
117:            /**
118:             * @see ServerConnection.waitCallMsg()
119:             */
120:            protected int waitCallMsg() throws IOException {
121:                if (isClosed) {
122:                    return -1;
123:                }
124:                int data;
125:
126:                try {
127:                    data = in.read();
128:                } catch (IOException ioe) {
129:                    data = -1;
130:                }
131:
132:                if (data == -1) {
133:                    if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
134:                        // rmi.log.123=Connection [{0}] is closed
135:                        proxyTransportLog.log(RMILog.VERBOSE, Messages
136:                                .getString("rmi.log.123", toString())); //$NON-NLS-1$
137:                    }
138:                    return -1;
139:                }
140:                DataOutputStream dout = new DataOutputStream(out);
141:
142:                if (data == PING_MSG) {
143:                    if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
144:                        // rmi.log.124=Got ping request
145:                        proxyTransportLog.log(RMILog.VERBOSE, Messages
146:                                .getString("rmi.log.124")); //$NON-NLS-1$
147:                    }
148:                    releaseInputStream();
149:
150:                    // send ping ack
151:                    dout.writeByte(PING_ACK);
152:                    dout.close();
153:                    return -1;
154:                } else if (data == DGCACK_MSG) {
155:                    if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
156:                        // rmi.log.125=Got DGC ack request
157:                        proxyTransportLog.log(RMILog.VERBOSE, Messages
158:                                .getString("rmi.log.125")); //$NON-NLS-1$
159:                    }
160:                    dgcUnregisterUID(UID.read(new DataInputStream(in)));
161:                    releaseInputStream();
162:                    dout.close();
163:                    return -1;
164:                } else if (data == CALL_MSG) {
165:                    if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
166:                        // rmi.log.126=Got call request
167:                        proxyTransportLog.log(RMILog.VERBOSE, Messages
168:                                .getString("rmi.log.126")); //$NON-NLS-1$
169:                    }
170:                    return data;
171:                } else {
172:                    if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
173:                        // rmi.log.127=Unknown request got: {0}
174:                        proxyTransportLog.log(RMILog.VERBOSE, Messages
175:                                .getString("rmi.log.127", data)); //$NON-NLS-1$
176:                    }
177:                    // rmi.87=Unknown message got: {0}
178:                    throw new RemoteException(Messages
179:                            .getString("rmi.87", data)); //$NON-NLS-1$
180:                }
181:            }
182:
183:            /**
184:             * Closes output stream. After that call this connection is treated as
185:             * closed and could be reused.
186:             */
187:            public synchronized void releaseOutputStream() throws IOException {
188:                if (isClosed) {
189:                    return;
190:                }
191:                isClosed = true;
192:                out.close();
193:            }
194:
195:            /**
196:             * Returns string representation of this connection.
197:             *
198:             * @return string representation of this connection
199:             */
200:            public String toString() {
201:                return "HttpServerConnection: remote endpoint:" + ep; //$NON-NLS-1$
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.