Class HttpConnection
- java.lang.Object
-
- org.apache.commons.httpclient.HttpConnection
-
@Deprecated public class HttpConnection extends java.lang.ObjectDeprecated.Jakarta Commons HttpClient 3.x is deprecated in the Jenkins project. It is not recommended to use it in any new code. Instead, use HTTP client API plugins as a dependency in your code. E.g. Apache HttpComponents Client API 4.x Plugin or Async HTTP Client Plugin.An abstraction of an HTTPInputStreamandOutputStreampair, together with the relevant attributes.The following options are set on the socket before getting the input/output streams in the
open()method:Socket Method Sockets Option Configuration Socket.setTcpNoDelay(boolean)SO_NODELAY HttpConnectionParams.setTcpNoDelay(boolean)Socket.setSoTimeout(int)SO_TIMEOUT HttpConnectionParams.setSoTimeout(int)Socket.setSendBufferSize(int)SO_SNDBUF HttpConnectionParams.setSendBufferSize(int)Socket.setReceiveBufferSize(int)SO_RCVBUF HttpConnectionParams.setReceiveBufferSize(int)
-
-
Constructor Summary
Constructors Constructor Description HttpConnection(java.lang.String host, int port)Deprecated.Creates a new HTTP connection for the given host and port.HttpConnection(java.lang.String proxyHost, int proxyPort, java.lang.String host, int port)Deprecated.Creates a new HTTP connection for the given host and port via the given proxy host and port using the default protocol.HttpConnection(java.lang.String proxyHost, int proxyPort, java.lang.String host, int port, Protocol protocol)Deprecated.Creates a new HTTP connection for the given host with the virtual alias and port via the given proxy host and port using the given protocol.HttpConnection(java.lang.String proxyHost, int proxyPort, java.lang.String host, java.lang.String virtualHost, int port, Protocol protocol)Deprecated.use #HttpConnection(String, int, String, int, Protocol)HttpConnection(java.lang.String host, int port, Protocol protocol)Deprecated.Creates a new HTTP connection for the given host and port using the given protocol.HttpConnection(java.lang.String host, java.lang.String virtualHost, int port, Protocol protocol)Deprecated.Creates a new HTTP connection for the given host with the virtual alias and port using given protocol.HttpConnection(HostConfiguration hostConfiguration)Deprecated.Creates a new HTTP connection for the given host configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Deprecated.Closes the socket and streams.booleancloseIfStale()Deprecated.Closes the connection if stale.voidflushRequestOutputStream()Deprecated.Flushes the output request stream.java.lang.StringgetHost()Deprecated.Returns the host.HttpConnectionManagergetHttpConnectionManager()Deprecated.Returns the httpConnectionManager.java.io.InputStreamgetLastResponseInputStream()Deprecated.Returns the stream used to read the last response's body.java.net.InetAddressgetLocalAddress()Deprecated.Return the local address used when creating the connection.HttpConnectionParamsgetParams()Deprecated.ReturnsHTTP protocol parametersassociated with this method.intgetPort()Deprecated.Returns the port of the host.ProtocolgetProtocol()Deprecated.Returns the protocol used to establish the connection.java.lang.StringgetProxyHost()Deprecated.Returns the proxy host.intgetProxyPort()Deprecated.Returns the port of the proxy host.java.io.OutputStreamgetRequestOutputStream()Deprecated.Returns anOutputStreamsuitable for writing the request.java.io.InputStreamgetResponseInputStream()Deprecated.Return aInputStreamsuitable for reading the response.intgetSendBufferSize()Deprecated.Gets the socket's sendBufferSize.intgetSoTimeout()Deprecated.java.lang.StringgetVirtualHost()Deprecated.no longer applicablebooleanisOpen()Deprecated.Tests if the connection is open.booleanisProxied()Deprecated.Returns true if the connection is established via a proxy, false otherwise.booleanisResponseAvailable()Deprecated.Tests if input data avaialble.booleanisResponseAvailable(int timeout)Deprecated.Tests if input data becomes available within the given period time in milliseconds.booleanisSecure()Deprecated.Returns true if the connection is established over a secure protocol.booleanisStaleCheckingEnabled()Deprecated.booleanisTransparent()Deprecated.Indicates if the connection is completely transparent from end to end.voidopen()Deprecated.Establishes a connection to the specified host and port (via a proxy if specified).voidprint(java.lang.String data)Deprecated.Useprint(String, String)Writes the specified String (as bytes) to the output stream.voidprint(java.lang.String data, java.lang.String charset)Deprecated.Writes the specified String (as bytes) to the output stream.voidprintLine()Deprecated.Writes "\r\n".getBytes() to the output stream.voidprintLine(java.lang.String data)Deprecated.UseprintLine(String, String)Writes the specified String (as bytes), followed by "\r\n".getBytes() to the output stream.voidprintLine(java.lang.String data, java.lang.String charset)Deprecated.Writes the specified String (as bytes), followed by "\r\n".getBytes() to the output stream.java.lang.StringreadLine()Deprecated.use #readLine(String)java.lang.StringreadLine(java.lang.String charset)Deprecated.Reads up to "\n" from the (unchunked) input stream.voidreleaseConnection()Deprecated.Releases the connection.voidsetConnectionTimeout(int timeout)Deprecated.voidsetHost(java.lang.String host)Deprecated.Sets the host to connect to.voidsetHttpConnectionManager(HttpConnectionManager httpConnectionManager)Deprecated.Sets the httpConnectionManager.voidsetLastResponseInputStream(java.io.InputStream inStream)Deprecated.Set the state to keep track of the last response for the last request.voidsetLocalAddress(java.net.InetAddress localAddress)Deprecated.Set the local address used when creating the connection.voidsetParams(HttpConnectionParams params)Deprecated.AssignsHTTP protocol parametersfor this method.voidsetPort(int port)Deprecated.Sets the port to connect to.voidsetProtocol(Protocol protocol)Deprecated.Sets the protocol used to establish the connectionvoidsetProxyHost(java.lang.String host)Deprecated.Sets the host to proxy through.voidsetProxyPort(int port)Deprecated.Sets the port of the host to proxy through.voidsetSendBufferSize(int sendBufferSize)Deprecated.voidsetSocketTimeout(int timeout)Deprecated.SetsSO_TIMEOUTvalue directly on the underlyingsocket.voidsetSoTimeout(int timeout)Deprecated.voidsetStaleCheckingEnabled(boolean staleCheckEnabled)Deprecated.voidsetVirtualHost(java.lang.String host)Deprecated.no longer applicablevoidshutdownOutput()Deprecated.unusedvoidtunnelCreated()Deprecated.Instructs the proxy to establish a secure tunnel to the host.voidwrite(byte[] data)Deprecated.Writes the specified bytes to the output stream.voidwrite(byte[] data, int offset, int length)Deprecated.Writes length bytes in data starting at offset to the output stream.voidwriteLine()Deprecated.Writes "\r\n".getBytes() to the output stream.voidwriteLine(byte[] data)Deprecated.Writes the specified bytes, followed by "\r\n".getBytes() to the output stream.
-
-
-
Constructor Detail
-
HttpConnection
public HttpConnection(java.lang.String host, int port)Deprecated.Creates a new HTTP connection for the given host and port.- Parameters:
host- the host to connect toport- the port to connect to
-
HttpConnection
public HttpConnection(java.lang.String host, int port, Protocol protocol)Deprecated.Creates a new HTTP connection for the given host and port using the given protocol.- Parameters:
host- the host to connect toport- the port to connect toprotocol- the protocol to use
-
HttpConnection
public HttpConnection(java.lang.String host, java.lang.String virtualHost, int port, Protocol protocol)Deprecated.Creates a new HTTP connection for the given host with the virtual alias and port using given protocol.- Parameters:
host- the host to connect tovirtualHost- the virtual host requests will be sent toport- the port to connect toprotocol- the protocol to use
-
HttpConnection
public HttpConnection(java.lang.String proxyHost, int proxyPort, java.lang.String host, int port)Deprecated.Creates a new HTTP connection for the given host and port via the given proxy host and port using the default protocol.- Parameters:
proxyHost- the host to proxy viaproxyPort- the port to proxy viahost- the host to connect toport- the port to connect to
-
HttpConnection
public HttpConnection(HostConfiguration hostConfiguration)
Deprecated.Creates a new HTTP connection for the given host configuration.- Parameters:
hostConfiguration- the host/proxy/protocol to use
-
HttpConnection
public HttpConnection(java.lang.String proxyHost, int proxyPort, java.lang.String host, java.lang.String virtualHost, int port, Protocol protocol)Deprecated.use #HttpConnection(String, int, String, int, Protocol)Creates a new HTTP connection for the given host with the virtual alias and port via the given proxy host and port using the given protocol.- Parameters:
proxyHost- the host to proxy viaproxyPort- the port to proxy viahost- the host to connect to. Parameter value must be non-null.virtualHost- No longer applicable.port- the port to connect toprotocol- The protocol to use. Parameter value must be non-null.
-
HttpConnection
public HttpConnection(java.lang.String proxyHost, int proxyPort, java.lang.String host, int port, Protocol protocol)Deprecated.Creates a new HTTP connection for the given host with the virtual alias and port via the given proxy host and port using the given protocol.- Parameters:
proxyHost- the host to proxy viaproxyPort- the port to proxy viahost- the host to connect to. Parameter value must be non-null.port- the port to connect toprotocol- The protocol to use. Parameter value must be non-null.
-
-
Method Detail
-
getHost
public java.lang.String getHost()
Deprecated.Returns the host.- Returns:
- the host.
-
setHost
public void setHost(java.lang.String host) throws java.lang.IllegalStateExceptionDeprecated.Sets the host to connect to.- Parameters:
host- the host to connect to. Parameter value must be non-null.- Throws:
java.lang.IllegalStateException- if the connection is already open
-
getVirtualHost
public java.lang.String getVirtualHost()
Deprecated.no longer applicableReturns the target virtual host.- Returns:
- the virtual host.
-
setVirtualHost
public void setVirtualHost(java.lang.String host) throws java.lang.IllegalStateExceptionDeprecated.no longer applicableSets the virtual host to target.- Parameters:
host- the virtual host name that should be used instead of physical host name when sending HTTP requests. Virtual host name can be set to null if virtual host name is not to be used- Throws:
java.lang.IllegalStateException- if the connection is already open
-
getPort
public int getPort()
Deprecated.Returns the port of the host. If the port is -1 (or less than 0) the default port for the current protocol is returned.- Returns:
- the port.
-
setPort
public void setPort(int port) throws java.lang.IllegalStateExceptionDeprecated.Sets the port to connect to.- Parameters:
port- the port to connect to- Throws:
java.lang.IllegalStateException- if the connection is already open
-
getProxyHost
public java.lang.String getProxyHost()
Deprecated.Returns the proxy host.- Returns:
- the proxy host.
-
setProxyHost
public void setProxyHost(java.lang.String host) throws java.lang.IllegalStateExceptionDeprecated.Sets the host to proxy through.- Parameters:
host- the host to proxy through.- Throws:
java.lang.IllegalStateException- if the connection is already open
-
getProxyPort
public int getProxyPort()
Deprecated.Returns the port of the proxy host.- Returns:
- the proxy port.
-
setProxyPort
public void setProxyPort(int port) throws java.lang.IllegalStateExceptionDeprecated.Sets the port of the host to proxy through.- Parameters:
port- the port of the host to proxy through.- Throws:
java.lang.IllegalStateException- if the connection is already open
-
isSecure
public boolean isSecure()
Deprecated.Returns true if the connection is established over a secure protocol.- Returns:
- true if connected over a secure protocol.
-
getProtocol
public Protocol getProtocol()
Deprecated.Returns the protocol used to establish the connection.- Returns:
- The protocol
-
setProtocol
public void setProtocol(Protocol protocol)
Deprecated.Sets the protocol used to establish the connection- Parameters:
protocol- The protocol to use.- Throws:
java.lang.IllegalStateException- if the connection is already open
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
Deprecated.Return the local address used when creating the connection. If null, the default address is used.- Returns:
- InetAddress the local address to be used when creating Sockets
-
setLocalAddress
public void setLocalAddress(java.net.InetAddress localAddress)
Deprecated.Set the local address used when creating the connection. If unset or null, the default address is used.- Parameters:
localAddress- the local address to use
-
isOpen
public boolean isOpen()
Deprecated.Tests if the connection is open.- Returns:
trueif the connection is open
-
closeIfStale
public boolean closeIfStale() throws java.io.IOExceptionDeprecated.Closes the connection if stale.- Returns:
trueif the connection was stale and therefore closed,falseotherwise.- Throws:
java.io.IOException- Since:
- 3.0
- See Also:
isStale()
-
isStaleCheckingEnabled
public boolean isStaleCheckingEnabled()
Deprecated.Tests if stale checking is enabled.- Returns:
trueif enabled- See Also:
isStale()
-
setStaleCheckingEnabled
public void setStaleCheckingEnabled(boolean staleCheckEnabled)
Deprecated.Sets whether or not isStale() will be called when testing if this connection is open.Setting this flag to
falsewill increase performance when reusing connections, but it will also make them less reliable. Stale checking ensures that connections are viable before they are used. When set tofalsesome method executions will result in IOExceptions and they will have to be retried.
-
isProxied
public boolean isProxied()
Deprecated.Returns true if the connection is established via a proxy, false otherwise.- Returns:
- true if a proxy is used to establish the connection, false otherwise.
-
setLastResponseInputStream
public void setLastResponseInputStream(java.io.InputStream inStream)
Deprecated.Set the state to keep track of the last response for the last request.The connection managers use this to ensure that previous requests are properly closed before a new request is attempted. That way, a GET request need not be read in its entirety before a new request is issued. Instead, this stream can be closed as appropriate.
- Parameters:
inStream- The stream associated with an HttpMethod.
-
getLastResponseInputStream
public java.io.InputStream getLastResponseInputStream()
Deprecated.Returns the stream used to read the last response's body.Clients will generally not need to call this function unless using HttpConnection directly, instead of calling
HttpClient.executeMethod(org.apache.commons.httpclient.HttpMethod). For those clients, call this function, and if it returns a non-null stream, close the stream before attempting to execute a method. Note that calling "close" on the stream returned by this function may close the connection if the previous response contained a "Connection: close" header.- Returns:
- An
InputStreamcorresponding to the body of the last response.
-
getParams
public HttpConnectionParams getParams()
Deprecated.ReturnsHTTP protocol parametersassociated with this method.- Returns:
- HTTP parameters.
- Since:
- 3.0
-
setParams
public void setParams(HttpConnectionParams params)
Deprecated.AssignsHTTP protocol parametersfor this method.- Since:
- 3.0
- See Also:
HttpConnectionParams
-
setSoTimeout
public void setSoTimeout(int timeout) throws java.net.SocketException, java.lang.IllegalStateExceptionDeprecated.Set theSocket's timeout, viaSocket.setSoTimeout(int). If the connection is already open, the SO_TIMEOUT is changed. If no connection is open, then subsequent connections will use the timeout value.Note: This is not a connection timeout but a timeout on network traffic!
- Parameters:
timeout- the timeout value- Throws:
java.net.SocketException- - if there is an error in the underlying protocol, such as a TCP error.java.lang.IllegalStateException
-
setSocketTimeout
public void setSocketTimeout(int timeout) throws java.net.SocketException, java.lang.IllegalStateExceptionDeprecated.SetsSO_TIMEOUTvalue directly on the underlyingsocket. This method does not change the default read timeout value set viaHttpConnectionParams.- Parameters:
timeout- the timeout value- Throws:
java.net.SocketException- - if there is an error in the underlying protocol, such as a TCP error.java.lang.IllegalStateException- if not connected- Since:
- 3.0
-
getSoTimeout
public int getSoTimeout() throws java.net.SocketExceptionDeprecated.Returns theSocket's timeout, viaSocket.getSoTimeout(), if the connection is already open. If no connection is open, return the value subsequent connection will use.Note: This is not a connection timeout but a timeout on network traffic!
- Returns:
- the timeout value
- Throws:
java.net.SocketException
-
setConnectionTimeout
public void setConnectionTimeout(int timeout)
Deprecated.Sets the connection timeout. This is the maximum time that may be spent until a connection is established. The connection will fail after this amount of time.- Parameters:
timeout- The timeout in milliseconds. 0 means timeout is not used.
-
open
public void open() throws java.io.IOExceptionDeprecated.Establishes a connection to the specified host and port (via a proxy if specified). The underlying socket is created from theProtocolSocketFactory.- Throws:
java.io.IOException- if an attempt to establish the connection results in an I/O error.
-
tunnelCreated
public void tunnelCreated() throws java.lang.IllegalStateException, java.io.IOExceptionDeprecated.Instructs the proxy to establish a secure tunnel to the host. The socket will be switched to the secure socket. Subsequent communication is done via the secure socket. The method can only be called once on a proxied secure connection.- Throws:
java.lang.IllegalStateException- if connection is not secure and proxied or if the socket is already secure.java.io.IOException- if an attempt to establish the secure tunnel results in an I/O error.
-
isTransparent
public boolean isTransparent()
Deprecated.Indicates if the connection is completely transparent from end to end.- Returns:
- true if conncetion is not proxied or tunneled through a transparent proxy; false otherwise.
-
flushRequestOutputStream
public void flushRequestOutputStream() throws java.io.IOExceptionDeprecated.Flushes the output request stream. This method should be called to ensure that data written to the request OutputStream is sent to the server.- Throws:
java.io.IOException- if an I/O problem occurs
-
getRequestOutputStream
public java.io.OutputStream getRequestOutputStream() throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Returns anOutputStreamsuitable for writing the request.- Returns:
- a stream to write the request to
- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs
-
getResponseInputStream
public java.io.InputStream getResponseInputStream() throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Return aInputStreamsuitable for reading the response.- Returns:
- InputStream The response input stream.
- Throws:
java.io.IOException- If an IO problem occursjava.lang.IllegalStateException- If the connection isn't open.
-
isResponseAvailable
public boolean isResponseAvailable() throws java.io.IOExceptionDeprecated.Tests if input data avaialble. This method returns immediately and does not perform any read operations on the input socket- Returns:
- boolean true if input data is available, false otherwise.
- Throws:
java.io.IOException- If an IO problem occursjava.lang.IllegalStateException- If the connection isn't open.
-
isResponseAvailable
public boolean isResponseAvailable(int timeout) throws java.io.IOExceptionDeprecated.Tests if input data becomes available within the given period time in milliseconds.- Parameters:
timeout- The number milliseconds to wait for input data to become available- Returns:
- boolean true if input data is availble, false otherwise.
- Throws:
java.io.IOException- If an IO problem occursjava.lang.IllegalStateException- If the connection isn't open.
-
write
public void write(byte[] data) throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Writes the specified bytes to the output stream.- Parameters:
data- the data to be written- Throws:
java.lang.IllegalStateException- if not connectedjava.io.IOException- if an I/O problem occurs- See Also:
write(byte[],int,int)
-
write
public void write(byte[] data, int offset, int length) throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Writes length bytes in data starting at offset to the output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.- Parameters:
data- array containing the data to be written.offset- the start offset in the data.length- the number of bytes to write.- Throws:
java.lang.IllegalStateException- if not connectedjava.io.IOException- if an I/O problem occurs
-
writeLine
public void writeLine(byte[] data) throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Writes the specified bytes, followed by "\r\n".getBytes() to the output stream.- Parameters:
data- the bytes to be written- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs
-
writeLine
public void writeLine() throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Writes "\r\n".getBytes() to the output stream.- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs
-
print
public void print(java.lang.String data) throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Useprint(String, String)Writes the specified String (as bytes) to the output stream.- Parameters:
data- the string to be written- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs
-
print
public void print(java.lang.String data, java.lang.String charset) throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Writes the specified String (as bytes) to the output stream.- Parameters:
data- the string to be writtencharset- the charset to use for writing the data- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs- Since:
- 3.0
-
printLine
public void printLine(java.lang.String data) throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.UseprintLine(String, String)Writes the specified String (as bytes), followed by "\r\n".getBytes() to the output stream.- Parameters:
data- the data to be written- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs
-
printLine
public void printLine(java.lang.String data, java.lang.String charset) throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Writes the specified String (as bytes), followed by "\r\n".getBytes() to the output stream.- Parameters:
data- the data to be writtencharset- the charset to use for writing the data- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs- Since:
- 3.0
-
printLine
public void printLine() throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Writes "\r\n".getBytes() to the output stream.- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs
-
readLine
public java.lang.String readLine() throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.use #readLine(String)Reads up to "\n" from the (unchunked) input stream. If the stream ends before the line terminator is found, the last part of the string will still be returned.- Returns:
- a line from the response
- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs
-
readLine
public java.lang.String readLine(java.lang.String charset) throws java.io.IOException, java.lang.IllegalStateExceptionDeprecated.Reads up to "\n" from the (unchunked) input stream. If the stream ends before the line terminator is found, the last part of the string will still be returned.- Parameters:
charset- the charset to use for reading the data- Returns:
- a line from the response
- Throws:
java.lang.IllegalStateException- if the connection is not openjava.io.IOException- if an I/O problem occurs- Since:
- 3.0
-
shutdownOutput
public void shutdownOutput()
Deprecated.unusedAttempts to shutdown theSocket's output, via Socket.shutdownOutput() when running on JVM 1.3 or higher.
-
close
public void close()
Deprecated.Closes the socket and streams.
-
getHttpConnectionManager
public HttpConnectionManager getHttpConnectionManager()
Deprecated.Returns the httpConnectionManager.- Returns:
- HttpConnectionManager
-
setHttpConnectionManager
public void setHttpConnectionManager(HttpConnectionManager httpConnectionManager)
Deprecated.Sets the httpConnectionManager.- Parameters:
httpConnectionManager- The httpConnectionManager to set
-
releaseConnection
public void releaseConnection()
Deprecated.Releases the connection. If the connection is locked or does not have a connection manager associated with it, this method has no effect. Note that it is completely safe to call this method multiple times.
-
getSendBufferSize
public int getSendBufferSize() throws java.net.SocketExceptionDeprecated.Gets the socket's sendBufferSize.- Returns:
- the size of the buffer for the socket OutputStream, -1 if the value has not been set and the socket has not been opened
- Throws:
java.net.SocketException- if an error occurs while getting the socket value- See Also:
Socket.getSendBufferSize()
-
setSendBufferSize
public void setSendBufferSize(int sendBufferSize) throws java.net.SocketExceptionDeprecated.Sets the socket's sendBufferSize.- Parameters:
sendBufferSize- the size to set for the socket OutputStream- Throws:
java.net.SocketException- if an error occurs while setting the socket value- See Also:
Socket.setSendBufferSize(int)
-
-