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 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
.
-
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 void
addRequestProperty(String propertyName, String propertyValue)
HttpResult
delete()
protected static Charset
extractCharset(String contentType)
Extract charset fromContent-Type
header.protected static String
extractHeaderComponent(String header, String component)
Extract a component of a header.HttpResult
get()
HttpResult
post()
HttpResult
put()
void
setAuthentication(String username, String password)
Set HTTP authentication.void
setRequestBody(String requestBody)
protected void
writeOutputStream(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, therequestBody
is 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-Type
header.- Parameters:
contentType
-Content-Type
header.- Returns:
- Character set extracted, UTF-8 if no valid charset found.
-
-