2013-03-13 5 views
7

Google Cloud EndpointsクラスのGZipContentを無効にして、POSTをローカル開発サーバーで使用できるようにしたいとします。AndroidのCloud Endpoints BuilderでGZipContentを無効にする方法

最新GPEのリリースは、このエンドポイントビルダー生成:

public static final class Builder extends AbstractGoogleJsonClient.Builder { 
    public Builder(HttpTransport transport, JsonFactory jsonFactory, 
     HttpRequestInitializer httpRequestInitializer) { 
     super(
      transport, 
      jsonFactory, 
      ...); 
    } 

をし、Googleドキュメントは、このようにそれを使用することをお勧めします:

Myendpoint.Builder endpointBuilder = new Myendpoint.Builder(
        AndroidHttp.newCompatibleTransport(), 
        new GsonFactory(), 
        credential); 

は、エンドポイントのGZipContentを無効にする方法を誰もが知っていますか?

ありがとうございました。

を使用でき

答えて

11

builder.setGoogleClientRequestInitializer(new TictactoeRequestInitializer() { 
    protected void initializeTictactoeRequest(TictactoeRequest<?> request) { 
     request.setDisableGZipContent(true); 
    } 
    }); 

アプリケーションに適したクラスでTictactoeRequestを交換してください。

+0

ありがとうございましたDan!それはちょうど良い(私はxxxxxRequestInitializerのコントロールに気づいたが、それを使用する方法はわかりませんでした)。私は私の日仕事を終えて答えを受け入れると、後でそれをテストします。 – aez

1

ダンの答えが私にとってうまくいかなかったのは100%ではありませんが、このGitHub project's codeは私のために解決しました。私が見たエラーのためにグーグルでされているものについては

/* 
* TODO: Need to change this to 'true' if you're running your backend locally using 
* the DevAppServer. See 
* http://developers.google.com/eclipse/docs/cloud_endpoints for more 
* information. 
*/ 
protected static final boolean LOCAL_ANDROID_RUN = false; 

/* 
* The root URL of where your DevAppServer is running (if you're running the 
* DevAppServer locally). 
*/ 
protected static final String LOCAL_APP_ENGINE_SERVER_URL = "http://localhost:8080/"; 

/* 
* The root URL of where your DevAppServer is running when it's being 
* accessed via the Android emulator (if you're running the DevAppServer 
* locally). In this case, you're running behind Android's virtual router. 
* See 
* http://developer.android.com/tools/devices/emulator.html#networkaddresses 
* for more information. 
*/ 
protected static final String LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID = "http://10.0.2.2:8080"; 

/** 
* Updates the Google client builder to connect the appropriate server based 
* on whether LOCAL_ANDROID_RUN is true or false. 
* 
* @param builder Google client builder 
* @return same Google client builder 
*/ 
public static <B extends AbstractGoogleClient.Builder> B updateBuilder(
     B builder) { 
    if (LOCAL_ANDROID_RUN) { 
     builder.setRootUrl(LOCAL_APP_ENGINE_SERVER_URL_FOR_ANDROID 
       + "/_ah/api/"); 
    } 

    // only enable GZip when connecting to remote server 
    final boolean enableGZip = builder.getRootUrl().startsWith("https:"); 

    builder.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() { 
     public void initialize(AbstractGoogleClientRequest<?> request) 
       throws IOException { 
      if (!enableGZip) { 
       request.setDisableGZipContent(true); 
      } 
     } 
    }); 

    return builder; 
} 
0

、それだけの開発サーバーでは、java.io.EOFExceptionました。

Myendpoint myendpointClient = new Myendpoint.Builder(
       AndroidHttp.newCompatibleTransport(), 
       new GsonFactory(), 
       credential).build(); 
EndpointService svcCall = myendpointClient.endpointService("firstArg"); 
// Note, I didn't call "execute()", as normal! 
svcCall.setDisableGZipContent(true); 
// This is also a handy place to set http headers, etc 
svcCall.getRequestHeaders().set("x-oddballhdr","OddballValue"); 
// It's now time to call execute() 
svcCall.execute(); 

他の有用な答えよりも少し簡単かもしれ:ここでは、私はOPの質問に記載された例を使用して、この問題を解決することができた方法です。

関連する問題