1

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());
    }
}

しかし、何も起こりません。コンソールには何も出力されません。

オブジェクトをシリアル化する最良の方法はどれですか? 私のやり方は正しいですか?

4

1 に答える 1

0

これには ClientResource を使用する必要があります。次のようなものにする必要があります。

ClientResource cr = new ClientResource(PATH_TO_URL);
AuthorizationResource proxy = cr.wrap(AuthorizationResource.class)
proxy.login(auth);
于 2012-06-03T19:43:56.650 に答える