Example usage for com.squareup.okhttp Response newBuilder

List of usage examples for com.squareup.okhttp Response newBuilder

Introduction

In this page you can find the example usage for com.squareup.okhttp Response newBuilder.

Prototype

public Builder newBuilder() 

Source Link

Usage

From source file:cloud.artik.api.UsersApi.java

License:Apache License

private com.squareup.okhttp.Call getUserDeviceTypesCall(String userId, Integer offset, Integer count,
        Boolean includeShared, final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // verify the required parameter 'userId' is set
    if (userId == null) {
        throw new ApiException(
                "Missing the required parameter 'userId' when calling getUserDeviceTypes(Async)");
    }//from  ww w . j  a  v a2 s  .  com

    // create path and map variables
    String localVarPath = "/users/{userId}/devicetypes".replaceAll("\\{format\\}", "json")
            .replaceAll("\\{" + "userId" + "\\}", apiClient.escapeString(userId.toString()));

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (offset != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "offset", offset));
    if (count != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "count", count));
    if (includeShared != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "includeShared", includeShared));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] { "artikcloud_oauth" };
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:cloud.artik.api.UsersApi.java

License:Apache License

private com.squareup.okhttp.Call getUserDevicesCall(String userId, Integer offset, Integer count,
        Boolean includeProperties, final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // verify the required parameter 'userId' is set
    if (userId == null) {
        throw new ApiException("Missing the required parameter 'userId' when calling getUserDevices(Async)");
    }//from w ww  . ja v  a 2s .  com

    // create path and map variables
    String localVarPath = "/users/{userId}/devices".replaceAll("\\{format\\}", "json")
            .replaceAll("\\{" + "userId" + "\\}", apiClient.escapeString(userId.toString()));

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (offset != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "offset", offset));
    if (count != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "count", count));
    if (includeProperties != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "includeProperties", includeProperties));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] { "artikcloud_oauth" };
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:cloud.artik.api.UsersApi.java

License:Apache License

private com.squareup.okhttp.Call getUserPropertiesCall(String userId, String aid,
        final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // verify the required parameter 'userId' is set
    if (userId == null) {
        throw new ApiException("Missing the required parameter 'userId' when calling getUserProperties(Async)");
    }// w w  w .j  a v  a2s  .  c om

    // create path and map variables
    String localVarPath = "/users/{userId}/properties".replaceAll("\\{format\\}", "json")
            .replaceAll("\\{" + "userId" + "\\}", apiClient.escapeString(userId.toString()));

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (aid != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "aid", aid));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] { "artikcloud_oauth" };
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:cloud.artik.api.UsersApi.java

License:Apache License

private com.squareup.okhttp.Call getUserRulesCall(String userId, Boolean excludeDisabled, Integer count,
        Integer offset, final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = null;

    // verify the required parameter 'userId' is set
    if (userId == null) {
        throw new ApiException("Missing the required parameter 'userId' when calling getUserRules(Async)");
    }// w  w  w  .  j ava 2  s .c o m

    // create path and map variables
    String localVarPath = "/users/{userId}/rules".replaceAll("\\{format\\}", "json")
            .replaceAll("\\{" + "userId" + "\\}", apiClient.escapeString(userId.toString()));

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (excludeDisabled != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "excludeDisabled", excludeDisabled));
    if (count != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "count", count));
    if (offset != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "offset", offset));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = {

    };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] { "artikcloud_oauth" };
    return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:cloud.artik.api.UsersApi.java

License:Apache License

private com.squareup.okhttp.Call updateUserPropertiesCall(String userId, AppProperties properties, String aid,
        final ProgressResponseBody.ProgressListener progressListener,
        final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
    Object localVarPostBody = properties;

    // verify the required parameter 'userId' is set
    if (userId == null) {
        throw new ApiException(
                "Missing the required parameter 'userId' when calling updateUserProperties(Async)");
    }//from  w  w w.  j ava  2 s  .co m

    // verify the required parameter 'properties' is set
    if (properties == null) {
        throw new ApiException(
                "Missing the required parameter 'properties' when calling updateUserProperties(Async)");
    }

    // create path and map variables
    String localVarPath = "/users/{userId}/properties".replaceAll("\\{format\\}", "json")
            .replaceAll("\\{" + "userId" + "\\}", apiClient.escapeString(userId.toString()));

    List<Pair> localVarQueryParams = new ArrayList<Pair>();
    if (aid != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "aid", aid));

    Map<String, String> localVarHeaderParams = new HashMap<String, String>();

    Map<String, Object> localVarFormParams = new HashMap<String, Object>();

    final String[] localVarAccepts = { "application/json" };
    final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    if (localVarAccept != null)
        localVarHeaderParams.put("Accept", localVarAccept);

    final String[] localVarContentTypes = { "application/json" };
    final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
    localVarHeaderParams.put("Content-Type", localVarContentType);

    if (progressListener != null) {
        apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
            @Override
            public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain)
                    throws IOException {
                com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                return originalResponse.newBuilder()
                        .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
            }
        });
    }

    String[] localVarAuthNames = new String[] { "artikcloud_oauth" };
    return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams,
            localVarFormParams, localVarAuthNames, progressRequestListener);
}

From source file:cn.com.crcement.oa.base.download.helper.ProgressHelper.java

License:Apache License

/**
 * OkHttpClient/*from w  w w. j  a  va  2s. c  o m*/
 * 
 * @param client
 *            OkHttpClient
 * @param progressListener
 *            ?
 * @return ?OkHttpClientclone
 */
public static OkHttpClient addProgressResponseListener(OkHttpClient client,
        final ProgressListener progressListener) {
    // 
    OkHttpClient clone = client.clone();
    // 
    clone.networkInterceptors().add(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            // 
            Response originalResponse = chain.proceed(chain.request());
            // ?
            return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
        }
    });
    return clone;
}

From source file:cn.edu.zafu.coreprogress.helper.ProgressHelper.java

License:Apache License

/**
 * OkHttpClient//from  w w  w  . j  a va2s . c  o  m
 * @param client OkHttpClient
 * @param progressListener ?
 * @return ?OkHttpClientclone
 */
public static OkHttpClient addProgressResponseListener(OkHttpClient client,
        final ProgressListener progressListener) {
    //
    OkHttpClient clone = client.clone();
    //
    clone.networkInterceptors().add(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            //
            Response originalResponse = chain.proceed(chain.request());
            //?
            return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener)).build();
        }
    });
    return clone;
}

From source file:co.paralleluniverse.fibers.okhttp.InterceptorTest.java

License:Open Source License

private void rewriteResponseFromServer(List<Interceptor> interceptors) throws Exception {
    server.enqueue(new MockResponse().addHeader("Original-Header: foo").setBody("abc"));

    interceptors.add(new Interceptor() {
        @Override//w  w w. ja  v a2s .  co  m
        public Response intercept(Chain chain) throws IOException {
            Response originalResponse = chain.proceed(chain.request());
            return originalResponse.newBuilder().body(uppercase(originalResponse.body()))
                    .addHeader("OkHttp-Intercepted", "yep").build();
        }
    });

    Request request = new Request.Builder().url(server.getUrl("/")).build();

    Response response = FiberOkHttpUtil.executeInFiber(client, request);
    assertEquals("ABC", response.body().string());
    assertEquals("yep", response.header("OkHttp-Intercepted"));
    assertEquals("foo", response.header("Original-Header"));
}

From source file:co.paralleluniverse.fibers.okhttp.InterceptorTest.java

License:Open Source License

private void multipleInterceptors(List<Interceptor> interceptors) throws Exception {
    server.enqueue(new MockResponse());

    interceptors.add(new Interceptor() {
        @Override//from  w ww .  j a  v  a 2s  .  com
        public Response intercept(Chain chain) throws IOException {
            Request originalRequest = chain.request();
            Response originalResponse = chain
                    .proceed(originalRequest.newBuilder().addHeader("Request-Interceptor", "Android") // 1. Added first.
                            .build());
            return originalResponse.newBuilder().addHeader("Response-Interceptor", "Donut") // 4. Added last.
                    .build();
        }
    });
    interceptors.add(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Request originalRequest = chain.request();
            Response originalResponse = chain
                    .proceed(originalRequest.newBuilder().addHeader("Request-Interceptor", "Bob") // 2. Added second.
                            .build());
            return originalResponse.newBuilder().addHeader("Response-Interceptor", "Cupcake") // 3. Added third.
                    .build();
        }
    });

    Request request = new Request.Builder().url(server.getUrl("/")).build();

    Response response = FiberOkHttpUtil.executeInFiber(client, request);
    assertEquals(Arrays.asList("Cupcake", "Donut"), response.headers("Response-Interceptor"));

    RecordedRequest recordedRequest = server.takeRequest();
    assertEquals(Arrays.asList("Android", "Bob"), recordedRequest.getHeaders().values("Request-Interceptor"));
}

From source file:co.paralleluniverse.fibers.okhttp.InterceptorTest.java

License:Open Source License

private void asyncInterceptors(List<Interceptor> interceptors) throws Exception {
    server.enqueue(new MockResponse());

    interceptors.add(new Interceptor() {
        @Override//from  ww  w. j a v  a2  s  . com
        public Response intercept(Chain chain) throws IOException {
            Response originalResponse = chain.proceed(chain.request());
            return originalResponse.newBuilder().addHeader("OkHttp-Intercepted", "yep").build();
        }
    });

    Request request = new Request.Builder().url(server.getUrl("/")).build();
    client.newCall(request).enqueue(callback);

    callback.await(request.url()).assertCode(200).assertHeader("OkHttp-Intercepted", "yep");
}