【问题标题】:Restlet Framework. Serialization. Don't understand how send and receive objectRestlet 框架。序列化。不明白如何发送和接收对象
【发布时间】: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 以了解如何传递它们。提示:您通过ClientResourceclientDispatcher 调用服务器资源并且您不直接调用login 方法...

标签: java rest restlet restlet-2.0


【解决方案1】:

您需要为此使用 ClientResource。它应该类似于以下内容:

ClientResource cr = new ClientResource(PATH_TO_URL);
AuthorizationResource proxy = cr.wrap(AuthorizationResource.class)
proxy.login(auth);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    相关资源
    最近更新 更多