List of usage examples for com.squareup.okhttp Response body
ResponseBody body
To view the source code for com.squareup.okhttp Response body.
Click Source Link
From source file:co.paralleluniverse.fibers.okhttp.test.InterceptorTest.java
License:Apache License
/** Make sure interceptors can interact with the OkHttp client. */ @Test//from ww w .ja v a 2 s .co m public void interceptorMakesAnUnrelatedRequest() throws Exception { server.enqueue(new MockResponse().setBody("a")); // Fetched by interceptor. server.enqueue(new MockResponse().setBody("b")); // Fetched directly. client.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { if (chain.request().url().getPath().equals("/b")) { Request requestA = new Request.Builder().url(server.url("/a")).build(); Response responseA = client.newCall(requestA).execute(); assertEquals("a", responseA.body().string()); } return chain.proceed(chain.request()); } }); Request requestB = new Request.Builder().url(server.url("/b")).build(); Response responseB = client.newCall(requestB).execute(); assertEquals("b", responseB.body().string()); }
From source file:co.paralleluniverse.fibers.okhttp.test.utils.original.RecordingCallback.java
License:Apache License
@Override public synchronized void onResponse(Response response) throws IOException { String body = response.body().string(); responses.add(new RecordedResponse(response.request(), response, null, body, null)); notifyAll();/*from ww w . ja v a 2s .c om*/ }
From source file:co.paralleluniverse.fibers.okhttp.test.utils.original.SocksProxyTest.java
License:Apache License
@Test public void proxy() throws Exception { server.enqueue(new MockResponse().setBody("abc")); server.enqueue(new MockResponse().setBody("def")); OkHttpClient client = new OkHttpClient().setProxy(socksProxy.proxy()); Request request1 = new Request.Builder().url(server.url("/")).build(); Response response1 = client.newCall(request1).execute(); assertEquals("abc", response1.body().string()); Request request2 = new Request.Builder().url(server.url("/")).build(); Response response2 = client.newCall(request2).execute(); assertEquals("def", response2.body().string()); // The HTTP calls should share a single connection. assertEquals(1, socksProxy.connectionCount()); }
From source file:co.paralleluniverse.fibers.okhttp.test.utils.original.SocksProxyTest.java
License:Apache License
@Test public void proxySelector() throws Exception { server.enqueue(new MockResponse().setBody("abc")); ProxySelector proxySelector = new ProxySelector() { @Override//from w ww . j a v a 2s . c o m public List<Proxy> select(URI uri) { return Collections.singletonList(socksProxy.proxy()); } @Override public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) { throw new AssertionError(); } }; OkHttpClient client = new OkHttpClient().setProxySelector(proxySelector); Request request = new Request.Builder().url(server.url("/")).build(); Response response = client.newCall(request).execute(); assertEquals("abc", response.body().string()); assertEquals(1, socksProxy.connectionCount()); }
From source file:co.uk.crowdemotion.FaceVideoApi.java
License:Apache License
private com.squareup.okhttp.Call facevideoFacevideoIdDeleteCall(Integer facevideoId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'facevideoId' is set if (facevideoId == null) { throw new ApiException( "Missing the required parameter 'facevideoId' when calling facevideoFacevideoIdDelete(Async)"); }// w w w. ja va 2 s. c o m // create path and map variables String localVarPath = "/facevideo/{facevideo_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "facevideo_id" + "\\}", apiClient.escapeString(facevideoId.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); 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[] { "api_key" }; return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:co.uk.crowdemotion.FaceVideoApi.java
License:Apache License
private com.squareup.okhttp.Call facevideoGetCall(Integer facevideoId, Integer responseId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/facevideo".replaceAll("\\{format\\}", "json"); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (facevideoId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "facevideo_id", facevideoId)); if (responseId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "response_id", responseId)); 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// ww w . ja v a 2s .c o m 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[] { "api_key" }; return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:co.uk.crowdemotion.FaceVideoApi.java
License:Apache License
private com.squareup.okhttp.Call facevideoPostCall(File filename, Boolean sandbox, Integer responseId, Integer researchId, Integer mediaId, Integer respondentId, Boolean processVideo, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/facevideo".replaceAll("\\{format\\}", "json"); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (sandbox != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "sandbox", sandbox)); if (responseId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "response_id", responseId)); if (researchId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "research_id", researchId)); if (mediaId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "media_id", mediaId)); if (respondentId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "respondent_id", respondentId)); if (processVideo != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "processVideo", processVideo)); Map<String, String> localVarHeaderParams = new HashMap<String, String>(); Map<String, Object> localVarFormParams = new HashMap<String, Object>(); if (filename != null) localVarFormParams.put("filename", filename); final String[] localVarAccepts = { "application/json" }; final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String[] localVarContentTypes = { "multipart/form-data" }; final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); localVarHeaderParams.put("Content-Type", localVarContentType); if (progressListener != null) { apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { @Override// w ww . j av a 2 s .c o m 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[] { "api_key" }; return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:co.uk.crowdemotion.FaceVideoApi.java
License:Apache License
private com.squareup.okhttp.Call facevideoPutCall(Boolean sandbox, Integer responseId, Integer researchId, Integer mediaId, Integer respondentId, Boolean processVideo, FaceVideoUpload body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = body; // create path and map variables String localVarPath = "/facevideo".replaceAll("\\{format\\}", "json"); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (sandbox != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "sandbox", sandbox)); if (responseId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "response_id", responseId)); if (researchId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "research_id", researchId)); if (mediaId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "media_id", mediaId)); if (respondentId != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "respondent_id", respondentId)); if (processVideo != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "processVideo", processVideo)); 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/*w w w . j a v a 2s . c o m*/ 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[] { "api_key" }; return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:co.uk.crowdemotion.MediaApi.java
License:Apache License
private com.squareup.okhttp.Call mediaGetCall(Integer skip, Integer limit, String where, String sort, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/media".replaceAll("\\{format\\}", "json"); List<Pair> localVarQueryParams = new ArrayList<Pair>(); if (skip != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "skip", skip)); if (limit != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "limit", limit)); if (where != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "where", where)); if (sort != null) localVarQueryParams.addAll(apiClient.parameterToPairs("", "sort", sort)); 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/*from w w w .j a v a2s . co m*/ 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[] { "api_key" }; return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }
From source file:co.uk.crowdemotion.MediaApi.java
License:Apache License
private com.squareup.okhttp.Call mediaMediaIdDeleteCall(Integer mediaId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // verify the required parameter 'mediaId' is set if (mediaId == null) { throw new ApiException( "Missing the required parameter 'mediaId' when calling mediaMediaIdDelete(Async)"); }/*from ww w .j av a 2 s . c om*/ // create path and map variables String localVarPath = "/media/{media_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "media_id" + "\\}", apiClient.escapeString(mediaId.toString())); List<Pair> localVarQueryParams = new ArrayList<Pair>(); 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[] { "api_key" }; return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); }