Google Cloud Endpoint不断抛出“意外的流结束”异常

时间:2022-09-17 20:20:46

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.

有没有人知道为什么Google Cloud Endpoint甚至在我的应用引擎实例实际到达之前就会不断引发意外的流末端异常?当我调用我的端点时,我不断收到以下错误。在大多数地方,错误显示在每次其他呼叫之后;在其他罕见的情况下,它是一致的。

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.

BTW:即使对于小型操作,例如验证令牌,我也会收到此错误,令牌可能是20到50个字符串。

2 个解决方案

#1


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.

我也遇到了同样的问题,每次我都得到这个“意外的流结束”IOE异常。正如你所说,在appengine中没有记录日志。我有一个有几个端点的类,但这只发生在其中一个端点上。

This is the structure of the Api Method:

这是Api方法的结构:

@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)

#2


0  

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:

我有同样的问题。问题是,与端点的通信不得在ui /主线程上运行。最简单的方法是创建简单的ASyncTask,例如像这样:

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.

我同意可以更明确地指出错误消息,但它有其原因。你不想在ui线程上运行时间昂贵的方法,因为它可能会降低其性能。

#1


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.

我也遇到了同样的问题,每次我都得到这个“意外的流结束”IOE异常。正如你所说,在appengine中没有记录日志。我有一个有几个端点的类,但这只发生在其中一个端点上。

This is the structure of the Api Method:

这是Api方法的结构:

@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)

#2


0  

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:

我有同样的问题。问题是,与端点的通信不得在ui /主线程上运行。最简单的方法是创建简单的ASyncTask,例如像这样:

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.

我同意可以更明确地指出错误消息,但它有其原因。你不想在ui线程上运行时间昂贵的方法,因为它可能会降低其性能。