@Test public void MarkerInterceptor() throws IOException { OkHttpStack okHttpStack = new OkHttpStack(new MarkerInterceptorFactory() { @Override public AbstractMarkerInterceptor create(Request request) { return new AbstractMarkerInterceptor(request) { @Override Object[] getMarkerArgs(Request<?> request, okhttp3.Request okhttpRequest) { return new Object[]{"test marker arg"}; } }; } }); server.enqueue(new MockResponse().setBody("Hi")); Request request = mock(Request.class); when(request.getMethod()).thenReturn("GET"); when(request.getTag()).thenReturn("mytag"); when(request.getBody()).thenReturn(null); when(request.getUrlString()).thenReturn(server.url("/").toString()); okHttpStack.performRequest(request, null, new ByteArrayPool(100)); verify(request).addMarker(AbstractMarkerInterceptor.OKHTTP3_INTERCEPT,"test marker arg"); }
@Override public NetworkResponse performRequest(Request<?> request, Headers additionalHeaders, ByteArrayPool byteArrayPool) throws IOException { OkHttpClient.Builder clientBuilder = this.client.newBuilder(); if (request.getRetryPolicy() != null) { clientBuilder .connectTimeout(request.getRetryPolicy().getCurrentConnectTimeout(), TimeUnit.MILLISECONDS) .readTimeout(request.getRetryPolicy().getCurrentReadTimeout(), TimeUnit.MILLISECONDS); } if (markerInterceptorFactory != null) { clientBuilder.addNetworkInterceptor(markerInterceptorFactory.create(request)); } OkHttpClient client = clientBuilder.build(); okhttp3.Request okRequest = new okhttp3.Request.Builder() .url(request.getUrlString()) .headers(JusOk.okHeaders(request.getHeaders(), additionalHeaders)) .tag(request.getTag()) .method(request.getMethod(), JusOk.okBody(request.getNetworkRequest())) .build(); long requestStart = System.nanoTime(); Response response = client.newCall(okRequest).execute(); byte[] data = null; if (NetworkDispatcher.hasResponseBody(request.getMethod(), response.code())) { data = getContentBytes(response.body().source(), byteArrayPool, (int) response.body().contentLength()); } else { data = new byte[0]; } return new NetworkResponse.Builder() .setHeaders(JusOk.jusHeaders(response.headers())) .setStatusCode(response.code()) .setBody(data) .setNetworkTimeNs(System.nanoTime() - requestStart) .build(); }
OkHttpStack extends AbstractHttpStack { @Override public NetworkResponse performRequest(Request<?> request, Headers additionalHeaders, ByteArrayPool byteArrayPool) throws IOException { OkHttpClient.Builder clientBuilder = this.client.newBuilder(); if (request.getRetryPolicy() != null) { clientBuilder .connectTimeout(request.getRetryPolicy().getCurrentConnectTimeout(), TimeUnit.MILLISECONDS) .readTimeout(request.getRetryPolicy().getCurrentReadTimeout(), TimeUnit.MILLISECONDS); } if (markerInterceptorFactory != null) { clientBuilder.addNetworkInterceptor(markerInterceptorFactory.create(request)); } OkHttpClient client = clientBuilder.build(); okhttp3.Request okRequest = new okhttp3.Request.Builder() .url(request.getUrlString()) .headers(JusOk.okHeaders(request.getHeaders(), additionalHeaders)) .tag(request.getTag()) .method(request.getMethod(), JusOk.okBody(request.getNetworkRequest())) .build(); long requestStart = System.nanoTime(); Response response = client.newCall(okRequest).execute(); byte[] data = null; if (NetworkDispatcher.hasResponseBody(request.getMethod(), response.code())) { data = getContentBytes(response.body().source(), byteArrayPool, (int) response.body().contentLength()); } else { data = new byte[0]; } return new NetworkResponse.Builder() .setHeaders(JusOk.jusHeaders(response.headers())) .setStatusCode(response.code()) .setBody(data) .setNetworkTimeNs(System.nanoTime() - requestStart) .build(); } }
OkHttpStack extends AbstractHttpStack { @Override public NetworkResponse performRequest(Request<?> request, Headers additionalHeaders, ByteArrayPool byteArrayPool) throws IOException { OkHttpClient.Builder clientBuilder = this.client.newBuilder(); if (request.getRetryPolicy() != null) { clientBuilder .connectTimeout(request.getRetryPolicy().getCurrentConnectTimeout(), TimeUnit.MILLISECONDS) .readTimeout(request.getRetryPolicy().getCurrentReadTimeout(), TimeUnit.MILLISECONDS); } if (markerInterceptorFactory != null) { clientBuilder.addNetworkInterceptor(markerInterceptorFactory.create(request)); } OkHttpClient client = clientBuilder.build(); okhttp3.Request okRequest = new okhttp3.Request.Builder() .url(request.getUrlString()) .headers(JusOk.okHeaders(request.getHeaders(), additionalHeaders)) .tag(request.getTag()) .method(request.getMethod(), JusOk.okBody(request.getNetworkRequest())) .build(); long requestStart = System.nanoTime(); Response response = client.newCall(okRequest).execute(); byte[] data = null; if (NetworkDispatcher.hasResponseBody(request.getMethod(), response.code())) { data = getContentBytes(response.body().source(), byteArrayPool, (int) response.body().contentLength()); } else { data = new byte[0]; } return new NetworkResponse.Builder() .setHeaders(JusOk.jusHeaders(response.headers())) .setStatusCode(response.code()) .setBody(data) .setNetworkTimeNs(System.nanoTime() - requestStart) .build(); } OkHttpStack();  OkHttpStack(MarkerInterceptorFactory markerInterceptorFactory);  OkHttpStack(OkHttpClient client, MarkerInterceptorFactory markerInterceptorFactory); }
OkHttpStack extends AbstractHttpStack { @Override public NetworkResponse performRequest(Request<?> request, Headers additionalHeaders, ByteArrayPool byteArrayPool) throws IOException { OkHttpClient.Builder clientBuilder = this.client.newBuilder(); if (request.getRetryPolicy() != null) { clientBuilder .connectTimeout(request.getRetryPolicy().getCurrentConnectTimeout(), TimeUnit.MILLISECONDS) .readTimeout(request.getRetryPolicy().getCurrentReadTimeout(), TimeUnit.MILLISECONDS); } if (markerInterceptorFactory != null) { clientBuilder.addNetworkInterceptor(markerInterceptorFactory.create(request)); } OkHttpClient client = clientBuilder.build(); okhttp3.Request okRequest = new okhttp3.Request.Builder() .url(request.getUrlString()) .headers(JusOk.okHeaders(request.getHeaders(), additionalHeaders)) .tag(request.getTag()) .method(request.getMethod(), JusOk.okBody(request.getNetworkRequest())) .build(); long requestStart = System.nanoTime(); Response response = client.newCall(okRequest).execute(); byte[] data = null; if (NetworkDispatcher.hasResponseBody(request.getMethod(), response.code())) { data = getContentBytes(response.body().source(), byteArrayPool, (int) response.body().contentLength()); } else { data = new byte[0]; } return new NetworkResponse.Builder() .setHeaders(JusOk.jusHeaders(response.headers())) .setStatusCode(response.code()) .setBody(data) .setNetworkTimeNs(System.nanoTime() - requestStart) .build(); } OkHttpStack();  OkHttpStack(MarkerInterceptorFactory markerInterceptorFactory);  OkHttpStack(OkHttpClient client, MarkerInterceptorFactory markerInterceptorFactory); @Override NetworkResponse performRequest(Request<?> request, Headers
            additionalHeaders, ByteArrayPool byteArrayPool); }
OkHttpStack extends AbstractHttpStack { @Override public NetworkResponse performRequest(Request<?> request, Headers additionalHeaders, ByteArrayPool byteArrayPool) throws IOException { OkHttpClient.Builder clientBuilder = this.client.newBuilder(); if (request.getRetryPolicy() != null) { clientBuilder .connectTimeout(request.getRetryPolicy().getCurrentConnectTimeout(), TimeUnit.MILLISECONDS) .readTimeout(request.getRetryPolicy().getCurrentReadTimeout(), TimeUnit.MILLISECONDS); } if (markerInterceptorFactory != null) { clientBuilder.addNetworkInterceptor(markerInterceptorFactory.create(request)); } OkHttpClient client = clientBuilder.build(); okhttp3.Request okRequest = new okhttp3.Request.Builder() .url(request.getUrlString()) .headers(JusOk.okHeaders(request.getHeaders(), additionalHeaders)) .tag(request.getTag()) .method(request.getMethod(), JusOk.okBody(request.getNetworkRequest())) .build(); long requestStart = System.nanoTime(); Response response = client.newCall(okRequest).execute(); byte[] data = null; if (NetworkDispatcher.hasResponseBody(request.getMethod(), response.code())) { data = getContentBytes(response.body().source(), byteArrayPool, (int) response.body().contentLength()); } else { data = new byte[0]; } return new NetworkResponse.Builder() .setHeaders(JusOk.jusHeaders(response.headers())) .setStatusCode(response.code()) .setBody(data) .setNetworkTimeNs(System.nanoTime() - requestStart) .build(); } OkHttpStack();  OkHttpStack(MarkerInterceptorFactory markerInterceptorFactory);  OkHttpStack(OkHttpClient client, MarkerInterceptorFactory markerInterceptorFactory); @Override NetworkResponse performRequest(Request<?> request, Headers
            additionalHeaders, ByteArrayPool byteArrayPool);  }