Google Cloud Endpoint keeps throwing "unexpected end of stream" exception
Asked Answered
H

2

7

Does anyone know why Google Cloud Endpoint keeps throwing unexpected end of stream exception even before my app engine instance is actually reached? I keep getting the following error when I call my endpoint. In most places the error shows after every other call; in rare others it's 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 verifying a token, which could be a string of 20 to 50 chars.

Household answered 7/5, 2013 at 2:48 Comment(3)
Could you provide your endpoint code please?Clea
There is an open GAE issue for this: code.google.com/p/googleappengine/issues/detail?id=9291Luddite
And an open google java api client issue: code.google.com/p/google-http-java-client/issues/detail?id=230Luddite
A
1

I am getting the same issue too, every other time I get this "unexpected end of stream" IOE exception. As you say no logs are recorded in appengine. I have a class with several endpoints but this only happens to 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)
Auriga answered 10/5, 2013 at 0:5 Comment(10)
It looks it is not related with the particular Api method being called. I have tried others that were working fine in other classes but in this particular one they fail. The only difference is that all endpoint that work ok are called from activities and this class that makes the method calls fail is a handler called by a service.Auriga
I have created an appengine issue: code.google.com/p/googleappengine/issues/…Auriga
can you add extra logging in app engine application to capture errors and see if you can get any clue . Check this google document with sample to get an idea : logging in appengineSuki
Tony, as Pouton mentions in his question the appengine instance is not even reached. It seems to be an issue in the Android Endpoints implementation.Auriga
@Auriga Have you found a workaround for this? I get this error occasionally when endpoint backend calls are made from an android service.Pulcheria
@plsp No so far I haven't... an it is quite frustrating.Auriga
@KillerFrca I am calling endpoints inside of a Thread that runs asynchronously (I prefer this option better than using AsyncTask). This can't be the reason.Auriga
I set the connection close property and so far I have not hit this error. But then again, I don't have a wide range of devices to test with. Let me know if this works for you. public Send send(com.google.api.services.devices.model.ServiceMessagesContentMessage content) throws java.io.IOException { Send result = new Send(content); result.getRequestHeaders().set("connection", "close"); initialize(result); return result; }Pulcheria
Thanks plspl. I check your approach in Android 4.2. It works fine.Parley
Sorry, still the error sometimes occurs. I try to other approach. #17963319Parley
G
1

I had same issue. Problem is, that communication with endpoints must NOT be running on ui/main thread. Easiest way is to create simple ASyncTask for example like thislike this:

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 error message could be more specified, but it has its reason. You dont want to run time expensive methods on ui thread, as it may reduce its performance.

Granulose answered 12/6, 2013 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.