首页 > 解决方案 > 移动设备上符合 JAX-RS 的实现

问题描述

我正在编写一个应该在桌面和移动设备上运行的应用程序,它需要使用 REST 与服务器通信。我正在使用 Gluon Mobile。

我在客户端编写的代码是符合 jax-rs 的,如下所示:

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;

Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target("http://www...").path("/login/...");
Future<Response> future = target.request().async().get();
Response response = future.get();

我指定了对 RESTEASY 或 Jersey 客户端等实现的依赖。

Gluon Connect 具有 REST 实现,但不符合 JAX-RS:

RestClient restClient = RestClient.create()
        .method("GET")
        .host("https://...")
        .path("/login/...")
...

这意味着我的客户需要 2 个代码版本。我想像使用其余代码一样编写一次运行任何地方。可能吗?我可以在 android 和 ios 上使用 JAX-RS 实现吗?我需要告诉 gradle 在为 android 和 ios 构建桌面和其他实现时使用一种实现,对吗?

标签: javarestjax-rsgluon-mobile

解决方案


推荐阅读