我尝试连接到我的一个端点方法,从Android客户端连接到我本地运行的应用引擎后端。问题是我收到了SSLHandshakeException。我的API不受OAuth保护。我想要达到的方法如下:
@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;
}
}
从我的客户那里我这样做:
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();
}
由于某些原因,这不起作用,我也尝试使用将后端模块导入android studio时获得的API,但它会给出相同的错误。
日志:
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
答案 0 :(得分:3)
所以......问题是我在客户端上设置rootUrl时使用的是https而不是http。