def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
}
public class OkHttpBuilder extends HttpBuilder
HttpBuilder
implementation based on the OkHttp client library.
Generally, this class should not be used directly, the preferred method of instantiation is via one of the two static configure()
methods of this
class or using one of the configure
methods of HttpBuilder
with a factory function for this builder.
HttpBuilder.ResponseHandlerFunction
Modifier | Constructor and Description |
---|---|
protected |
OkHttpBuilder(HttpObjectConfig config) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
static HttpBuilder |
configure(Closure closure)
Creates an
HttpBuilder using the OkHttpBuilder factory instance configured with the provided configuration closure. |
static HttpBuilder |
configure(java.util.function.Consumer<HttpObjectConfig> configuration)
Creates an
HttpBuilder using the OkHttpBuilder factory instance configured with the provided configuration function. |
protected java.lang.Object |
doDelete(ChainedHttpConfig chainedConfig) |
protected java.lang.Object |
doGet(ChainedHttpConfig chainedConfig) |
protected java.lang.Object |
doHead(ChainedHttpConfig chainedConfig) |
protected java.lang.Object |
doOptions(ChainedHttpConfig config) |
protected java.lang.Object |
doPatch(ChainedHttpConfig chainedConfig) |
protected java.lang.Object |
doPost(ChainedHttpConfig chainedConfig) |
protected java.lang.Object |
doPut(ChainedHttpConfig chainedConfig) |
protected java.lang.Object |
doTrace(ChainedHttpConfig config) |
java.lang.Object |
getClientImplementation()
Retrieves the internal client implementation as an
OkHttpClient instance. |
java.util.concurrent.Executor |
getExecutor() |
protected ChainedHttpConfig |
getObjectConfig() |
addCookieStore, configure, configure, configure, cookies, cookiesToAdd, delete, delete, delete, delete, delete, deleteAsync, deleteAsync, deleteAsync, deleteAsync, deleteAsync, findCause, get, get, get, get, get, getAsync, getAsync, getAsync, getAsync, getAsync, getCookieManager, getCookieStore, handleException, head, head, head, head, head, headAsync, headAsync, headAsync, headAsync, headAsync, options, options, options, options, options, optionsAsync, optionsAsync, optionsAsync, optionsAsync, optionsAsync, patch, patch, patch, patch, patch, patchAsync, patchAsync, patchAsync, patchAsync, patchAsync, post, post, post, post, post, postAsync, postAsync, postAsync, postAsync, postAsync, put, put, put, put, put, putAsync, putAsync, putAsync, putAsync, putAsync, trace, trace, trace, trace, trace, traceAsync, traceAsync, traceAsync, traceAsync, traceAsync
protected OkHttpBuilder(HttpObjectConfig config)
public java.lang.Object getClientImplementation()
Retrieves the internal client implementation as an OkHttpClient
instance.
getClientImplementation
in class HttpBuilder
OkHttpClient
public static HttpBuilder configure(@DelegatesTo(value=HttpObjectConfig.class) Closure closure)
Creates an HttpBuilder
using the OkHttpBuilder
factory instance configured with the provided configuration closure.
The configuration closure delegates to the HttpObjectConfig
interface, which is an extension of the HttpConfig
interface -
configuration properties from either may be applied to the global client configuration here. See the documentation for those interfaces for
configuration property details.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
}
closure
- the configuration closure (delegated to HttpObjectConfig
)HttpBuilder
public static HttpBuilder configure(java.util.function.Consumer<HttpObjectConfig> configuration)
Creates an HttpBuilder
using the OkHttpBuilder
factory instance configured with the provided configuration function.
The configuration Consumer
function accepts an instance of the HttpObjectConfig
interface, which is an extension of the HttpConfig
interface - configuration properties from either may be applied to the global client configuration here. See the documentation for those interfaces for
configuration property details.
This configuration method is generally meant for use with standard Java.
HttpBuilder.configure(new Consumer<HttpObjectConfig>() {
public void accept(HttpObjectConfig config) {
config.getRequest().setUri(format("http://localhost:%d", serverRule.getPort()));
}
});
Or, using lambda expressions:
HttpBuilder.configure(config -> {
config.getRequest().setUri(format("http://localhost:%d", serverRule.getPort()));
});
configuration
- the configuration function (accepting HttpObjectConfig
)HttpBuilder
protected ChainedHttpConfig getObjectConfig()
getObjectConfig
in class HttpBuilder
public java.util.concurrent.Executor getExecutor()
getExecutor
in class HttpBuilder
protected java.lang.Object doGet(ChainedHttpConfig chainedConfig)
doGet
in class HttpBuilder
protected java.lang.Object doHead(ChainedHttpConfig chainedConfig)
doHead
in class HttpBuilder
protected java.lang.Object doPost(ChainedHttpConfig chainedConfig)
doPost
in class HttpBuilder
protected java.lang.Object doPut(ChainedHttpConfig chainedConfig)
doPut
in class HttpBuilder
protected java.lang.Object doPatch(ChainedHttpConfig chainedConfig)
doPatch
in class HttpBuilder
protected java.lang.Object doDelete(ChainedHttpConfig chainedConfig)
doDelete
in class HttpBuilder
protected java.lang.Object doOptions(ChainedHttpConfig config)
doOptions
in class HttpBuilder
protected java.lang.Object doTrace(ChainedHttpConfig config)
doTrace
in class HttpBuilder
public void close() throws java.io.IOException
java.io.IOException