Я написал этот спокойный клиент веб-сервиса для использования веб-сервиса JAX-RS. Я хотел бы использовать его на Android, но Android не поддерживает библиотеки javax.ws или javax.xml.bind. Есть ли простой способ конвертировать код для работы на Android без необходимости полного пересмотра? если нет, то что я могу использовать для простого API-интерфейса restful для Android?
package databaseAccess;
import databaseAccess.Recipe.recipeType;
import databaseAccess.UserProfile.skillLevel;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
public class DatabaseService {
private static final String BASE_URI =
"http://localhost:8080/RecipeAppDatabaseService/webresources";
private Client client;
public DatabaseService() {
client = ClientBuilder.newClient();
}
/**
* validate if correct password (on sign-in)
* @return if correct - the user's profile. if incorrect username or
password - returns null
*/
public UserProfile validateSignIn(String email, String password) {
WebTarget webTarget =
client.target(BASE_URI).path("userProfile/signIn/" + email + "/" +
password);
return webTarget.request().get(UserProfile.class);
}
/**
* add a new user to the database (on first sign-up)
*/
public Response addUser(UserProfile user, String password) {
WebTarget webTarget = client.target(BASE_URI).path("userProfile/add/"
+ password);
Response response =
webTarget.request().post(Entity.entity(user,MediaType.APPLICATION_XML));
return response;
}
/**
* delete account
*/
public Response deleteUser(String email) {
WebTarget webTarget = client.target(BASE_URI).path("userProfile/" +
email);
Response response = webTarget.request().delete();
return response;
}
/**
* get User profile based on a given email
* @return user profile
*/
public UserProfile getUser(String email) {
WebTarget webTarget = client.target(BASE_URI).path("userProfile/" +
email);
return webTarget.request().get(UserProfile.class);
}
/**
* add a follower to a user
*/
public Response addFollower(String userEmail, String followerEmail) {
WebTarget webTarget = client.target(BASE_URI).path("userProfile/" + userEmail + "/" + followerEmail);
Response response = webTarget.request().get();
return response;
}
/**
* add a follower to a user
*/
public Response deleteFollower(String userEmail, String followerEmail) {
WebTarget webTarget = client.target(BASE_URI).path("userProfile/" +
userEmail + "/" + followerEmail);
Response response = webTarget.request().delete();
return response;
}
...
package databaseAccess;
import java.io.Serializable;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class UserProfile implements Serializable {
public enum skillLevel{BEGINNER, INTERMEDIATE, PRO}
private String email;
private String firstName;
private String lastName;
private skillLevel cookingSkills;
@XmlElement
private ArrayList<String> cuisines;
private String country;
@XmlElement
private ArrayList<String> followers; // emails of followers
@XmlElement
private ArrayList<String> followerOf; // emails of people the user
follows
public UserProfile() {
followers = new ArrayList<>();
followerOf = new ArrayList<>();
cuisines = new ArrayList<>();
}
...