Google Cloud Endpoints error Caused by: java.lang.IllegalArgumentException: expected primitive class, 但得到了
Google Cloud Endpoints error Caused by: java.lang.IllegalArgumentException: expected primitive class, but got
我有一个从我的 Android 应用调用的简单 Google 云端点。很长一段时间以来,它一直像一个魅力一样工作。最近,我更新了 Android Studio,Gradle 插件,以及项目中的 build.gradle 个文件。
从那时起,Android 应用每次尝试调用该端点时都会返回此错误:
Process: com.berylo.chat, PID: 26426
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.IllegalArgumentException:
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:889)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:382)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:355)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.berylo.chat.Encriptador.doInBackground(Encriptador.java:282)
at com.berylo.chat.Encriptador.doInBackground(Encriptador.java:277)
at android.os.AsyncTask.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.IllegalArgumentException: expected primitive class, but got: class com.crypto.berylo.com.clavePublica4Api.model.RespuestaAlCliente
at com.google.api.client.util.Data.parsePrimitiveValue(Data.java:453)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:859)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:382)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:355)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.berylo.chat.Encriptador.doInBackground(Encriptador.java:282)
at com.berylo.chat.Encriptador.doInBackground(Encriptador.java:277)
at android.os.AsyncTask.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
这是端点代码:
@ApiMethod(name = "obtenerDiasCaducidadClavesDeGrupo",
path = "grupo",
httpMethod = ApiMethod.HttpMethod.GET)
public RespuestaAlCliente obtenerDiasCaducidadClavesDeGrupo(User user)
throws OAuthRequestException, IOException {
String dias = "";
if (user == null)
{
throw new OAuthRequestException("Usuario no valido");
}
else {
dias = DIAS_HASTA_CADUCIDAD_DE_CLAVES_DE_GRUPO;
}
respuestaalcliente.setMessage(dias);
logger.info("respuestaalcliente: " + respuestaalcliente);
return respuestaalcliente;
}
这是 Android 应用代码。触发错误的行标有 THIS ------>
private void obtenernumeroDiasValidezClavesAsimetricas(final Context context){
try {
AsyncTask<Void, Void, String> miTareaAsincrona;
miTareaAsincrona = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
THIS ------> RespuestaAlCliente respuestaAlCliente = MisEndPointsClavePublica.serviceEndPoint.obtenerDiasCaducidadClaveAsimetrica().execute();
return respuestaAlCliente.getMessage();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
protected void onPostExecute(String result) {
if((result != null) && (!result.equals("") && (!result.equals("null")))) {
numeroDiasValidezClaveAsimetrica = parseInt(result);
} else {
numeroDiasValidezClaveAsimetrica = 1;
}
try {
generateAsymmetricKeys(context, numeroDiasValidezClaveAsimetrica);
} catch (Exception e) {
e.printStackTrace();
}
}
};
miTareaAsincrona.execute(null, null, null);
} catch (Exception e){
e.printStackTrace();
}
}
RespuestaAlCliente 是一个简单的 class,它包装了端点的响应,因为不允许原语作为端点响应
public class RespuestaAlCliente {
public String message;
public RespuestaAlCliente() {}
public RespuestaAlCliente(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
我尝试恢复到以前的 Android Studio 版本、gradle 插件、库,甚至恢复一些项目的备份。错误仍然存在。
我遗漏了一些东西,有什么想法吗?提前致谢。
编辑:我忘了说我在 google-api-java-client 的 github 中发现了这个旧问题,具有相同的堆栈跟踪。这可能与我的问题有关。 https://github.com/googleapis/google-api-java-client/issues/1250
好吧,我真丢人,这是我的错:(
我想让一些人在发布之前看到我的网站,所以我在我的 web.xml 文件中上传了一些安全限制,并授予这些用户权限。这些限制阻止了 Android 应用程序到达后端端点...
我希望没有人在这上面浪费时间。对于给您带来的不便,我们深表歉意。
我有一个从我的 Android 应用调用的简单 Google 云端点。很长一段时间以来,它一直像一个魅力一样工作。最近,我更新了 Android Studio,Gradle 插件,以及项目中的 build.gradle 个文件。
从那时起,Android 应用每次尝试调用该端点时都会返回此错误:
Process: com.berylo.chat, PID: 26426
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.IllegalArgumentException:
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:889)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:382)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:355)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.berylo.chat.Encriptador.doInBackground(Encriptador.java:282)
at com.berylo.chat.Encriptador.doInBackground(Encriptador.java:277)
at android.os.AsyncTask.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.IllegalArgumentException: expected primitive class, but got: class com.crypto.berylo.com.clavePublica4Api.model.RespuestaAlCliente
at com.google.api.client.util.Data.parsePrimitiveValue(Data.java:453)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:859)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:382)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:355)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.berylo.chat.Encriptador.doInBackground(Encriptador.java:282)
at com.berylo.chat.Encriptador.doInBackground(Encriptador.java:277)
at android.os.AsyncTask.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
这是端点代码:
@ApiMethod(name = "obtenerDiasCaducidadClavesDeGrupo",
path = "grupo",
httpMethod = ApiMethod.HttpMethod.GET)
public RespuestaAlCliente obtenerDiasCaducidadClavesDeGrupo(User user)
throws OAuthRequestException, IOException {
String dias = "";
if (user == null)
{
throw new OAuthRequestException("Usuario no valido");
}
else {
dias = DIAS_HASTA_CADUCIDAD_DE_CLAVES_DE_GRUPO;
}
respuestaalcliente.setMessage(dias);
logger.info("respuestaalcliente: " + respuestaalcliente);
return respuestaalcliente;
}
这是 Android 应用代码。触发错误的行标有 THIS ------>
private void obtenernumeroDiasValidezClavesAsimetricas(final Context context){
try {
AsyncTask<Void, Void, String> miTareaAsincrona;
miTareaAsincrona = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
THIS ------> RespuestaAlCliente respuestaAlCliente = MisEndPointsClavePublica.serviceEndPoint.obtenerDiasCaducidadClaveAsimetrica().execute();
return respuestaAlCliente.getMessage();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
protected void onPostExecute(String result) {
if((result != null) && (!result.equals("") && (!result.equals("null")))) {
numeroDiasValidezClaveAsimetrica = parseInt(result);
} else {
numeroDiasValidezClaveAsimetrica = 1;
}
try {
generateAsymmetricKeys(context, numeroDiasValidezClaveAsimetrica);
} catch (Exception e) {
e.printStackTrace();
}
}
};
miTareaAsincrona.execute(null, null, null);
} catch (Exception e){
e.printStackTrace();
}
}
RespuestaAlCliente 是一个简单的 class,它包装了端点的响应,因为不允许原语作为端点响应
public class RespuestaAlCliente {
public String message;
public RespuestaAlCliente() {}
public RespuestaAlCliente(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
我尝试恢复到以前的 Android Studio 版本、gradle 插件、库,甚至恢复一些项目的备份。错误仍然存在。
我遗漏了一些东西,有什么想法吗?提前致谢。
编辑:我忘了说我在 google-api-java-client 的 github 中发现了这个旧问题,具有相同的堆栈跟踪。这可能与我的问题有关。 https://github.com/googleapis/google-api-java-client/issues/1250
好吧,我真丢人,这是我的错:(
我想让一些人在发布之前看到我的网站,所以我在我的 web.xml 文件中上传了一些安全限制,并授予这些用户权限。这些限制阻止了 Android 应用程序到达后端端点...
我希望没有人在这上面浪费时间。对于给您带来的不便,我们深表歉意。