2013-09-25 9 views
6

私はPlayでアクションコンポジションを使用しています!今まではアプリでしたが、うまく機能しました。しかし、最近の2.2.0アップデートでは、もう動作しません。正しく更新する方法がわかりません。PlayFramework 2.2 Java Action Composition

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); 
} 
} 

問題は今、「コール」方式である「結果」の代わりに「約束」を返す必要があります、と私は返す方法を把握することはできません。たとえば、このアクションは、その

私はダミー関数を作成しているだけなので、たくさんのコードや無駄なコードを使わずに簡単なJSONメッセージを受け取ることができます。私が見ていないより良い方法がある必要があります、助言してください。

答えて

9

私は自分の問題に対してより良い解決策を見つけました。次のとおりです。

return F.Promise.pure((SimpleResult) badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("message.cannot.be.empty.error"), FailConstants.REASON_EMPTY)));