BlazeDS文档显示了如何在ActionScript和Java对象之间显式映射。例如,这适用于RPC服务,例如
import flash.utils.IExternalizable;
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
[Bindable]
[RemoteClass(alias="javaclass.User")]
public class User implements IExternalizable {
public var id : String;
public var secret : String;
public function User() {
}
public function readExternal(input : IDataInput) : void {
id = input.readObject() as String;
}
public function writeExternal(output : IDataOutput) : void {
output.writeObject(id);
}
}
和
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class User implements Externalizable {
protected String id;
protected String secret;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
id = (String) in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(id);
}
}
如果我调用了返回User
的RPC服务,则secret
不会通过网络发送。
是否也可以为消息传递服务执行此操作?也就是说,如果我创建自定义消息传递适配器并使用下面的功能,我还可以阻止发送secret
吗?
MessageBroker messageBroker = MessageBroker.getMessageBroker(null);
AsyncMessage message = new AsyncMessage();
message.setDestination("MyMessagingService");
message.setClientId(UUIDUtils.createUUID());
message.setMessageId(UUIDUtils.createUUID());
User user = new User();
user.setId("id");
user.setSecret("secret");
message.setBody(user);
messageBroker.routeMessageToService(message, null);