jdk/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 51 6fe31bc95bbc
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 51
diff changeset
     2
 * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.rmi.transport.proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.rmi.runtime.Log;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The HttpSendSocket class extends the java.net.Socket class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * by enclosing the data output stream in, then extracting the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * stream from, an HTTP protocol transmission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * NOTES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Since the length of the output request must be known before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * HTTP header can be completed, all of the output is buffered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * an HttpOutputStream object until either an attempt is made to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * read from this socket, or the socket is explicitly closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * On the first read attempt to read from this socket, the buffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * output is sent to the destination as the body of an HTTP POST
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * request.  All reads will then acquire data from the body of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the response.  A subsequent attempt to write to this socket will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * throw an IOException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class HttpSendSocket extends Socket implements RMISocketInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /** the host to connect to */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected String host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /** the port to connect to */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /** the URL to forward through */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /** the object managing this connection through the URL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected URLConnection conn = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /** internal input stream for this socket */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected InputStream in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /** internal output stream for this socket */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected OutputStream out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /** the notifying input stream returned to users */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected HttpSendInputStream inNotifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /** the notifying output stream returned to users */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected HttpSendOutputStream outNotifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Line separator string.  This is the value of the line.separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * property at the moment that the socket was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private String lineSeparator =
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    81
        java.security.AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            new sun.security.action.GetPropertyAction("line.separator"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Create a stream socket and connect it to the specified port on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * the specified host.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param host the host
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param port the port
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public HttpSendSocket(String host, int port, URL url) throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        super((SocketImpl)null);        // no underlying SocketImpl for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (RMIMasterSocketFactory.proxyLog.isLoggable(Log.VERBOSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            RMIMasterSocketFactory.proxyLog.log(Log.VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                "host = " + host + ", port = " + port + ", url = " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.host = host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.url = url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        inNotifier = new HttpSendInputStream(null, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        outNotifier = new HttpSendOutputStream(writeNotify(), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Create a stream socket and connect it to the specified port on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * the specified host.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param host the host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param port the port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public HttpSendSocket(String host, int port) throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this(host, port, new URL("http", host, port, "/"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Create a stream socket and connect it to the specified address on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * the specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param address the address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param port the port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public HttpSendSocket(InetAddress address, int port) throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this(address.getHostName(), port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Indicate that this socket is not reusable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public boolean isReusable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Create a new socket connection to host (or proxy), and prepare to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * send HTTP transmission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public synchronized OutputStream writeNotify() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (conn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            throw new IOException("attempt to write on HttpSendSocket after " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                  "request has been sent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        conn = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        conn.setDoOutput(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        conn.setUseCaches(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        conn.setRequestProperty("Content-type", "application/octet-stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        inNotifier.deactivate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return out = conn.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Send HTTP output transmission and prepare to receive response.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public synchronized InputStream readNotify() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        RMIMasterSocketFactory.proxyLog.log(Log.VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            "sending request and activating input stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        outNotifier.deactivate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            in = conn.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            RMIMasterSocketFactory.proxyLog.log(Log.BRIEF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                "failed to get input stream, exception: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            throw new IOException("HTTP request failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         * If an HTTP error response is returned, sometimes an IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * is thrown, which is handled above, and other times it isn't, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * the error response body will be available for reading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         * As a safety net to catch any such unexpected HTTP behavior, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         * verify that the content type of the response is what the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * HttpOutputStream generates: "application/octet-stream".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * (Servers' error responses will generally be "text/html".)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * Any error response body is printed to the log.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        String contentType = conn.getContentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (contentType == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            !conn.getContentType().equals("application/octet-stream"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            if (RMIMasterSocketFactory.proxyLog.isLoggable(Log.BRIEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                String message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                if (contentType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    message = "missing content type in response" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                        lineSeparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    message = "invalid content type in response: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        contentType + lineSeparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                message += "HttpSendSocket.readNotify: response body: ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    DataInputStream din = new DataInputStream(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    String line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    while ((line = din.readLine()) != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        message += line + lineSeparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                RMIMasterSocketFactory.proxyLog.log(Log.BRIEF, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new IOException("HTTP request failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Get the address to which the socket is connected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public InetAddress getInetAddress()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return InetAddress.getByName(host);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return null;        // null if couldn't resolve destination host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Get the local address to which the socket is bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public InetAddress getLocalAddress()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return InetAddress.getLocalHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return null;        // null if couldn't determine local host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Get the remote port to which the socket is connected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public int getPort()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Get the local port to which the socket is connected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public int getLocalPort()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return -1;      // request not applicable to this socket type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Get an InputStream for this socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public InputStream getInputStream() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return inNotifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Get an OutputStream for this socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public OutputStream getOutputStream() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return outNotifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Enable/disable TCP_NODELAY.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * This operation has no effect for an HttpSendSocket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void setTcpNoDelay(boolean on) throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Retrieve whether TCP_NODELAY is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public boolean getTcpNoDelay() throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return false;   // imply option is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Enable/disable SO_LINGER with the specified linger time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * This operation has no effect for an HttpSendSocket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public void setSoLinger(boolean on, int val) throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Retrive setting for SO_LINGER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public int getSoLinger() throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return -1;      // imply option is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Enable/disable SO_TIMEOUT with the specified timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * This operation has no effect for an HttpSendSocket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public synchronized void setSoTimeout(int timeout) throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Retrive setting for SO_TIMEOUT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public synchronized int getSoTimeout() throws SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return 0;       // imply option is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Close the socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public synchronized void close() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (out != null) // push out transmission if not done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Return string representation of this pseudo-socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public String toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return "HttpSendSocket[host=" + host +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
               ",port=" + port +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
               ",url=" + url + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
}