【发布时间】:2012-04-10 05:22:12
【问题描述】:
我正在使用 RESTlet 框架。
我不明白服务器如何获取客户端发送的对象。例如。 我在客户端有这样一个界面:
public interface AuthorizationResource {
@Post
public void login(Authentication auth);
}
然后我将 Authentication 类的对象发送到服务器:
Authentication auth = new Authentication ("login", "password");
resource.login(auth);
Authentication 类(这两个类在服务器和客户端上都可用):
public class Authentication implements Serializable{
private static final long serialVersionUID = 1L;
public String login;
public String password;
public Authentication() {}
public Authentication(String login, String password) {
super();
this.login = login;
this.password = password;
}
public String getLogin() {
return login;
}
public String getPassword() {
return password;
}
public void setLogin(String login) {
this.login = login;
}
public void setPassword(String password) {
this.password = password;
}
}
那么在服务器端,我要获取Authentication类的对象:
public class AuthenticationServerResource extends ServerResource {
Authentication auth = new Authentication("defaultLogin", "defaultPassword");
@Post
public void login (Authentication auth) {
this.auth = auth;
System.out.println(auth.getLogin());
}
}
但什么也没发生。控制台不输出任何东西。
我的问题,序列化对象的最佳方法是什么?我的方法对吗?
【问题讨论】:
-
我建议你在 restlet 中查找
Representation以了解如何传递它们。提示:您通过ClientResource或clientDispatcher调用服务器资源并且您不直接调用login方法...
标签: java rest restlet restlet-2.0