Package io.toro.martini
Class HttpClientMethods
- java.lang.Object
-
- io.toro.martini.HttpClientMethods
-
public final class HttpClientMethods extends Object
Provides one-liner methods for HTTP related operations.
HTTP (Hypertext Transfer Protocol) is the set of rules for transferring files on the World Wide Web. The one-liners in this class make it easy to execute HTTP requests (GET/POST), and read responses by returning them as strings.
-
-
Constructor Summary
Constructors Constructor Description HttpClientMethods(io.toro.martini.http.ESBHttpClient esbHttpClient)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
http(String uri)
Send an HTTP GET request.static String
http(String uri, Closure<String> body)
Send an HTTP POST request.static String
http(String uri, String body)
Send an HTTP POST request.static String
http(String uri, Map params)
Send an HTTP request.static String
http(String uri, Map params, Map headers)
Send an HTTP request.static String
http(String uri, Map params, Map headers, byte[] body)
Send an HTTP request.static String
http(String uri, Map params, Map headers, Closure<String> body)
Send an HTTP request.static String
http(String uri, Map params, Map headers, String body)
Send an HTTP request.
-
-
-
Constructor Detail
-
HttpClientMethods
@Autowired HttpClientMethods(io.toro.martini.http.ESBHttpClient esbHttpClient)
-
-
Method Detail
-
http
public static String http(String uri) throws ToroException
Send an HTTP GET request.
Example usage:
def response = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx'.http()
- Parameters:
uri
- the URI where the request will be sent- Returns:
- the response message entity content as a string
- Throws:
ToroException
- Since:
- 1.0
-
http
public static String http(String uri, String body) throws ToroException
Send an HTTP POST request.
Example usage:
def response = 'http://www.example.com'.http('
Hello, world ')- Parameters:
uri
- the URI where the request will be sentbody
- the body content to be sent with the request as a string- Returns:
- the response message entity content as a string
- Throws:
ToroException
- Since:
- 1.0
-
http
public static String http(String uri, Closure<String> body) throws ToroException
Send an HTTP POST request.
Example usage:
boolean success = false; def response = "http://www.example.com".http() { if (success) "Successful" // returns the string even without the keyword return else "Failed to authenticate" }
- Parameters:
uri
- the URI where the request will be sentbody
- a closure returning a string which will be used as the body content of the request- Returns:
- the response message entity content as a string
- Throws:
ToroException
- Since:
- 1.0
-
http
public static String http(String uri, Map params) throws ToroException
Send an HTTP request.
Example usage:
def properties = [ method: "POST", email: "user@your.org", password: "superS3CR3Tpa$$word" ] def response = "https://www.example.com/login".http( properties )
- Parameters:
uri
- the URI where the request will be sentparams
- optional parameters to be sent as part of the request- Returns:
- the response message entity content as a string
- Throws:
ToroException
- Since:
- 1.0
-
http
public static String http(String uri, Map params, Map headers) throws ToroException
Send an HTTP request.
Example usage:
def properties = [ method: "POST", email: "user@your.org", password: "superS3CR3Tpa$$word" ] def header = [ "Content-Type": "text/xml", "Connection": "keep-alive" ] def response = "https://www.example.com/login".http( properties, header )
- Parameters:
uri
- the URI where the request will be sentparams
- optional parameters to be sent as part of the requestheaders
- optional headers to be sent as part of the request- Returns:
- the response message entity content as a string
- Throws:
ToroException
- Since:
- 1.0
-
http
public static String http(String uri, Map params, Map headers, String body) throws ToroException
Send an HTTP request.
Example usage:
def properties = [ method: "POST", email: "user@your.org", password: "superS3CR3Tpa$$word" ] def header = [ "Content-Type": "text/xml", "Connection": "keep-alive" ] def response = "https://www.example.com/login".http( properties, header, "
Hello, world " )- Parameters:
uri
- the URI where the request will be sentparams
- optional parameters to be sent as part of the requestheaders
- optional headers to be sent as part of the requestbody
- the body content to be sent with the request as a string- Returns:
- the response message entity content as a string
- Throws:
ToroException
- Since:
- 1.0
-
http
public static String http(String uri, Map params, Map headers, Closure<String> body) throws ToroException
Send an HTTP request.
Example usage:
def properties = [ method: "POST", email: "user@your.org", password: "superS3CR3Tpa$$word" ] def header = [ "Content-Type": "text/xml", "Connection": "keep-alive" ] boolean success = header != null def response = "https://www.example.com/login".http( properties, header, { if ( success ) "Successful" // returns the string even without the keyword return else "Failed to authenticate" })
- Parameters:
uri
- the URI where the request will be sentbody
- a closure returning a string which will be used as the body content of the requestparams
- optional parameters to be sent as part of the requestheaders
- optional headers to be sent as part of the request- Returns:
- the response message entity content as a string
- Throws:
ToroException
- Since:
- 1.0
-
http
public static String http(String uri, Map params, Map headers, byte[] body) throws ToroException
Send an HTTP request.
Example usage:
def properties = [ method: "POST", email: "user@your.org", password: "superS3CR3Tpa$$word" ] def header = [ "Content-Type": "text/xml", "Connection": "keep-alive" ] def body = "The quick fox jumped over the lazy dog".getBytes() def response = "https://www.example.com/login".http( properties, header, body )
- Parameters:
uri
- the URI where the request will be sentbody
- the body content to be sent with the request as an array of bytesparams
- optional parameters to be sent as part of the requestheaders
- optional headers to be sent as part of the request- Returns:
- the response message entity content as a string
- Throws:
ToroException
- Since:
- 1.0
-
-