简体   繁体   English

playframework全局回调,可成功响应

[英]playframework global callback for successful response

I am using Play!Framework 2.2.x(Java) for communication between server and mobile app. 我正在使用Play!Framework 2.2.x(Java)在服务器和移动应用程序之间进行通信。

I want to get callback if the mobile app request data and it was successfully returned in controller's action. 如果移动应用请求数据并且在控制器的操作中成功返回数据,我想获取回调。

Because I want to store last time the app successfully get the data from the server, so that I can only provide the data after that time if the app is not request specific time of data. 因为我要存储上次应用程序成功从服务器获取数据的时间,所以如果应用程序未请求特定时间的数据,则只能在该时间之后提供数据。

I looked at play.GlobalSettings, there are onRequest, onBadRequest, OnError, however I can't find onSuccess kind of global handler. 我看了看play.GlobalSettings,有onRequest,onBadRequest,OnError,但是找不到onSuccess类型的全局处理程序。

It would be very appreciated if anybody give me some ideas in this case. 如果有人在这种情况下给我一些想法,将不胜感激。

I did as follows on GlobalSettings#onRequest, 我对GlobalSettings#onRequest进行了以下操作,

@Override
public Action onRequest(Request request, Method method) {

    return new Action.Simple() {

        @Override
        public Promise<SimpleResult> call(Context context) throws Throwable {
            // TODO: do something before actual action call.

            Promise<SimpleResult> call = delegate.call(context);
            Callback<SimpleResult> callbackOnRedeem = new Callback<SimpleResult>() {

                @Override
                public void invoke(SimpleResult result) throws Throwable {
                    // TODO : do something after action call.
                }

            };
            call.onRedeem(callbackOnRedeem);
            return call;
        }

     };
}

Javadoc for onRedeem: 适用于onRedeem的Javadoc:

http://www.playframework.com/documentation/2.2.0/api/java/play/libs/F.Promise.html#onRedeem(play.libs.F.Callback) http://www.playframework.com/documentation/2.2.0/api/java/play/libs/F.Promise.html#onRedeem(play.libs.F.Callback)

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

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