简体   繁体   English

RMI:远程对象的字段是否已序列化并发送到客户端?

[英]RMI: are fields of remote object serialized and sent to client?

I have the following code: 我有以下代码:

public class Foo implements SomeRemote {
  private String verySecretString;
  public void doSomething(){...}
}

As I understand foo will somehow be serialized and sent from RMI server to RMI client. 据我了解,foo将以某种方式被序列化并从RMI服务器发送到RMI客户端。 So, can the client access anyway verySecretString ? 因此,客户端仍然可以访问verySecretString吗?

This is not how it works, you are supposed to expose a Remote interface instead of a class then manipulate the interface at client level this way the client has no idea of the implementation details. 这不是它的工作原理,应该公开一个Remote接口而不是一个类,然后在客户端级别操作该接口,这样客户端就不知道实现细节。

So here you should rather have something like: 因此,在这里您应该拥有类似的东西:

public interface MyService extends Remote {
    void doSomething() throws RemoteException;
}

This is only what you know at the client level. 这只是您在客户端级别上了解的内容。 At the sever level you will have your implementation Foo , something like: 在服务器级别,您将实现Foo ,类似于:

public class Foo implements MyService {
    private String verySecretString;
    public void doSomething(){...}
}

Response Update: 回应更新:

If you don't want a field value to be serialized simply add the keyword transient to its declaration as next: 如果您不想序列化字段值,则只需在其声明中添加关键字transient ,如下所示:

private transient String verySecretString;

As I understand foo will somehow be serialized and sent from RMI server to RMI client. 据我了解,foo将以某种方式被序列化并从RMI服务器发送到RMI客户端。

No. If Foo is an exported remote object it won't be sent anywhere. 否。如果Foo是导出的远程对象,则不会将其发送到任何地方。 Its stub will be sent. 它的存根将被发送。

So, can the client access anyway verySecretString? 那么,客户端仍然可以访问verySecretString吗?

No. 没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM