2013-09-25 6 views
6

मैं अपने प्ले पर एक्शन कंपोज़िशन का उपयोग कर रहा हूं! अब तक ऐप्स, और उन्होंने ठीक काम किया। हालांकि हाल ही में 2.2.0 अपडेट के साथ वे अब काम नहीं करते हैं और मुझे नहीं पता कि उन्हें सही तरीके से कैसे अपडेट किया जाए।PlayFramework 2.2 जावा एक्शन कंपोज़िशन

उदाहरण के लिए इस कार्रवाई यही कारण है कि:

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