ped*_*oso 6 java playframework playframework-2.0
我一直在Play上使用Action组合!直到现在的应用程序,他们工作正常.但是最近的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);
}
}
Run Code Online (Sandbox Code Playgroud)
Problem is now the "call" method should return "Promise" instead of "Result", and I can't figure out a way to return a simple JSON message without doing a LOT of code, useless code because I'm creating dummy functions just to have Promises. There has to be a better way I'm not seeing, please advise.
我为我的问题找到了更好的解决方案.它如下:
return F.Promise.pure((SimpleResult) badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("message.cannot.be.empty.error"), FailConstants.REASON_EMPTY)));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2479 次 |
最近记录: |