use of retrofit2.http in project resilience4j by resilience4j.
the class RetrofitRateLimiterTest method setUp.
@Before
public void setUp() {
// ms
final long TIMEOUT = 300;
OkHttpClient client = new OkHttpClient.Builder().connectTimeout(TIMEOUT, TimeUnit.MILLISECONDS).readTimeout(TIMEOUT, TimeUnit.MILLISECONDS).writeTimeout(TIMEOUT, TimeUnit.MILLISECONDS).build();
this.rateLimiter = RateLimiter.of("backendName", config);
this.service = new Retrofit.Builder().addCallAdapterFactory(RateLimiterCallAdapter.of(rateLimiter)).addConverterFactory(ScalarsConverterFactory.create()).client(client).baseUrl("http://localhost:8080/").build().create(RetrofitService.class);
}
use of retrofit2.http in project elastest-torm by elastest.
the class DockerComposeService method setup.
public void setup() throws IOException, InterruptedException {
// 1. Start docker-compose-ui container
dockerComposeUiContainerName = dockerService.generateContainerName(dockerComposeUiPrefix);
int dockerComposeBindPort = dockerService.findRandomOpenPort();
Binding bindNoVncPort = bindPort(dockerComposeBindPort);
ExposedPort exposedNoVncPort = tcp(dockerComposeUiPort);
String dockerComposeServiceUrl = "http://" + dockerService.getDockerServerIp() + ":" + dockerComposeBindPort;
log.debug("Starting docker-compose-ui container: {}", dockerComposeUiContainerName);
List<PortBinding> portBindings = asList(new PortBinding(bindNoVncPort, exposedNoVncPort));
Volume volume = new Volume(dockerDefaultSocket);
List<Volume> volumes = asList(volume);
List<Bind> binds = asList(new Bind(dockerDefaultSocket, volume));
DockerBuilder dockerBuilder = dockerBuilder(dockerComposeUiImageId, dockerComposeUiContainerName).portBindings(portBindings).volumes(volumes).binds(binds);
dockerService.startAndWaitContainer(dockerBuilder.build());
// 2. Create Retrofit object to call docker-compose-ui REST API
OkHttpClient okHttpClient = new OkHttpClient.Builder().readTimeout(dockerComposeTimeout, SECONDS).connectTimeout(dockerComposeTimeout, SECONDS).build();
Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create()).baseUrl(dockerComposeServiceUrl).build();
dockerComposeApi = retrofit.create(DockerComposeApi.class);
log.debug("docker-compose-ui up and running on URL: {}", dockerComposeServiceUrl);
// 3.Delete default example projects
dockerService.waitForHostIsReachable(dockerComposeServiceUrl);
String[] defaultProjects = { "env-demo", "hello-node", "node-redis", "volumes-demo", "volumes-relative-paths" };
removeProjects(defaultProjects);
}
use of retrofit2.http in project bdcodehelper by boredream.
the class LcErrorConstants method parseHttpErrorInfo.
/**
* 解析服务器错误信息
*/
public static String parseHttpErrorInfo(Throwable throwable) {
String errorInfo = throwable.getMessage();
if (throwable instanceof HttpException) {
// 如果是Retrofit的Http错误,则转换类型,获取信息
HttpException exception = (HttpException) throwable;
ResponseBody responseBody = exception.response().errorBody();
MediaType type = responseBody.contentType();
// 如果是application/json类型数据,则解析返回内容
if (type != null && type.type().equals("application") && type.subtype().equals("json")) {
try {
// 这里的返回内容是Bmob/AVOS/Parse等RestFul API文档中的错误代码和错误信息对象
BaseResponse errorResponse = new Gson().fromJson(responseBody.string(), BaseResponse.class);
errorInfo = getLocalErrorInfo(errorResponse);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (throwable instanceof LcErrorResponse) {
LcErrorResponse lce = (LcErrorResponse) throwable;
errorInfo = getLocalErrorInfo(lce.getError());
} else {
if (throwable instanceof UnknownHostException) {
errorInfo = "无法连接到服务器";
}
}
return errorInfo;
}
use of retrofit2.http in project RxJavaSamples by rengwuxian.
the class Network method getZhuangbiApi.
public static ZhuangbiApi getZhuangbiApi() {
if (zhuangbiApi == null) {
Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).baseUrl("http://www.zhuangbi.info/").addConverterFactory(gsonConverterFactory).addCallAdapterFactory(rxJavaCallAdapterFactory).build();
zhuangbiApi = retrofit.create(ZhuangbiApi.class);
}
return zhuangbiApi;
}
use of retrofit2.http in project RxJavaSamples by rengwuxian.
the class Network method getGankApi.
public static GankApi getGankApi() {
if (gankApi == null) {
Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).baseUrl("http://gank.io/api/").addConverterFactory(gsonConverterFactory).addCallAdapterFactory(rxJavaCallAdapterFactory).build();
gankApi = retrofit.create(GankApi.class);
}
return gankApi;
}
Aggregations