Package com.avoka.component.http
Class GetRequest
java.lang.Object
com.avoka.component.http.HttpRequest
com.avoka.component.http.GetRequest
Provides a GET Request class for performing simple HTTP request operations.
This class provides an easier and safer interface for the Apache HTTP Components library.
The default connection timeout is 10 seconds and socket read timeout is 60 seconds.
Socket connections will also apply any JVM proxy settings automatically.
By default the maximum response read size is 16 MB. If the response is larger than this an IOException will be thrown.
To increase the maximum read limit use the
HttpRequest.setReadLimit(int)
method.
In RESTful services the GET method is used to retrieve resources specified by the URI.
Examples
The example below performs REST request and returns a JSON object
import com.avoka.component.http.GetRequest def params = [:] def params.id = request.getParameter('customerId') def params.account = request.getParameter('accountId') def username = serviceParameters.username def password = serviceParameters.password // execute GET request and return a HttpResponse object def response = new GetRequest('https://service.mycorp.com/secure/rest/accounts/') .setParams(params) .setBasicAuth(username, password) .execute() // check HttpResponse status code if (response.status == 200) { // get JSON object from the response def json = response.getJsonContent() ... } else if (response.status == 404) { // object not found ... } else { throw new RuntimeException(response.statusLine) }
- Since:
- 4.2.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.avoka.component.http.HttpRequest
HttpRequest.Method
-
Constructor Summary
-
Method Summary
Methods inherited from class com.avoka.component.http.HttpRequest
addHeader, addHeadersAll, execute, getContext, setAcceptCompress, setBasicAuth, setCompressMessage, setConnectTimeout, setContentType, setContext, setMessage, setMessageData, setNtlmAuth, setParams, setReadLimit, setSocketFactory, setSocketTimeout, setTimeouts, setUserAgent, toString
-
Constructor Details
-
GetRequest
Create a GET HTTP request object with the given URI.- Parameters:
uri
- the request URI (required)
-