我是 JAX-WS 的新手,我创建了一个测试样本,例如:
服务器:
@Path("/login")
public class Login {
public Login(){
initDB();
}
@GET
@Path("{username}/{password}")
@Produces(MediaType.TEXT_PLAIN)
public String login(@PathParam("username") String username,@PathParam("password") String password) {
int id = db.login(username, password);
return ""+id;
}
}
客户:
public class WSConnection {
private ClientConfig config;
private Client client;
private WebResource service;
public WSConnection(){
config = new DefaultClientConfig();
client = Client.create(config);
service = client.resource(getBaseURI());
}
public int login(String username,String password){
return Integer.parseInt(service.path("rest").path("login").path(username).path(password).accept(
MediaType.TEXT_PLAIN).get(String.class));
}
private URI getBaseURI() {
return UriBuilder.fromUri(
"http://localhost:8080/Project2").build();
}
}
在服务器中,在方法登录时,我返回从用户名和密码中选择的用户的 ID。如果我想返回对象:
public class Utente {
private int id;
private String username;
private String nome;
private String cognome;
public Utente(int id, String username, String nome, String cognome) {
this.id = id;
this.username = username;
this.nome = nome;
this.cognome = cognome;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
}
我必须做什么?有人可以解释一下吗?谢谢你!!!:)