Documentation Archive Developer
Search
PATH Documentation > WebObjects

Table of Contents

WOHTTPConnection


Inherits from:
Object
Package:
com.webobjects.appserver


Class Description


The WOHTTPConnection class is intended to be used as a client for HTTP communications. It gives you direct access to the HTTP contents and headers. WOHTTPConnection's sendRequest method allows you to send a WORequest object directly to the server specified by the constructor's host and port parameters, and readResponse allows you to receive WOResponse objects from that same server.




Method Types


Constructing and initializing
WOHTTPConnection
Sending and receiving data
readResponse
sendRequest
Working with connection settings
connectTimeout
keepAliveEnabled
receiveTimeout
sendTimeout
setConnectTimeout
setKeepAliveEnabled
setReceiveTimeout
setSendTimeout


Constructors



WOHTTPConnection

public WOHTTPConnection( String hostName, int portNumber)

Returns a WOHTTPConnection instance initialized with the specified host name and port number.

public WOHTTPConnection ( String aHost, int portNumber, int timeOut)

Description forthcoming.


Static Methods



expectContentLengthHeader

public static void expectContentLengthHeader( boolean expectContentLengthHeader, int contentTimeout)

This class method allows you to specify whether a content-length header is expected to accompany HTTP content, and, if a content-length header is not found, how long (in milliseconds) WOHTTPConnection should wait to determine that all HTTP content has been received. Set the first parameter to true and supply an appropriate timeout if a content-length header is always expected. (If a content-length header is detected, the value it specifies will be used to determine how much data to accumulate independent of the boolean parameter). If you set the first parameter to false, the timeout parameter is ignored and, if no content-length header is found among the HTTP content, no data will be returned when reading from the socket.

socketForHostAndPortAndTimeout

protected static java.net.Socket socketForHostAndPortAndTimeout( String host, int port, int timeout)

Protected class method that returns a java.net.Socket for the provided hostname and port. This method may throw a java.io.IOException or a java.net.UnknownHostException if it is unable to create a new socket based upon the supplied hostname and port.


Instance Methods



connectTimeout

public int connectTimeout()

Returns the connection timeout interval in seconds.

See Also: receiveTimeout, sendTimeout, setConnectTimeout



isConnected

public boolean isConnected()

Description forthcoming.

keepAliveEnabled

public boolean keepAliveEnabled()

Returns whether the socket will be left open after requests are sent.

See Also: setKeepAliveEnabled



readResponse

public WOResponse readResponse()

Reads a response from the server and returns it as a WOResponse object. This method blocks until the contents of the response have been fully received. Returns null if an error is detected while reading or interpreting the response.

readResponse sets the keep-alive enabled flag to false unless the response indicates that the connection should be held open.

See Also: sendRequest



receiveTimeout

public int receiveTimeout()

Returns the receive timeout interval in seconds.

See Also: connectTimeout, sendTimeout, setReceiveTimeout



sendRequest

public boolean sendRequest(WORequest aRequest)

Opens a socket connection to the server indicated by the receiver's host name and port number and writes aRequest to that socket. Returns true if the socket is being held open for a subsequent invocation of sendRequest, or false if is has been closed. Use the setKeepAliveEnabled method to control whether the socket is to be held open.

Throws an exception if the socket connection cannot be established.

See Also: readResponse



sendTimeout

public int sendTimeout()

Returns the send timeout interval in seconds.

See Also: connectTimeout, receiveTimeout, setSendTimeout



setConnectTimeout

public void setConnectTimeout(int timeout)

Sets the connection timeout interval to timeout seconds. The default value for this timeout is 5 seconds unless overridden by the WOHTTPConnectTimeout user default.

See Also: setReceiveTimeout, setSendTimeout



setKeepAliveEnabled

public void setKeepAliveEnabled(boolean flag)

Specifies according to flag whether the socket is to be left open after each request has been sent so that subsequent requests don't require the socket to be re-opened.

See Also: keepAliveEnabled, readResponse, sendRequest



setReceiveTimeout

public void setReceiveTimeout(int timeout)

Sets the receive timeout interval to timeout seconds. The default value for this timeout is 30 seconds unless overridden by the WOHTTPReceiveTimeout user default.

See Also: setConnectTimeout, setSendTimeout



setSendTimeout

public void setSendTimeout(int timeout)

Sets the send timeout interval to timeout seconds. The default value for this timeout is 10 seconds unless overridden by the WOHTTPSendTimeout user default.

See Also: setConnectTimeout, setReceiveTimeout



toString

public String toString()

Returns a String containing a string representation of the receiver.

© 2001 Apple Computer, Inc. (Last Published April 15, 2001)


Table of Contents