Source Code Cross Referenced for Proxy.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  Vasily Zakharov
021:         * @version $Revision: 1.1.2.2 $
022:         */package org.apache.harmony.rmi.transport.proxy;
023:
024:        import java.io.IOException;
025:        import java.net.NoRouteToHostException;
026:        import java.net.Socket;
027:        import java.security.AccessController;
028:
029:        import org.apache.harmony.rmi.common.GetBooleanPropAction;
030:        import org.apache.harmony.rmi.common.GetLongPropAction;
031:        import org.apache.harmony.rmi.common.GetStringPropAction;
032:        import org.apache.harmony.rmi.common.RMIConstants;
033:        import org.apache.harmony.rmi.common.RMILog;
034:        import org.apache.harmony.rmi.internal.nls.Messages;
035:
036:        /**
037:         * Provides access to Java proxy system properties.
038:         *
039:         * Note: instances of this class and values returned by their methods
040:         * should not be stored longer than is required to establish a particular
041:         * connection. Instead, a new instance should be created and the methods
042:         * of that instance called each time new connection is established.
043:         *
044:         * @author  Vasily Zakharov
045:         * @version $Revision: 1.1.2.2 $
046:         */
047:        public final class Proxy implements  ProxyConstants {
048:
049:            /**
050:             * HTTP proxy host name.
051:             */
052:            private final String proxyHost;
053:
054:            /**
055:             * HTTP proxy port number.
056:             */
057:            private final int proxyPort;
058:
059:            /**
060:             * If proxy is set.
061:             */
062:            private final boolean proxySet;
063:
064:            /**
065:             * Should we enable direct (non-proxy) HTTP connections.
066:             */
067:            private final boolean enableDirect;
068:
069:            /**
070:             * Creates instance of this class.
071:             *
072:             * Note: instances of this class and values returned by their methods
073:             * should not be stored longer than is required to establish a particular
074:             * connection. Instead, a new instance should be created and the methods
075:             * of that instance called each time new connection is established.
076:             */
077:            public Proxy() {
078:                proxyHost = getProxyHost();
079:
080:                if (proxyHost != null) {
081:                    proxySet = true;
082:                    proxyPort = getProxyPort();
083:                    enableDirect = false;
084:                } else {
085:                    proxySet = false;
086:                    proxyPort = (-1);
087:                    enableDirect = isDirectEnabled();
088:                }
089:                // rmi.log.11D=Proxy configuration:
090:                // rmi.log.11E=proxy disabled, direct HTTP connections
091:                if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
092:                    proxyTransportLog
093:                            .log(
094:                                    RMILog.VERBOSE,
095:                                    Messages.getString("rmi.log.11D") //$NON-NLS-1$
096:                                            + (proxySet ? (proxyHost + ':' + proxyPort)
097:                                                    : (Messages
098:                                                            .getString("rmi.log.11E") //$NON-NLS-1$
099:                                                            + (enableDirect ? "enabled" : "disabled") //$NON-NLS-1$ //$NON-NLS-2$
100:                                                    + '.')));
101:                }
102:            }
103:
104:            /**
105:             * Returns proxy host name or <code>null</code> if proxy host is not set.
106:             *
107:             * @return  Proxy host name or <code>null</code> if proxy host is not set.
108:             */
109:            public String getHost() {
110:                return proxyHost;
111:            }
112:
113:            /**
114:             * Returns proxy port number or {@link #HTTP_DEFAULT_PORT} if proxy port
115:             * is not set or <code>-1</code> if proxy host is not set.
116:             *
117:             * @return  Proxy port number or {@link #HTTP_DEFAULT_PORT} if proxy port
118:             *          is not set or <code>-1</code> if proxy host is not set.
119:             */
120:            public int getPort() {
121:                return proxyPort;
122:            }
123:
124:            /**
125:             * Returns <code>true</code> if proxy host is set in system environment,
126:             * <code>false</code> otherwise.
127:             *
128:             * @return  <code>true</code> if proxy host is set in system environment,
129:             *          <code>false</code> otherwise.
130:             */
131:            public boolean isSet() {
132:                return proxySet;
133:            }
134:
135:            /**
136:             * Returns new socket connected to specified host and port, probably
137:             * through a proxy (if proxy is set). If proxy is not set, then if direct
138:             * HTTP connections are enabled, connection is established directly,
139:             * otherwise {@link IOException} is thrown.
140:             *
141:             * @param   host
142:             *          Host to connect to.
143:             *z
144:             * @param   port
145:             *          Port to connect to.
146:             *
147:             * @return  New socket connected to the specified host and port,
148:             *          probably through a proxy.
149:             *
150:             * @throws  IOException
151:             *          If I/O error occurs.
152:             */
153:            public Socket getSocket(String host, int port) throws IOException {
154:                if (proxySet) {
155:                    return new Socket(proxyHost, proxyPort);
156:                } else if (enableDirect) {
157:                    return new Socket(host, port);
158:                } else {
159:                    // rmi.81=HTTP proxy is not set
160:                    throw new NoRouteToHostException(Messages
161:                            .getString("rmi.81")); //$NON-NLS-1$
162:                }
163:            }
164:
165:            /**
166:             * Accesses {@link #PROXY_HOST_PROP} system property
167:             * and retrieves the proxy host name.
168:             *
169:             * @return  Proxy host name or <code>null</code> if proxy host is not set.
170:             */
171:            private static String getProxyHost() {
172:                String host = (String) AccessController
173:                        .doPrivileged(new GetStringPropAction(PROXY_HOST_PROP));
174:
175:                if ((host == null) || (host.length() < 1)) {
176:                    return null;
177:                }
178:
179:                host = host.trim();
180:
181:                return ((host.length() < 1) ? null : host);
182:            }
183:
184:            /**
185:             * Accesses {@link #PROXY_PORT_PROP} system property
186:             * and retrieves the proxy port number.
187:             *
188:             * @return  Proxy port number or {@link #HTTP_DEFAULT_PORT}
189:             *          if proxy port is not set.
190:             */
191:            private static int getProxyPort() {
192:                return ((Long) AccessController
193:                        .doPrivileged(new GetLongPropAction(PROXY_PORT_PROP,
194:                                RMIConstants.HTTP_DEFAULT_PORT))).intValue();
195:            }
196:
197:            /**
198:             * Accesses {@link #ENABLE_DIRECT_HTTP_PROP} system property
199:             * to find out if direct connections are allowed.
200:             *
201:             * @return  <code>true</code> if direct connections are allowed,
202:             *          <code>false</code> otherwise.
203:             */
204:            private static boolean isDirectEnabled() {
205:                return ((Boolean) AccessController
206:                        .doPrivileged(new GetBooleanPropAction(
207:                                ENABLE_DIRECT_HTTP_PROP))).booleanValue();
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.