1

I am using RESTlet framework.

I don't understand how server can take an object sent by the client. For example. I have such an interface on the client side:

public interface AuthorizationResource {
    @Post
    public void login(Authentication auth);
}

Then I send to server the object of Authentication class:

Authentication auth = new Authentication ("login", "password");

resource.login(auth);

The Authentication class (Both classes are also available on the server and client):

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

Then on the server side, I want to get the object of Authentication class:

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

but nothing happens. The console doesn't output anything.

My questions, which is best way to serialize an object? Is my way right?

Arul Kumaran
  • 983
  • 7
  • 23
Sultan
  • 21
  • 1
  • 6
  • I suggest you look up `Representation` in restlet to see how to pass them around. Tip: You call a server resource via a `ClientResource` or a `clientDispatcher` and you don't invoke the `login` method directly... – PhD Apr 23 '12 at 22:23

1 Answers1

0

You need to use ClientResource for this. it should be something like the following:

ClientResource cr = new ClientResource(PATH_TO_URL);
AuthorizationResource proxy = cr.wrap(AuthorizationResource.class)
proxy.login(auth);
ravyoli
  • 698
  • 6
  • 13