I am trying a demo Android app to connect servlet (both local server and aws instance) it gives Handshake failed error. I have tried with volley and http client also. The relevant code and logcat result is following. Currently I am using Android version 7.1 and redmi 5A cellphone for testing.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
execute();
}
void execute() {
new Thread(new Runnable() {
public void run() {
try {
URL url = new URL("https://192.168.0.7:9999/WebS/welcome/test");
URLConnection connection = url.openConnection();
String inputString = "hello server";
//inputString = URLEncoder.encode(inputString, "UTF-8");
Log.d("inputString", inputString);
connection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(inputString);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
Toast.makeText(MainActivity.this, in.toString(), Toast.LENGTH_LONG).show();
in.close();
} catch (Exception e) {
Log.e("YOUR_APP_LOG_TAG", "I got an error", e);
}
}
}).start();}}
Logcat result:
app_url E/YOUR_APP_LOG_TAG: I got an error javax.net.ssl.SSLHandshakeException: Handshake failed at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:429) at com.android.okhttp.Connection.connectTls(Connection.java:235) at com.android.okhttp.Connection.connectSocket(Connection.java:199) at com.android.okhttp.Connection.connect(Connection.java:172) at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367) at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:247) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java) at com.example.cg_dte.app_url.MainActivity$1.run(MainActivity.java:41) at java.lang.Thread.run(Thread.java:760) Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed ... 15 more Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed ... 15 more Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x7fa2258640: Failure in SSL library, usually a protocol error error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.c:192 0x7f94590e7e:0x00000000) at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357) ... 14 more Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x7fa2258640: Failure in SSL library, usually a protocol error error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.c:192 0x7f94590e7e:0x00000000) at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357) ... 14 more Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x7fa2258640: Failure in SSL library, usually a protocol error error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.c:192 0x7f94590e7e:0x00000000) at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357) ... 14 more