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.1 $
022: */package org.apache.harmony.rmi.transport.proxy;
023:
024: import java.io.IOException;
025:
026: import org.apache.harmony.rmi.common.RMIConstants;
027: import org.apache.harmony.rmi.transport.SocketWrapper;
028:
029: /**
030: * Outbound HTTP socket wrapper.
031: *
032: * @author Mikhail A. Markov, Vasily Zakharov
033: * @version $Revision: 1.1.2.1 $
034: */
035: public class HttpOutboundSocket extends SocketWrapper implements
036: ProxyConstants {
037:
038: /**
039: * Host to connect to.
040: */
041: private String host;
042:
043: /**
044: * Port to connect to.
045: */
046: private int port;
047:
048: /**
049: * If this is a CGI socket.
050: */
051: private boolean cgi;
052:
053: /**
054: * Returns new <code>HttpOutboundSocket</code> instance connected
055: * to specified host and port, probably through a proxy (if proxy is set).
056: * If proxy is not set, and direct HTTP connections are enabled,
057: * then direct connection is established.
058: *
059: * Equivalent to
060: * {@link #HttpOutboundSocket(Proxy, String, int, boolean)
061: * HttpOutboundSocket(new Proxy(), host, port, false)}.
062: *
063: * @param host
064: * Host to connect to.
065: *
066: * @param port
067: * Port to connect to.
068: *
069: * @throws IOException
070: * If I/O error occurs.
071: */
072: public HttpOutboundSocket(String host, int port) throws IOException {
073: this (new Proxy(), host, port, false);
074: }
075:
076: /**
077: * Returns new <code>HttpOutboundSocket</code> instance connected
078: * to specified host and port, probably through a proxy (if proxy is set).
079: * If proxy is not set, and direct HTTP connections are enabled,
080: * then direct connection is established.
081: *
082: * Equivalent to
083: * {@link #HttpOutboundSocket(Proxy, String, int, boolean)
084: * HttpOutboundSocket(proxy, host, port, false)}.
085: *
086: * @param proxy
087: * Proxy configuration.
088: *
089: * @param host
090: * Host to connect to.
091: *
092: * @param port
093: * Port to connect to.
094: *
095: * @throws IOException
096: * If I/O error occurs.
097: */
098: public HttpOutboundSocket(Proxy proxy, String host, int port)
099: throws IOException {
100: this (proxy, host, port, false);
101: }
102:
103: /**
104: * Returns new <code>HttpOutboundSocket</code> instance connected
105: * to specified host and port, probably through a proxy (if proxy is set).
106: * If proxy is not set, and direct HTTP connections are enabled,
107: * then direct connection is established.
108: *
109: * @param proxy
110: * Proxy configuration.
111: *
112: * @param host
113: * Host to connect to.
114: *
115: * @param port
116: * Port to connect to.
117: *
118: * @param cgi
119: * If this is CGI stream.
120: *
121: * @throws IOException
122: * If I/O error occurs.
123: */
124: public HttpOutboundSocket(Proxy proxy, String host, int port,
125: boolean cgi) throws IOException {
126: super (proxy.getSocket(host,
127: (cgi ? RMIConstants.HTTP_DEFAULT_PORT : port)));
128: this .host = host;
129: this .port = port;
130: this .cgi = cgi;
131: in = new HttpInputStream(in, false);
132: out = new HttpOutputStream(out, false, host, port, cgi);
133: }
134:
135: /**
136: * {@inheritDoc}
137: */
138: public String toString() {
139: return ("HttpOutboundSocket[" + s.toString() + ", " //$NON-NLS-1$ //$NON-NLS-2$
140: + host + ':' + port + ", " + (cgi ? "" : "non-") + "CGI]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
141: }
142: }
|