1414import io .ably .lib .platform .Platform ;
1515import io .ably .lib .push .Push ;
1616import io .ably .lib .realtime .Connection ;
17+ import io .ably .lib .transport .Defaults ;
1718import io .ably .lib .types .AblyException ;
1819import io .ably .lib .types .AsyncHttpPaginatedResponse ;
1920import io .ably .lib .types .AsyncPaginatedResult ;
@@ -249,7 +250,14 @@ public PaginatedResult<Stats> stats(Param[] params) throws AblyException {
249250 }
250251
251252 PaginatedResult <Stats > stats (Http http , Param [] params ) throws AblyException {
252- return new PaginatedQuery <>(http , "/stats" , HttpUtils .defaultAcceptHeaders (false ), params , StatsReader .statsResponseHandler ).get ();
253+ return new PaginatedQuery <>(
254+ http ,
255+ "/stats" ,
256+ // Stats api uses protocol v2 format for now
257+ Param .set (HttpUtils .defaultAcceptHeaders (false ), new Param (Defaults .ABLY_PROTOCOL_VERSION_HEADER , 2 )),
258+ params ,
259+ StatsReader .statsResponseHandler
260+ ).get ();
253261 }
254262
255263 /**
@@ -276,8 +284,15 @@ public void statsAsync(Param[] params, Callback<AsyncPaginatedResult<Stats>> cal
276284 statsAsync (http , params , callback );
277285 }
278286
279- void statsAsync (Http http , Param [] params , Callback <AsyncPaginatedResult <Stats >> callback ) {
280- (new AsyncPaginatedQuery <Stats >(http , "/stats" , HttpUtils .defaultAcceptHeaders (false ), params , StatsReader .statsResponseHandler )).get (callback );
287+ void statsAsync (Http http , Param [] params , Callback <AsyncPaginatedResult <Stats >> callback ) {
288+ (new AsyncPaginatedQuery <Stats >(
289+ http ,
290+ "/stats" ,
291+ // Stats api uses protocol v2 format for now
292+ Param .set (HttpUtils .defaultAcceptHeaders (false ), new Param (Defaults .ABLY_PROTOCOL_VERSION_HEADER , 2 )),
293+ params ,
294+ StatsReader .statsResponseHandler
295+ )).get (callback );
281296 }
282297
283298 /**
@@ -433,7 +448,12 @@ private Http.Request<PublishResponse[]> publishBatchImpl(final Message.Batch[] p
433448 public void execute (HttpScheduler http , final Callback <PublishResponse []> callback ) throws AblyException {
434449 HttpCore .RequestBody requestBody = options .useBinaryProtocol ? MessageSerializer .asMsgpackRequest (pubSpecs ) : MessageSerializer .asJSONRequest (pubSpecs );
435450 final Param [] params = options .addRequestIds ? Param .set (initialParams , Crypto .generateRandomRequestId ()) : initialParams ; // RSC7c
436- http .post ("/messages" , HttpUtils .defaultAcceptHeaders (options .useBinaryProtocol ), params , requestBody , new HttpCore .ResponseHandler <PublishResponse []>() {
451+ // This method uses an old batch format from protocol v2
452+ Param [] headers = Param .set (
453+ HttpUtils .defaultAcceptHeaders (options .useBinaryProtocol ),
454+ new Param (Defaults .ABLY_PROTOCOL_VERSION_HEADER , 2 )
455+ );
456+ http .post ("/messages" , headers , params , requestBody , new HttpCore .ResponseHandler <PublishResponse []>() {
437457 @ Override
438458 public PublishResponse [] handleResponse (HttpCore .Response response , ErrorInfo error ) throws AblyException {
439459 if (error != null && error .code != 40020 ) {
@@ -446,11 +466,6 @@ public PublishResponse[] handleResponse(HttpCore.Response response, ErrorInfo er
446466 });
447467 }
448468
449- /**
450- * Authentication token has changed. waitForResult is true if there is a need to
451- * wait for server response to auth request
452- */
453-
454469 /**
455470 * Override this method in AblyRealtime and pass updated token to ConnectionManager
456471 * @param token new token
0 commit comments