7

有谁知道为什么 Google Cloud Endpoint 会unexpected end of stream在我的应用引擎实例实际到达之前一直抛出异常?当我调用我的端点时,我不断收到以下错误。在大多数地方,每隔一个电话就会显示错误;在极少数情况下,它是一致的。

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)

顺便说一句:即使对于验证令牌(可能是 20 到 50 个字符的字符串)之类的小操作,我也会收到此错误。

4

2 回答 2

1

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

这是 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)
于 2013-05-10T00:05:25.137 回答
1

我有同样的问题。问题是,与端点的通信不能在 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();

            }
        });
    }
}

我同意可以更具体地指定错误消息,但它有其原因。您不想在 ui 线程上运行耗时的方法,因为它可能会降低其性能。

于 2013-06-12T15:40:07.823 回答