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, 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.ServerSocket;
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.RMILog;
031: import org.apache.harmony.rmi.internal.nls.Messages;
032:
033: /**
034: * Socket factory for HTTP proxy connections. Returns {@link HttpOutboundSocket}
035: * for client and {@link HttpServerSocket} for server sockets.
036: *
037: * @author Mikhail A. Markov, Vasily Zakharov
038: * @version $Revision: 1.1.2.2 $
039: */
040: public class HttpProxyRMISocketFactory extends ProxyRMISocketFactory
041: implements ProxyConstants {
042:
043: /**
044: * serialVersionUID
045: */
046: private static final long serialVersionUID = -8113740863920118588L;
047:
048: /**
049: * {@inheritDoc}
050: */
051: public Socket createSocket(Proxy proxy, String host, int port)
052: throws IOException {
053: Socket s;
054:
055: // Check if plain HTTP is disabled.
056: if (((Boolean) AccessController
057: .doPrivileged(new GetBooleanPropAction(
058: DISABLE_PLAIN_HTTP_PROP))).booleanValue()) {
059: if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
060: // rmi.log.131=Plain HTTP connections disabled, trying CGI connection.
061: proxyTransportLog.log(RMILog.VERBOSE, Messages
062: .getString("rmi.log.131")); //$NON-NLS-1$
063: }
064: } else {
065: try {
066: // Try plain HTTP connection.
067: s = new HttpOutboundSocket(proxy, host, port, false);
068:
069: if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
070: // rmi.log.132=Plain HTTP connection to [{0}:{1}] from port {2} succeeded.
071: proxyTransportLog
072: .log(
073: RMILog.VERBOSE,
074: Messages
075: .getString(
076: "rmi.log.132", new Object[] { host, port, s.getLocalPort() })); //$NON-NLS-1$
077: }
078:
079: return s;
080: } catch (IOException e) {
081: if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
082: // rmi.log.133=Plain HTTP connection to [{0}:{1}] failed: {2}. Trying CGI connection.
083: proxyTransportLog.log(RMILog.VERBOSE, Messages
084: .getString("rmi.log.133", //$NON-NLS-1$
085: new Object[] { host, port, e }));
086: }
087: }
088: }
089:
090: try {
091: // Try CGI HTTP connection.
092: s = new HttpOutboundSocket(proxy, host, port, true);
093:
094: if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
095: // rmi.log.134=CGI HTTP connection to [{0}:{1}] from port {2} succeeded.
096: proxyTransportLog.log(RMILog.VERBOSE, Messages
097: .getString("rmi.log.134", //$NON-NLS-1$
098: new Object[] { host, port,
099: s.getLocalPort() }));
100: }
101: return s;
102: } catch (IOException e) {
103: if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
104: // rmi.log.135=CGI HTTP connection to [{0}:{1}] failed: {2}
105: proxyTransportLog.log(RMILog.VERBOSE, Messages
106: .getString("rmi.log.135", //$NON-NLS-1$
107: new Object[] { host, port, e }));
108: }
109: throw e;
110: }
111: }
112:
113: /**
114: * {@inheritDoc}
115: */
116: public ServerSocket createServerSocket(int port) throws IOException {
117: return new HttpServerSocket(port);
118: }
119: }
|