有没有办法拦截客户端的RequestFactory请求?
我想截取这样的电话:
dummyRequest.dummyOperation().fire( new Receiver<String>() {
@Override
public void onSuccess(String response) {
}
});
这个想法是在与服务器通信时显示一些加载指示。
答案 0 :(得分:6)
您可以覆盖默认传输实现并在RF初始化期间传递它:
SampleRequestFactory factory = GWT.create( SampleRequestFactory.class );
factory.initialize( new SimpleEventBus(), new DefaultRequestTransport() );
您可以从DefaultRequestTransport继承并覆盖方法
send(String payload, TransportReceiver receiver)
在调用超级实现之前进行一些处理,并使用委托包装TransportReceiver来处理结果。
答案 1 :(得分:3)
final DefaultRequestTransport requestTransport = new DefaultRequestTransport() {
@Override
public void send(final String payload, final TransportReceiver receiver) {
GWT.log("making rpc");
final TransportReceiver proxy = new TransportReceiver() {
@Override
public void onTransportFailure(final ServerFailure failure) {
GWT.log("rpc returned");
receiver.onTransportFailure(failure);
}
@Override
public void onTransportSuccess(final String payload) {
GWT.log("rpc returned");
receiver.onTransportSuccess(payload);
}
};
super.send(payload, proxy);
}