我一直在我的 Play! 中使用动作合成!到目前为止,这些应用程序运行良好。然而,随着最近的 2.2.0 更新,它们不再工作,我不知道如何正确更新它们。
以这个动作为例:
public class ChatMsgValidation extends Action<ChatMsgValidation.ValidChatMsg> {
@With(ChatMsgValidation.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidChatMsg {
}
public Result call(Http.Context ctx) throws Throwable {
Utils.debugFunctionCall("ValidChatMsg() " + ctx.toString());
// validate we got the "player" parameter
JsonNode jsonRequest = request().body().asJson();
if (!WSUtils.validateJSONField(Constants.JSON_MSG, jsonRequest)) {
return badRequest(WSUtils.simpleMissingFieldMsg(Constants.JSON_MSG));
}
RequestParser requestParser = new RequestParser(request());
String chatMsg = requestParser.getMessage();
if (chatMsg.isEmpty()) {
return badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("message.cannot.be.empty.error"), FailConstants.REASON_EMPTY));
}
if (chatMsg.length() < Constants.MIN_CHAT_MESSAGE_LENGTH) {
return badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("query.lower.limit.error"), FailConstants.REASON_TOO_SHORT));
}
if (chatMsg.length() > Constants.MAX_CHAT_MESSAGE_LENGTH) {
return badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("message.too.long.error"), FailConstants.REASON_TOO_LONG));
}
return delegate.call(ctx);
}
}
现在的问题是“call”方法应该返回“Promise”而不是“Result”,并且我无法找到一种方法来返回简单的 JSON 消息,而无需执行大量代码,无用的代码,因为我正在创建虚拟函数只是为了有承诺。一定有更好的方法我没有看到,请指教。
我为我的问题找到了更好的解决方案。如下:
return F.Promise.pure((SimpleResult) badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("message.cannot.be.empty.error"), FailConstants.REASON_EMPTY)));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)