use of okhttp3.Response in project MVCHelper by LuckyJayce.
the class HttpMethod method executeSync.
/**
* 执行同步请求
*
* @return 返回请求回来的 Response
* @throws Exception
*/
public final Response executeSync() throws Exception {
Request request = buildRequest();
call = client.newCall(request);
return call.execute();
}
use of okhttp3.Response in project MVCHelper by LuckyJayce.
the class BooksOkHttp_SyncDataSource method loadBooks.
private List<Book> loadBooks(final int page) throws Exception {
GetMethod method = new GetMethod("https://www.baidu.com");
method.addHeader("a", "aaaaa");
method.addParam("api_key", "75ee6c644cad38dc8e53d3598c8e6b6c");
List<Book> data = method.executeSync(new ResponseParser<List<Book>>() {
@Override
public List<Book> parse(Response response) throws Exception {
Thread.sleep(1000);
List<Book> books = new ArrayList<Book>();
for (int i = 0; i < 15; i++) {
books.add(new Book("page" + page + " Java编程思想 " + i, 108.00d));
}
mPage = page;
return books;
}
});
return data;
}
use of okhttp3.Response in project feign by OpenFeign.
the class BaseApiTest method resolvesBodyParameter.
@Test
public void resolvesBodyParameter() throws InterruptedException {
server.enqueue(new MockResponse().setBody("foo"));
String baseUrl = server.url("/default").toString();
Feign.builder().encoder(new Encoder() {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
assertThat(bodyType).isEqualTo(new TypeToken<Keys<String>>() {
}.getType());
}
}).decoder(new Decoder() {
@Override
public Object decode(Response response, Type type) {
assertThat(type).isEqualTo(new TypeToken<Entities<String, Long>>() {
}.getType());
return null;
}
}).target(MyApi.class, baseUrl).getAll(new Keys<String>());
}
use of okhttp3.Response in project feign by OpenFeign.
the class BaseApiTest method resolvesParameterizedResult.
@Test
public void resolvesParameterizedResult() throws InterruptedException {
server.enqueue(new MockResponse().setBody("foo"));
String baseUrl = server.url("/default").toString();
Feign.builder().decoder(new Decoder() {
@Override
public Object decode(Response response, Type type) {
assertThat(type).isEqualTo(new TypeToken<Entity<String, Long>>() {
}.getType());
return null;
}
}).target(MyApi.class, baseUrl).get("foo");
assertThat(server.takeRequest()).hasPath("/default/api/foo");
}
use of okhttp3.Response in project feign by OpenFeign.
the class AbstractClientTest method testContentTypeWithoutCharset.
@Test
public void testContentTypeWithoutCharset() throws Exception {
server.enqueue(new MockResponse().setBody("AAAAAAAA"));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.postWithContentType("foo", "text/plain");
// Response length should not be null
assertEquals("AAAAAAAA", Util.toString(response.body().asReader()));
}
Aggregations