Google Cloud Endpoint continues to throw an “unexpected end of stream” exception

Does anyone know why Google Cloud Endpoint continues to throw an unexpected end of stream exception before the application core instance is actually reached? I keep getting the following error when I call my endpoint. In most places, an error is displayed after every other call; in rare others, he is consistent.

 05-06 18:32:28.335: W/System.err(11783): java.io.IOException: unexpected end of stream 05-06 18:32:28.343: W/System.err(11783): at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58) 05-06 18:32:28.343: W/System.err(11783): at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:82) 05-06 18:32:28.343: W/System.err(11783): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:980) 05-06 18:32:28.343: W/System.err(11783): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412) 05-06 18:32:28.343: W/System.err(11783): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345) 05-06 18:32:28.343: W/System.err(11783): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463) … 05-06 18:32:28.343: W/System.err(11783): at android.os.AsyncTask.finish(AsyncTask.java:631) 05-06 18:32:28.343: W/System.err(11783): at android.os.AsyncTask.access$600(AsyncTask.java:177) 05-06 18:32:28.343: W/System.err(11783): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) 05-06 18:32:28.343: W/System.err(11783): at android.os.Handler.dispatchMessage(Handler.java:99) 05-06 18:32:28.343: W/System.err(11783): at android.os.Looper.loop(Looper.java:137) 05-06 18:32:28.343: W/System.err(11783): at android.app.ActivityThread.main(ActivityThread.java:4849) 05-06 18:32:28.343: W/System.err(11783): at java.lang.reflect.Method.invokeNative(Native Method) 05-06 18:32:28.343: W/System.err(11783): at java.lang.reflect.Method.invoke(Method.java:511) 05-06 18:32:28.343: W/System.err(11783): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) 05-06 18:32:28.343: W/System.err(11783): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) 05-06 18:32:28.343: W/System.err(11783): at dalvik.system.NativeStart.main(Native Method) 

BTW: I get this error even for small operations, such as checking a token, which can be a string of 20 to 50 characters.

+6
source share
2 answers

I get the same problem too, every time I get an "unexpected end of stream" IOE exception. As you say, logs are not written to appengine. I have a class with several endpoints, but this only happens with one of them.

This is the structure of the Api method:

 @ApiMethod(name = "blablabla", httpMethod = HttpMethod.POST) public static ooooo createCDR(@Named("iiii") String iiii, @Named("uuuu") String uuuu, @Named("cccc") Long cccc, @Named("aaaa") int aaaa, User user) 
+1
source

I had the same problem. The problem is that communication with endpoints should NOT be done on ui / main thread. The easiest way is to create a simple ASyncTask, for example, for example:

 private class InsertTask extends AsyncTask<Void, Void, Void> { Exception exceptionThrown = null; TargetEndpoint targetEndpoint; Target target; public InsertMessageTask(Activity activity, TargetEndpoint targetEndpoint, Target target) { this.messageEndpoint= messageEndpoint; this.target= target; } @Override protected Void doInBackground(Void... params) { try { targetEndpoint.insertTarget(target).execute(); } catch (IOException e) { exceptionThrown = e; } return null; } protected void onPostExecute(Void arg) { TheActivity.this.runOnUiThread(new Runnable() { @Override public void run() { if (exceptionThrown == null) Toast.makeText(TheActivity.this, "Success!", Toast.LENGTH_LONG).show(); else Toast.makeText(TheActivity.this, "Error occured: '" + exceptionThrown.getMessage(), Toast.LENGTH_LONG).show(); } }); } } 

I agree that the error message may be more indicated, but it has a reason. You do not want to run expensive methods on the ui thread, as this can reduce its performance.

0
source

Source: https://habr.com/ru/post/944405/


All Articles