本文整理了Java中retrofit2.Call.execute()
方法的一些代码示例,展示了Call.execute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Call.execute()
方法的具体详情如下:
包路径:retrofit2.Call
类名称:Call
方法名:execute
[英]Synchronously send the request and return its response.
[中]同步发送请求并返回其响应。
代码示例来源:origin: square/retrofit
@Override public Response<T> execute() throws IOException {
return delegate.execute();
}
代码示例来源:origin: square/retrofit
private static void printContributors(GitHub gitHub, String owner, String repo)
throws IOException {
System.out.println(String.format("== Contributors for %s/%s ==", owner, repo));
Call<List<Contributor>> contributors = gitHub.contributors(owner, repo);
for (Contributor contributor : contributors.execute().body()) {
System.out.println(contributor.login + " (" + contributor.contributions + ")");
}
System.out.println();
}
}
代码示例来源:origin: square/retrofit
@Override public Response<T> execute() throws IOException {
return getDelegate().execute();
}
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException {
// Create a very simple REST adapter which points the GitHub API.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
// Create an instance of our GitHub API interface.
GitHub github = retrofit.create(GitHub.class);
// Create a call instance for looking up Retrofit contributors.
Call<List<Contributor>> call = github.contributors("square", "retrofit");
// Fetch and print a list of the contributors to the library.
List<Contributor> contributors = call.execute().body();
for (Contributor contributor : contributors) {
System.out.println(contributor.login + " (" + contributor.contributions + ")");
}
}
}
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException {
InvocationLogger invocationLogger = new InvocationLogger();
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(invocationLogger)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://square.com/")
.callFactory(okHttpClient)
.build();
Browse browse = retrofit.create(Browse.class);
browse.robots().execute();
browse.favicon().execute();
browse.home().execute();
browse.page("sitemap.xml").execute();
browse.page("notfound").execute();
}
}
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException {
HostSelectionInterceptor hostSelectionInterceptor = new HostSelectionInterceptor();
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(hostSelectionInterceptor)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://www.github.com/")
.callFactory(okHttpClient)
.build();
Pop pop = retrofit.create(Pop.class);
Response<ResponseBody> response1 = pop.robots().execute();
System.out.println("Response from: " + response1.raw().request().url());
System.out.println(response1.body().string());
hostSelectionInterceptor.setHost("www.pepsi.com");
Response<ResponseBody> response2 = pop.robots().execute();
System.out.println("Response from: " + response2.raw().request().url());
System.out.println(response2.body().string());
}
}
代码示例来源:origin: Graylog2/graylog2-server
@POST
@Timed
@ApiOperation(value = "Finds master node and triggers deflector cycle")
@Path("/{indexSetId}/cycle")
@NoAuditEvent("this is a proxy resource, the event will be triggered on the individual nodes")
public void cycle(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) throws IOException {
getDeflectorResource().cycleIndexSet(indexSetId).execute();
}
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException {
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse().setBody("{\"name\": \"Jason\"}"));
server.enqueue(new MockResponse().setBody("<user name=\"Eximel\"/>"));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new QualifiedTypeConverterFactory(
GsonConverterFactory.create(),
SimpleXmlConverterFactory.create()))
.build();
Service service = retrofit.create(Service.class);
User user1 = service.exampleJson().execute().body();
System.out.println("User 1: " + user1.name);
User user2 = service.exampleXml().execute().body();
System.out.println("User 2: " + user2.name);
server.shutdown();
}
}
代码示例来源:origin: nickbutcher/plaid
private void handleActionUpvote(long storyId) {
if (storyId == 0L) return;
if (!repository.isLoggedIn()) {
// TODO prompt for login
return;
}
final Call<Story> upvoteStoryCall = service.upvoteStory(storyId);
try {
final Response<Story> response = upvoteStoryCall.execute();
// TODO report success
} catch (Exception e) {
// TODO report failure
}
}
}
代码示例来源:origin: Graylog2/graylog2-server
@POST
@Timed
@ApiOperation(value = "Finds master node and triggers deflector cycle")
@Path("/cycle")
@NoAuditEvent("this is a proxy resource, the event will be triggered on the individual nodes")
public void cycle() throws IOException {
getDeflectorResource().cycle().execute();
}
代码示例来源:origin: Graylog2/graylog2-server
@GET
@Timed
@Path("/names")
@ApiOperation(value = "Get all metrics keys/names from node")
@RequiresPermissions(RestPermissions.METRICS_ALLKEYS)
public MetricNamesResponse metricNames(@ApiParam(name = "nodeId", value = "The id of the node whose metrics we want.", required = true)
@PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
final Response<MetricNamesResponse> result = getResourceForNode(nodeId).metricNames().execute();
if (result.isSuccessful()) {
return result.body();
} else {
throw new WebApplicationException(result.message(), BAD_GATEWAY);
}
}
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException, InterruptedException {
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse());
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new JsonStringConverterFactory(GsonConverterFactory.create()))
.build();
Service service = retrofit.create(Service.class);
Call<ResponseBody> call = service.example(new Filter("123"));
Response<ResponseBody> response = call.execute();
// TODO handle user response...
// Print the request path that the server saw to show the JSON query param:
RecordedRequest recordedRequest = server.takeRequest();
System.out.println(recordedRequest.getPath());
server.shutdown();
}
}
代码示例来源:origin: Graylog2/graylog2-server
@POST
@Timed
@ApiOperation(value = "Resume message processing on node")
@Path("resume")
@NoAuditEvent("proxy resource, audit event will be emitted on target node")
public void resume(@ApiParam(name = "nodeId", value = "The id of the node where processing will be resumed.", required = true)
@PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
final Response response = this.getRemoteSystemProcessingResource(nodeId).resume().execute();
if (!response.isSuccessful()) {
LOG.warn("Unable to resume message processing on node {}: {}", nodeId, response.message());
throw new WebApplicationException(response.message(), BAD_GATEWAY);
}
}
}
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException, InterruptedException {
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse());
server.enqueue(new MockResponse());
server.start();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new ChunkingConverterFactory())
.addConverterFactory(GsonConverterFactory.create())
.build();
Service service = retrofit.create(Service.class);
Repo retrofitRepo = new Repo("square", "retrofit");
service.sendNormal(retrofitRepo).execute();
RecordedRequest normalRequest = server.takeRequest();
System.out.println(
"Normal @Body Transfer-Encoding: " + normalRequest.getHeader("Transfer-Encoding"));
service.sendChunked(retrofitRepo).execute();
RecordedRequest chunkedRequest = server.takeRequest();
System.out.println(
"@Chunked @Body Transfer-Encoding: " + chunkedRequest.getHeader("Transfer-Encoding"));
server.shutdown();
}
}
代码示例来源:origin: square/retrofit
Service service = retrofit.create(Service.class);
Library library1 = service.exampleMoshi().execute().body();
System.out.println("Library 1: " + library1.name);
Library library2 = service.exampleGson().execute().body();
System.out.println("Library 2: " + library2.name);
Library library3 = service.exampleSimpleXml().execute().body();
System.out.println("Library 3: " + library3.name);
Library library4 = service.exampleDefault().execute().body();
System.out.println("Library 4: " + library4.name);
代码示例来源:origin: square/retrofit
Service service = retrofit.create(Service.class);
Response<User> response = service.getUser().execute();
代码示例来源:origin: square/retrofit
@Override public void call(Subscriber<? super Response<T>> subscriber) {
// Since Call is a one-shot type, clone it for each new subscriber.
Call<T> call = originalCall.clone();
CallArbiter<T> arbiter = new CallArbiter<>(call, subscriber);
subscriber.add(arbiter);
subscriber.setProducer(arbiter);
Response<T> response;
try {
response = call.execute();
} catch (Throwable t) {
Exceptions.throwIfFatal(t);
arbiter.emitError(t);
return;
}
arbiter.emitResponse(response);
}
}
代码示例来源:origin: square/retrofit
Response<T> response = call.execute();
if (!disposable.isDisposed()) {
observer.onNext(response);
代码示例来源:origin: resilience4j/resilience4j
@Test(expected = IOException.class)
public void shouldNotCatchCallExceptionsInRateLimiter() throws Exception {
stubFor(get(urlPathEqualTo("/greeting"))
.willReturn(aResponse()
.withStatus(200)
.withFixedDelay(400)));
service.greeting().execute();
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void decorateSuccessfulCall() throws Exception {
stubFor(get(urlPathEqualTo("/greeting"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/plain")
.withBody("hello world")));
service.greeting().execute();
verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}
内容来源于网络,如有侵权,请联系作者删除!