Class HttpRequest
- java.lang.Object
-
- org.codehaus.cargo.util.log.LoggedObject
-
- org.codehaus.cargo.container.internal.http.HttpRequest
-
- All Implemented Interfaces:
Loggable
- Direct Known Subclasses:
HttpFileRequest,HttpFormRequest
public class HttpRequest extends LoggedObject
HTTP(S) request class.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intBUFFER_CHUNK_SIZESize of the buffers / chunks used when sending files to the HTTP server.
When trying to upload large amount of data the internal connection buffer can become too large and exceed the heap size, leading to anOutOfMemoryError.
-
Constructor Summary
Constructors Constructor Description HttpRequest(URL url)Constructor.HttpRequest(URL url, long timeout)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRequestProperty(String propertyName, String propertyValue)HttpResultdelete()protected static CharsetextractCharset(String contentType)Extract charset fromContent-Typeheader.protected static StringextractHeaderComponent(String header, String component)Extract a component of a header.HttpResultget()HttpResultpost()HttpResultput()voidsetAuthentication(String username, String password)Set HTTP authentication.voidsetRequestBody(String requestBody)protected voidwriteOutputStream(HttpURLConnection connection)If necessary, writes to the output stream of the HTTP URL connection.-
Methods inherited from class org.codehaus.cargo.util.log.LoggedObject
getLogger, setLogger
-
-
-
-
Field Detail
-
BUFFER_CHUNK_SIZE
protected static final int BUFFER_CHUNK_SIZE
Size of the buffers / chunks used when sending files to the HTTP server.
When trying to upload large amount of data the internal connection buffer can become too large and exceed the heap size, leading to anOutOfMemoryError. This was fixed in JDK 1.5 by introducingHttpURLConnection.setChunkedStreamingMode(int).
As per CARGO-1418, use a sensible chunk size for fast links.- See Also:
- Constant Field Values
-
-
Method Detail
-
addRequestProperty
public void addRequestProperty(String propertyName, String propertyValue)
- Parameters:
propertyName- Name of request header property.propertyValue- Value of request header property.
-
setRequestBody
public void setRequestBody(String requestBody)
- Parameters:
requestBody- String request body to set.
-
setAuthentication
public void setAuthentication(String username, String password)
Set HTTP authentication.- Parameters:
username- User name.password- Password.
-
get
public HttpResult get() throws IOException
- Returns:
- Result of HTTP GET call of this connection.
- Throws:
IOException- If connecting to the server fails.
-
post
public HttpResult post() throws IOException
- Returns:
- Result of HTTP POST call of this connection.
- Throws:
IOException- If connecting to the server fails.
-
put
public HttpResult put() throws IOException
- Returns:
- Result of HTTP PUT call of this connection.
- Throws:
IOException- If connecting to the server fails.
-
delete
public HttpResult delete() throws IOException
- Returns:
- Result of HTTP DELETE call of this connection.
- Throws:
IOException- If connecting to the server fails.
-
writeOutputStream
protected void writeOutputStream(HttpURLConnection connection) throws IOException
If necessary, writes to the output stream of the HTTP URL connection. By default, therequestBodyis written as output.- Parameters:
connection- the HTTP URL connection to read from- Throws:
IOException- if an error happens during the connection establishment or write
-
extractCharset
protected static Charset extractCharset(String contentType)
Extract charset fromContent-Typeheader.- Parameters:
contentType-Content-Typeheader.- Returns:
- Character set extracted, UTF-8 if no valid charset found.
-
-