[(applysockettimeout)] Apply socket and connection timeout in OkHttpRestfulClientFactory.
This commit is contained in:
parent
cc20893018
commit
459ff0e64c
|
@ -4,6 +4,7 @@ import java.net.InetSocketAddress;
|
|||
import java.net.Proxy;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
|
@ -62,7 +63,12 @@ public class OkHttpRestfulClientFactory extends RestfulClientFactory {
|
|||
|
||||
public synchronized Call.Factory getNativeClient() {
|
||||
if (myNativeClient == null) {
|
||||
myNativeClient = new OkHttpClient();
|
||||
myNativeClient = new OkHttpClient()
|
||||
.newBuilder()
|
||||
.connectTimeout(getConnectTimeout(), TimeUnit.MILLISECONDS)
|
||||
.readTimeout(getSocketTimeout(), TimeUnit.MILLISECONDS)
|
||||
.writeTimeout(getSocketTimeout(), TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
return myNativeClient;
|
||||
|
|
|
@ -42,4 +42,18 @@ public class OkHttpRestfulClientFactoryTest {
|
|||
assertSame(okHttpClient, clientFactory.getNativeClient());
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testSocketTimeout() {
|
||||
clientFactory.setSocketTimeout(1515);
|
||||
|
||||
assertEquals(1515, ((OkHttpClient)clientFactory.getNativeClient()).readTimeoutMillis());
|
||||
assertEquals(1515, ((OkHttpClient)clientFactory.getNativeClient()).writeTimeoutMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectTimeout() {
|
||||
clientFactory.setConnectTimeout(1516);
|
||||
|
||||
assertEquals(1516, ((OkHttpClient)clientFactory.getNativeClient()).connectTimeoutMillis());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue