6

有人知道爲什麼Google雲端點甚至在我的應用程序引擎實例實際到達之前仍會拋出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個字符的字符串)等小操作,我也會得到此錯誤。

+0

請問您可以提供您的端點代碼嗎? – MikO 2013-05-07 09:14:34

+0

對此有一個開放的GAE問題: https://code.google.com/p/googleappengine/issues/detail?id=9291 – Tom 2013-10-16 18:10:42

+0

而且一個開放式的google java api客戶端問題: https://code.google .com/p/google-http-java-client/issues/detail?id = 230 – Tom 2013-10-16 18:11:12

回答

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) 
+0

它看起來與被調用的特定Api方法無關。我嘗試了其他班級工作良好的其他班級,但在這個特殊班級中他們失敗了。唯一的區別是所有可以正常工作的端點都是從活動中調用的,並且此類使方法調用失敗的類是由服務調用的處理程序。 – Miguel 2013-05-10 01:48:33

+1

我創建了一個appengine問題:https://code.google.com/p/googleappengine/issues/detail?id=9291&thanks=9291&ts=1368199444 – Miguel 2013-05-10 16:43:35

+0

您是否可以在應用引擎應用中添加額外的日誌記錄以捕獲錯誤並查看您是否可以得到任何線索。檢查這個谷歌文檔樣本得到一個想法:[登錄appengine](https://developers.google.com/appengine/articles/logging) – 2013-05-18 12:39:37

0

我有同樣的問題。問題是,與端點的通信不能在ui /主線程上運行。最簡單的方法是創建例如簡單的AsyncTask像thislike這樣:

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線程上運行時間昂貴的方法,因爲它可能會降低其性能。