java.i.o.Exception End of stream error while on citrix secure hub as MDX

87 Views Asked by At

I saw this question asked so many times but mine is with different case. Please dont mark it as duplicate.

Following is my client for retrofit. Which works perfectly fine when we're using apk. But as soon as we convert it to MDX for citrix/secure hub we are facing this end of stream error.

I have also tried this with volley but am getting same error. As you can see that I have tried all the interceptor and all for retrofit.

Already tried following interceptor.

  1. addHeader("Connection", "close")
  2. retryOnConnectionFailure(true)

So my question is what is happening exactly? Why is it working in apk and not on MDX.

  public static Retrofit getClient() {
  //Basic Auth
  String authToken = null;
  if (!TextUtils.isEmpty(AppConfig.username) &&
      !TextUtils.isEmpty(AppConfig.password)) {
      authToken = Credentials.basic((String) AppConfig.username, (String) AppConfig.password);
  }

  //Create a new Interceptor.
  final String finalAuthToken = authToken;
  Interceptor headerAuthorizationInterceptor = new Interceptor() {
      @Override
      public okhttp3.Response intercept(Chain chain) throws IOException {
          okhttp3.Request request = chain.request();
          Headers headers = request.headers().newBuilder()
              //                        .add("Authorization", finalAuthToken)
              .add("Connection", "close").build();
          request = request.newBuilder().headers(headers).build();
          return chain.proceed(request);
      }
  };

  //TO be added in milliseconds
  List < Protocol > protos = new ArrayList < > ();
  protos.add(Protocol.HTTP_2);
  protos.add(Protocol.HTTP_1_1);

  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
  interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  OkHttpClient client = new OkHttpClient.Builder()
      .addInterceptor(interceptor)
      .protocols(protos)
      .retryOnConnectionFailure(true) //FIRST TRY : Added this line after getting Unexpected                   end of stream error.
      .connectTimeout(180, TimeUnit.SECONDS)
      .readTimeout(180, TimeUnit.SECONDS)
      .writeTimeout(180, TimeUnit.SECONDS)
      //.addInterceptor(new GzipRequestInterceptor())

      // THIRD TRY : Added this new interceptor for end of stream error
      /*.addInterceptor(new Interceptor() {
          @NonNull
          @Override
          public Response intercept(@NonNull Chain chain) throws IOException {
              Request request = chain.request().newBuilder()
                      .addHeader("Connection", "close")
                      .addHeader("Transfer-Encoding", "chunked")
                      //.addHeader("Accept-Encoding", "gzip")
                      .build();
              return chain.proceed(request);
          }
      })*/
      //.addInterceptor(headerAuthorizationInterceptor) // SECOND TRY : Added this line after              getting Unexpected end of stream error. fot connection close
      //ABOVE LINE is Next try would be adding this line as
      // this headerInterceptor we have added .add("Connection","close")
      // may be we need to remove the authorization from that headerInterceptor
      .build();


  return new Retrofit.Builder()
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .addConverterFactory(GsonConverterFactory.create())
      .client(client)
      .baseUrl(AppConfig.mainURLDev3forRetrofit2)
      .build();  }
0

There are 0 best solutions below