I'm getting Connection refused error when I'm using a proxy configuration in Android Studio and send a request to server.
Does anyone have a light about this?
This is my Client builder:
SSLContext sslContext = SSLContext.getInstance("SSL");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStorePass.toCharArray());
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
client = new OkHttpClient.Builder().sslSocketFactory(sslContext.getSocketFactory())
.hostnameVerifier(new HostnameVerifier() {
#Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}).connectTimeout(timeout, TimeUnit.MILLISECONDS)
.readTimeout(timeout, TimeUnit.MILLISECONDS)
.writeTimeout(timeout, TimeUnit.MILLISECONDS).build();
This is the Error log:
W/System.err: java.net.ConnectException: Failed to connect to /10.51.33.41:443
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:222)
W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:146)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:186)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
at okhttp3.RealCall.execute(RealCall.java:63)
W/System.err: at br.com.oi.http.HttpClient.doRequest(HttpClient.java:192)
at br.com.oi.http.HttpClient.doRequest(HttpClient.java:86)
at br.com.oi.dadosfacil.service.oi.login.LoginService.run(LoginService.java:64)
at br.com.oi.http.BaseService.onHandleIntent(BaseService.java:38)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
W/System.err: at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.net.ConnectException: failed to connect to /10.51.33.41 (port 443) from /192.163.222.2 (port 49536) after 120000ms: isConnected failed: ECONNREFUSED (Connection refused)
W/System.err: at libcore.io.IoBridge.isConnected(IoBridge.java:273)
at libcore.io.IoBridge.connectErrno(IoBridge.java:188)
at libcore.io.IoBridge.connect(IoBridge.java:130)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356)
W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:357)
W/System.err: at java.net.Socket.connect(Socket.java:616)
at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:63)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:220)
... 25 more
W/System.err: Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.isConnected(IoBridge.java:262)
W/System.err: ... 35 more
I'm using minSdkVersion 19 and targetSdkVersion 26
Related
I created a MQTT broker using Mosquitto library (version - 1.6.12). and created Android mobile app, which acts as paho clients(Libraries Used - 'libs/org.eclipse.paho.client.mqttv3-1.2.0.jar', 'libs/org.eclipse.paho.android.service-1.1.1.jar')
Trying to connect android app to the local Mosquitto broker. I'm able to connect through Android emulator Getting Socket issue When I try with real android device.
Android Code:
MqttAndroidClient client;
String clientId = MqttClient.generateClientId();
//Since broker is running in the same system I gave my local IP-ADDRESS - 192.168.0.100
//Port - 1883
client = new MqttAndroidClient(this.getApplicationContext(), "tcp://192.168.0.100:1883", clientId);
try {
MqttConnectOptions options = new MqttConnectOptions();
options.setKeepAliveInterval(60);
Log.d(TAG, "MqttConnectOptions : "+options.toString());
IMqttToken token = client.connect(options);
token.setActionCallback(new IMqttActionListener() {
#Override
public void onSuccess(IMqttToken asyncActionToken) {
Log.d(TAG, "onSuccess");
}
#Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
Log.d(TAG, "onFailure ");
exception.printStackTrace();
}
});
} catch (MqttException e) {
e.printStackTrace();
}
Android Studio Logs:
2020-10-06 20:27:31.775 23972-23972/com.exam.mqttwithlibs W/System.err: MqttException (0) - java.net.SocketTimeoutException: failed to connect to /192.168.0.100 (port 1883) from /192.168.0.102 (port 37459) after 30000ms
2020-10-06 20:27:31.778 23972-23972/com.exam.mqttwithlibs W/System.err: at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
2020-10-06 20:27:31.779 23972-23972/com.exam.mqttwithlibs W/System.err: at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:715)
2020-10-06 20:27:31.779 23972-23972/com.exam.mqttwithlibs W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
2020-10-06 20:27:31.779 23972-23972/com.exam.mqttwithlibs W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2020-10-06 20:27:31.780 23972-23972/com.exam.mqttwithlibs W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
2020-10-06 20:27:31.780 23972-23972/com.exam.mqttwithlibs W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2020-10-06 20:27:31.780 23972-23972/com.exam.mqttwithlibs W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2020-10-06 20:27:31.781 23972-23972/com.exam.mqttwithlibs W/System.err: at java.lang.Thread.run(Thread.java:764)
2020-10-06 20:27:31.785 23972-23972/com.exam.mqttwithlibs W/System.err: Caused by: java.net.SocketTimeoutException: failed to connect to /192.168.0.100 (port 1883) from /192.168.0.102 (port 37459) after 30000ms
2020-10-06 20:27:31.786 23972-23972/com.exam.mqttwithlibs W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:185)
2020-10-06 20:27:31.786 23972-23972/com.exam.mqttwithlibs W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:129)
2020-10-06 20:27:31.786 23972-23972/com.exam.mqttwithlibs W/System.err: at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:137)
2020-10-06 20:27:31.786 23972-23972/com.exam.mqttwithlibs W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
2020-10-06 20:27:31.787 23972-23972/com.exam.mqttwithlibs W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
2020-10-06 20:27:31.787 23972-23972/com.exam.mqttwithlibs W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
2020-10-06 20:27:31.787 23972-23972/com.exam.mqttwithlibs W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
2020-10-06 20:27:31.788 23972-23972/com.exam.mqttwithlibs W/System.err: at java.net.Socket.connect(Socket.java:621)
2020-10-06 20:27:31.788 23972-23972/com.exam.mqttwithlibs W/System.err: at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:84)
2020-10-06 20:27:31.788 23972-23972/com.exam.mqttwithlibs W/System.err: at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:701)
2020-10-06 20:27:31.788 23972-23972/com.exam.mqttwithlibs W/System.err: ... 6 more
In above image 192.168.0.100 - System's IP and 192.168.0.102 - Android device IP
Thanks for any help.
Open Port 1883 by following this link https://bytesofgigabytes.com/networking/how-to-open-port-in-windows/ solves this issue
If you use Mosquitto as a server on MacOS, you need edit the config file at /opt/homebrew/etc/mosquitto/mosquitto.conf
listener 1883 -- Specify port number
allow_anonymous true
Then restart Mosquitto
I'm retrieving data from an API. When I try to launch the app on an Android emulator running Android API 19 the request fails with the error below.
It work perfectly fine using other versions of the emulator (like Android API 27).
I changed the URL to target another API from a previous project and it works. So it seems the issue is with this specific API but I don't understand why, especially as when I pass the URL into the emulator's browser it works fine.
I've seen some people suggesting this is an issue with the computer's firewall, but there is no firewall enabled on mine.
Retrofit
interface SpaceXApi {
#GET("rockets")
fun getRockets(): Observable<MutableList<RocketDto>>
}
object SpaceXApiConstants {
const val BASE_URL = "https://api.spacexdata.com/v3/"
}
// Interceptor passed to OkHttpClient Builder
class ConnectivityInterceptor(private val context: Context) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
if (isConnected()) {
return chain.proceed(chain.request())
} else {
throw NoNetworkException()
}
}
}
Error
D/OkHttp: --> GET https://api.spacexdata.com/v3/rockets
D/OkHttp: <-- HTTP FAILED: java.net.ConnectException: Failed to connect to api.spacexdata.com/2606:4700:30::681f:5749:443
W/System.err: java.net.ConnectException: Failed to connect to api.spacexdata.com/2606:4700:30::681f:5749:443
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:247)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:165)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:213)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.example.myproject.network.ConnectivityInterceptor.intercept(ConnectivityInterceptor.kt:13)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:42)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
at io.reactivex.Observable.subscribe(Observable.java:12090)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.net.ConnectException: failed to connect to api.spacexdata.com/2606:4700:30::681f:5749 (port 443) after 20000ms: isConnected failed: EHOSTUNREACH (No route to host)
at libcore.io.IoBridge.isConnected(IoBridge.java:223)
at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
12-02 17:44:40.445 4877-4877/com.example.myproject W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:843)
at okhttp3.internal.platform.AndroidPlatform.connectSocket(AndroidPlatform.java:73)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:245)
... 38 more
Caused by: libcore.io.ErrnoException: isConnected failed: EHOSTUNREACH (No route to host)
at libcore.io.IoBridge.isConnected(IoBridge.java:208)
... 45 more
Any solution?
Looks like a protocol issue : devices with API 19 and older don't use TLS 1.2 by default.
You can enable it with this :
ProviderInstaller.installIfNeededAsync(this, new ProviderInstaller.ProviderInstallListener() {
#Override
public void onProviderInstalled() {
}
#Override
public void onProviderInstallFailed(int i, Intent intent) {
Log.i(TAG, "Provider install failed (" + i + ") : SSL Problems may occurs");
}
});
This has to be called before your first call, so I usually call it in the OnCreate of the Application object.
For more information, you can check this link : https://quizlet.com/blog/working-with-tls-1-2-on-android-4-4-and-lower
I am getting the following error :
java.net.ConnectException: failed to connect to /139.59.67.108 (port 21): connect failed: ECONNREFUSED (Connection refused)
Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
at libcore.io.Posix.connect(Native Method)
Here is my code
try
{
FTPClient con = null;
con = new FTPClient();
con.connect("139.59.67.108");
Log.v("checkLogin", "succeeded");
if (con.login("xxxx", "xxxx"))
{
con.enterLocalPassiveMode(); // important!
con.setFileType(FTP.BINARY_FILE_TYPE);
///data/data/com.prd.inspirationslate/databases
String data = "/data/data/com.prd.inspirationslate/databases"; //path on device
FileInputStream in = new FileInputStream(new File(data));
Log.v("upload result check", "succeeded");
boolean result = con.storeFile("/vivekm4a.m4a", in);
in.close();
if (result) Log.v("upload result", "succeeded");
con.logout();
con.disconnect();
}
}
catch (Exception e)
{
e.printStackTrace();
}
trying to upload file via ftp on server . On filezilla I can easily connect
Log trace
java.net.ConnectException: failed to connect to /139.59.67.108 (port 21): connect failed: ECONNREFUSED (Connection refused)
W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:124)
W/System.err: at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
W/System.err: at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:163)
W/System.err: at java.net.Socket.startupSocket(Socket.java:592)
W/System.err: at java.net.Socket.tryAllAddresses(Socket.java:128)
W/System.err: at java.net.Socket.(Socket.java:178)
W/System.err: at java.net.Socket.(Socket.java:150)
W/System.err: at
org.apache.commons.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:53)
W/System.err: at
org.apache.commons.net.SocketClient.connect(SocketClient.java:162)
W/System.err: at
org.apache.commons.net.SocketClient.connect(SocketClient.java:250)
W/System.err: at
com.prd.inspirationslate.LoginActivity$2$1.run(LoginActivity.java:120)
W/System.err: at java.lang.Thread.run(Thread.java:818)
W/System.err: Caused by: android.system.ErrnoException: connect
failed: ECONNREFUSED (Connection refused) W/System.err: at
libcore.io.Posix.connect(Native Method) W/System.err: at
libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111) W/System.err:
at libcore.io.IoBridge.connectErrno(IoBridge.java:137) W/System.err:
at libcore.io.IoBridge.connect(IoBridge.java:122) W/System.err: ...
11 more
I'm having issues with the https connection to a server with a self signed certificate on devices < api 19. I followed this guide published by android for trusting self-signed certifcates Android SSL and it seems to work fine with all the api>19 devices i tested. How ever i keep getting the "Trust anchor for certification path not found" error on pre 19.
I've created the keystore using keytool and doesn't seem to be the problem because is working on some devices.
This is my code:
URL url_uri = new URL(url);
AssetManager am = context.getAssets();
InputStream caInput = am.open("certs/myCert.bks");
KeyStore keyStore;
try {
keyStore = KeyStore.getInstance("BKS");
char[] pass = "MyPassword".toCharArray();
keyStore.load(caInput, pass);
} finally {
caInput.close();
}
// Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
// Create an SSLContext that uses our TrustManager
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
HttpsURLConnection urlConnection =
(HttpsURLConnection)url_uri.openConnection();
urlConnection.setSSLSocketFactory(context.getSocketFactory());
InputStream in = urlConnection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = reader.readLine()) != null){
sb.append(line + NL);
}
in.close();
JSON = sb.toString();
And here is the logcat error:
W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
W/System.err: at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
W/System.err: at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
W/System.err: at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
W/System.err: at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
W/System.err: at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
W/System.err: at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
W/System.err: at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
W/System.err: at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
W/System.err: at com.splunk.mint.network.http.MonitorableHttpsURLConnection.getInputStream(MonitorableHttpsURLConnection.java:73)
W/System.err: at com.w3is2.webservice.JsonConnect.connectSSL(JsonConnect.java:161)
W/System.err: at com.w3is2.webservice.JsonConnect.getFamilias(JsonConnect.java:482)
W/System.err: at com.w3is2.dat.biologia.ListaFamilias$DataLoader.doInBackground(ListaFamilias.java:137)
W/System.err: at com.w3is2.dat.biologia.ListaFamilias$DataLoader.doInBackground(ListaFamilias.java:124)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/System.err: at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
W/System.err: at java.lang.Thread.run(Thread.java:856)W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err: at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:192)
W/System.err: at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:163)
W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:573)
W/System.err: at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
W/System.err: ... 20 more
W/System.err: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
W/System.err: ... 25 more
W/System.err: org.json.JSONException: End of input at character 0 of
W/System.err: at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
W/System.err: at org.json.JSONTokener.nextValue(JSONTokener.java:97)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:154)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:171)
W/System.err: at com.w3is2.webservice.JsonConnect.getFamilias(JsonConnect.java:488)
W/System.err: at com.w3is2.dat.biologia.ListaFamilias$DataLoader.doInBackground(ListaFamilias.java:137)
W/System.err: at com.w3is2.dat.biologia.ListaFamilias$DataLoader.doInBackground(ListaFamilias.java:124)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/System.err: at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
W/System.err: at java.lang.Thread.run(Thread.java:856)
I increased the timeout of okhttp client to 5 minutes:
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(5, TimeUnit.MINUTES);
client.setReadTimeout(5, TimeUnit.MINUTES);
client.setWriteTimeout(5, TimeUnit.MINUTES);
client.interceptors().add(new Interceptor() {
#Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
// Customize the request
Request request = original.newBuilder()
//.header("Accept", "application/json")
.header("Authorization", Constants.SERVICE_AUTH_KEY)
.method(original.method(), original.body())
.build();
// Customize or return the response
return chain.proceed(request);
}
});
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.SERVICE_URL)
.client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
I use WCF Webservice, i also increased the timeout time to same thing.
Everything works perfectly fine, but uploading file or image to the server.
Even after increasing timeout on both Android and WCF, I still get the error on android:
java.net.SocketException: sendto failed: ETIMEDOUT (Connection timed
out)
This is the full log
W/System.err: java.net.SocketException: sendto failed: ETIMEDOUT (Connection timed out)
W/System.err: at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:550)
W/System.err: at libcore.io.IoBridge.sendto(IoBridge.java:519)
W/System.err: at java.net.PlainSocketImpl.write(PlainSocketImpl.java:511)
W/System.err: at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
W/System.err: at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
W/System.err: at okio.Okio$1.write(Okio.java:80)
W/System.err: at okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:46)
W/System.err: at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:302)
W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
W/System.err: at okio.RealBufferedSink.writeAll(RealBufferedSink.java:104)
W/System.err: at com.squareup.okhttp.RequestBody$3.writeTo(RequestBody.java:118)
W/System.err: at com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeOrCountBytes(MultipartBuilder.java:277)
W/System.err: at com.squareup.okhttp.MultipartBuilder$MultipartRequestBody.writeTo(MultipartBuilder.java:297)
W/System.err: at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:887)
W/System.err: at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)
W/System.err: at com.squareup.okhttp.Call.getResponse(Call.java:268)
W/System.err: at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
W/System.err: at com.mbh.mbhportal.network.NewPortalService$1.intercept(NewPortalService.java:59)
W/System.err: at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)
W/System.err: at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
W/System.err: at com.squareup.okhttp.Call.execute(Call.java:79)
W/System.err: at retrofit.OkHttpCall.execute(OkHttpCall.java:116)
W/System.err: at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:111)
W/System.err: at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:88)
W/System.err: at rx.Observable$2.call(Observable.java:162)
W/System.err: at rx.Observable$2.call(Observable.java:154)
W/System.err: at rx.Observable$2.call(Observable.java:162)
W/System.err: at rx.Observable$2.call(Observable.java:154)
W/System.err: at rx.Observable$2.call(Observable.java:162)
W/System.err: at rx.Observable$2.call(Observable.java:154)
W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:8098)
W/System.err: at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:62)
W/System.err: at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
W/System.err: at java.lang.Thread.run(Thread.java:838)
W/System.err: Caused by: libcore.io.ErrnoException: sendto failed: ETIMEDOUT (Connection timed out)
W/System.err: at libcore.io.Posix.sendtoBytes(Native Method)
W/System.err: at libcore.io.Posix.sendto(Posix.java:151)
W/System.err: at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
W/System.err: at libcore.io.IoBridge.sendto(IoBridge.java:517)
W/System.err: ... 40 more
What timeout is this ETIMEDOUT !?