如何在Java Play中的复合动作中修改请求正文

时间:2018-09-05 11:10:21

标签: java playframework

我在Java play 2.6中具有以下复合操作:

public class EncryptPasswordAction extends Action<EncryptPassword> {

    @Override
    public CompletionStage<Result> call(Context ctx) {
        User actionAuthor = (User) ctx.args.get(JWTDeadboltHandler.CURRENT_USER_KEY);
        JsonNode requestData = ctx.request().body().asJson();
        for (Iterator<String> fNames = requestData.fieldNames(); fNames.hasNext();) {
            String fieldName = fNames.next();
            if (fieldName == "password") {
                byte[] encryptedPassword = DBUtils.getEncryptedPassword(actionAuthor.getEmail(),
                        requestData.get(fieldName).asText());
                ((ObjectNode) requestData).put(fieldName, encryptedPassword);
            }
        }
        //Do something to update the request body with the new password value
        return delegate.call(ctx);
    }
}

目标是加密json正文中任何名为password的字段。加密字段后,如何在调用delegate.call(ctx)之前修改请求的主体,以便将password字段的新值用于以下操作?

0 个答案:

没有答案