List of usage examples for com.squareup.okhttp Response request
Request request
To view the source code for com.squareup.okhttp Response request.
Click Source Link
From source file:co.paralleluniverse.fibers.okhttp.RecordedResponse.java
License:Open Source License
/** * Asserts that the current response was redirected and returns the prior * response./*from w ww .j a v a 2s . co m*/ */ public RecordedResponse priorResponse() { Response priorResponse = response.priorResponse(); assertNotNull(priorResponse); assertNull(priorResponse.body()); return new RecordedResponse(priorResponse.request(), priorResponse, null, null, null); }
From source file:co.paralleluniverse.fibers.okhttp.RecordedResponse.java
License:Open Source License
/** * Asserts that the current response used the network and returns the network * response.//from w w w . j a va2 s. co m */ public RecordedResponse networkResponse() { Response networkResponse = response.networkResponse(); assertNotNull(networkResponse); assertNull(networkResponse.body()); return new RecordedResponse(networkResponse.request(), networkResponse, null, null, null); }
From source file:co.paralleluniverse.fibers.okhttp.RecordedResponse.java
License:Open Source License
/** * Asserts that the current response used the cache and returns the cache * response.//from w w w.ja v a 2s . c o m */ public RecordedResponse cacheResponse() { Response cacheResponse = response.cacheResponse(); assertNotNull(cacheResponse); assertNull(cacheResponse.body()); return new RecordedResponse(cacheResponse.request(), cacheResponse, null, null, null); }
From source file:co.paralleluniverse.fibers.okhttp.RecordingCallback.java
License:Open Source License
@Override public synchronized void onResponse(Response response) throws IOException { Buffer buffer = new Buffer(); ResponseBody body = response.body(); body.source().readAll(buffer);//from w w w.ja v a 2s .c om responses.add(new RecordedResponse(response.request(), response, null, buffer.readUtf8(), null)); notifyAll(); }
From source file:co.paralleluniverse.fibers.okhttp.test.InterceptorTest.java
License:Apache License
@Test public void networkInterceptorModifiedRequestIsReturned() throws IOException { server.enqueue(new MockResponse()); Interceptor modifyHeaderInterceptor = new Interceptor() { @Override/*from w ww . j av a2s.c om*/ public Response intercept(Chain chain) throws IOException { return chain .proceed(chain.request().newBuilder().header("User-Agent", "intercepted request").build()); } }; client.networkInterceptors().add(modifyHeaderInterceptor); Request request = new Request.Builder().url(server.url("/")).header("User-Agent", "user request").build(); Response response = client.newCall(request).execute(); assertNotNull(response.request().header("User-Agent")); assertEquals("user request", response.request().header("User-Agent")); assertEquals("intercepted request", response.networkResponse().request().header("User-Agent")); }
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 . j av a 2 s . c om*/ }
From source file:com.anony.okhttp.sample.Authenticate.java
License:Apache License
public void run() throws Exception { client.setAuthenticator(new Authenticator() { @Override/*from w ww . j av a 2 s.c om*/ public Request authenticate(Proxy proxy, Response response) { System.out.println("Authenticating for response: " + response); System.out.println("Challenges: " + response.challenges()); String credential = Credentials.basic("jesse", "password1"); return response.request().newBuilder().header("Authorization", credential).build(); } @Override public Request authenticateProxy(Proxy proxy, Response response) { return null; // Null indicates no attempt to authenticate. } }); Request request = new Request.Builder().url("http://publicobject.com/secrets/hellosecret.txt").build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); System.out.println(response.body().string()); }
From source file:com.auth0.api.internal.SimpleRequest.java
License:Open Source License
@Override public void onResponse(Response response) throws IOException { Log.d(TAG, String.format("Received response from request to %s with status code %d", response.request().urlString(), response.code())); final InputStream byteStream = response.body().byteStream(); if (!response.isSuccessful()) { Throwable throwable;// ww w.ja v a 2 s .com try { Map<String, Object> payload = errorReader.readValue(byteStream); throwable = new APIClientException("Request failed with response " + payload, response.code(), payload); } catch (IOException e) { throwable = new APIClientException("Request failed", response.code(), null); } postOnFailure(throwable); return; } try { Log.d(TAG, "Received successful response from " + response.request().urlString()); T payload = getReader().readValue(byteStream); postOnSuccess(payload); } catch (IOException e) { postOnFailure(new APIClientException("Request failed", response.code(), null)); } }
From source file:com.auth0.api.internal.VoidRequest.java
License:Open Source License
@Override public void onResponse(Response response) throws IOException { Log.d(TAG, String.format("Received response from request to %s with status code %d", response.request().urlString(), response.code())); final InputStream byteStream = response.body().byteStream(); if (!response.isSuccessful()) { Throwable throwable;/*from w w w. j a va 2 s . co m*/ try { Map<String, Object> payload = errorReader.readValue(byteStream); throwable = new APIClientException("Request failed with response " + payload, response.code(), payload); } catch (IOException e) { throwable = new APIClientException("Request failed", response.code(), null); } postOnFailure(throwable); return; } postOnSuccess(null); }
From source file:com.carlospinan.demoretrofit2.helpers.LoggingInterceptor.java
License:Open Source License
@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); long t1 = System.nanoTime(); Log.d(LOG_TAG, String.format("--> Sending request %s on %s%n%s", request.url(), chain.connection(), request.headers()));// w ww . j a v a 2s. com Buffer requestBuffer = new Buffer(); if (request.body() != null) { request.body().writeTo(requestBuffer); Log.d(LOG_TAG, requestBuffer.readUtf8()); } Response response = chain.proceed(request); long t2 = System.nanoTime(); Log.d(LOG_TAG, String.format("<-- Received response for %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers())); MediaType contentType = response.body().contentType(); String content = response.body().string(); Log.d(LOG_TAG, content); ResponseBody wrappedBody = ResponseBody.create(contentType, content); return response.newBuilder().body(wrappedBody).build(); }