/**
* configures the rest engine
*/
@Override
public void configure(final BreinConfig config) {
final long connectionTimeout = config.getConnectionTimeout();
final long socketTimeout = config.getSocketTimeout();
if (connectionTimeout != 0 && socketTimeout != 0) {
Options.refresh();
Unirest.setTimeouts(connectionTimeout, socketTimeout);
// we need to warm-up Unirest, see https://github.com/Mashape/unirest-java/issues/92
final Future<HttpResponse<String>> future = Unirest
.get("https://www.breinify.com").asStringAsync();
while (!future.isDone()) {
// wait for the request to return
}
}
}
java类com.mashape.unirest.http.options.Options的实例源码
UniRestEngine.java 文件源码
项目:brein-api-library-java
阅读 20
收藏 0
点赞 0
评论 0
TestWithProxiedEmbeddedServer.java 文件源码
项目:Bastion
阅读 24
收藏 0
点赞 0
评论 0
@BeforeClass
public static void setupProxying() {
DnsResolver dnsResolver = prepareProxiedDnsResolver();
DefaultSchemePortResolver schemePortResolver = prepareSchemePortResolver();
BasicHttpClientConnectionManager connManager = prepareConnectionManager(dnsResolver, schemePortResolver);
HttpClient httpClient = prepareHttpClient(connManager);
originalHttpClient = (HttpClient) Options.getOption(Option.HTTPCLIENT);
Unirest.setHttpClient(httpClient);
}
Unirest.java 文件源码
项目:unirest-android
阅读 23
收藏 0
点赞 0
评论 0
/**
* Set the connection timeout and socket timeout
*/
public static void setTimeouts(long connectionTimeout, long socketTimeout) {
Options.setOption(Option.CONNECTION_TIMEOUT, connectionTimeout);
Options.setOption(Option.SOCKET_TIMEOUT, socketTimeout);
// Reload the client implementations
Options.refresh();
}
Unirest.java 文件源码
项目:unirest-android
阅读 23
收藏 0
点赞 0
评论 0
/**
* Set default header
*/
@SuppressWarnings("unchecked")
public static void setDefaultHeader(String name, String value) {
Object headers = Options.getOption(Option.DEFAULT_HEADERS);
if (headers == null) {
headers = new HashMap<String, String>();
}
((Map<String, String>) headers).put(name, value);
Options.setOption(Option.DEFAULT_HEADERS, headers);
}
Connection.java 文件源码
项目:invoiced-java
阅读 23
收藏 0
点赞 0
评论 0
private void refreshUnirestConnection() {
Connection.closeAll();
Options.refresh();
}
ClientFactory.java 文件源码
项目:unirest-android
阅读 21
收藏 0
点赞 0
评论 0
public static HttpClient getHttpClient() {
return (HttpClient) Options.getOption(Option.HTTPCLIENT);
}
ClientFactory.java 文件源码
项目:unirest-android
阅读 21
收藏 0
点赞 0
评论 0
public static CloseableHttpAsyncClient getAsyncHttpClient() {
return (CloseableHttpAsyncClient) Options.getOption(Option.ASYNCHTTPCLIENT);
}
Unirest.java 文件源码
项目:unirest-android
阅读 26
收藏 0
点赞 0
评论 0
/**
* Set the HttpClient implementation to use for every synchronous request
*/
public static void setHttpClient(HttpClient httpClient) {
Options.setOption(Option.HTTPCLIENT, httpClient);
}
Unirest.java 文件源码
项目:unirest-android
阅读 21
收藏 0
点赞 0
评论 0
/**
* Clear default headers
*/
public static void clearDefaultHeaders() {
Options.setOption(Option.DEFAULT_HEADERS, null);
}
Unirest.java 文件源码
项目:unirest-android
阅读 21
收藏 0
点赞 0
评论 0
/**
* Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request
*/
public static void setAsyncHttpClient(CloseableHttpAsyncClient asyncHttpClient) {
Options.setOption(Option.ASYNCHTTPCLIENT, asyncHttpClient);
}
Unirest.java 文件源码
项目:unirest-android
阅读 23
收藏 0
点赞 0
评论 0
/**
* Close the asynchronous client and its event loop. Use this method to close all the threads and allow an application to exit.
*/
public static void shutdown() throws IOException {
CloseableHttpAsyncClient asyncClient = (CloseableHttpAsyncClient) Options.getOption(Option.ASYNCHTTPCLIENT);
if (asyncClient.isRunning()) asyncClient.close();
}
Consul.java 文件源码
项目:beyondj
阅读 20
收藏 0
点赞 0
评论 0
/**
* With some frameworks it is necessary to refresh the unirest connection pool state
* during runtime. This method does just that.
*/
public void startup() {
Options.refresh();
}