import co.paralleluniverse.fibers.okhttp.FiberOkHttpClient;
import co.paralleluniverse.strands.SuspendableCallable;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class HttpClientExample {
public static void main(String[] args) throws Exception {
OkHttpClient client = FiberOkHttpClient.newFiberOkHttpClient();
Request request = new Request.Builder()
.url("https://example.com")
.build();
Response response = FiberOkHttpClient.execute(client, new SuspendableCallable<Response>() {
@Override
public Response run() throws SuspendExecution, InterruptedException {
try {
return client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
});
if (response != null && response.isSuccessful()) {
System.out.println(response.body().string());
} else {
System.out.println("Request failed.");
}
}
}