问题
I'm trying to connect to one of my endpoint methods from an android client to my locally running app engine backend. The problem is I'm getting a SSLHandshakeException. My API is not protected by OAuth. The method I am trying to reach looks like this:
@ApiMethod(name = "register")
public UserInfo registerUser(UserInfo userInfo) {
try {
checkUserParameters(userInfo);
ofy().save().entity(userInfo).now();
return ofy().load().entity(userInfo).now();
} catch (InvalidPropertiesFormatException e) {
logger.info(e.getMessage());
return null;
}
}
And from my client I am doing this:
if (regService == null) {
UserInfoApi.Builder builder = new UserInfoApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
.setRootUrl(LoginActivity.LOCALHOST_IP)
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
regService = builder.build();
UserInfo userInfo = new UserInfo();
userInfo.setGcmId(registerToGcm());
userInfo.setAccountName(params[0]);
userInfo.setEmail(params[0]);
userInfo.setProfilePictureUrl(null);
UserInfo userInfo = regService.register(userInfo).execute();
}
For some reason this does not work, I have also tried with the API that you get when importing the backend module to android studio but it gives the same error.
Logs:
03-18 12:21:21.642 30454-30477/huka.com.repli W/System.err﹕ javax.net.ssl.SSLHandshakeException: Handshake failed
03-18 12:21:21.642 30454-30477/huka.com.repli W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
03-18 12:21:21.642 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.Connection.upgradeToTls(Connection.java:197)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.Connection.connect(Connection.java:151)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:208)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at gcm.GcmRegistrationAsyncTask.registerToService(GcmRegistrationAsyncTask.java:80)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at gcm.GcmRegistrationAsyncTask.doInBackground(GcmRegistrationAsyncTask.java:69)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at gcm.GcmRegistrationAsyncTask.doInBackground(GcmRegistrationAsyncTask.java:26)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xaf724200: Failure in SSL library, usually a protocol error
03-18 12:21:21.643 30454-30477/huka.com.repli W/System.err﹕ error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:790 0xac490e61:0x00000000)
03-18 12:21:21.644 30454-30477/huka.com.repli W/System.err﹕ at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
03-18 12:21:21.644 30454-30477/huka.com.repli W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302)
03-18 12:21:21.644 30454-30477/huka.com.repli W/System.err﹕ ... 23 more
回答1:
So... The problem was I was using https instead of http when setting rootUrl on the client.
来源:https://stackoverflow.com/questions/29114785/sslhandshakeexception-when-trying-to-reach-app-engine-endpoint