简体   繁体   中英

playframework global callback for successful response

I am using Play!Framework 2.2.x(Java) for communication between server and mobile app.

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.

It would be very appreciated if anybody give me some ideas in this case.

I did as follows on 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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