为什么入口方法会被调用两次?

问题描述 投票:0回答:1

我有一段代码如下。有没有人经历过这个问题?谢谢!

def update() {
    String metadata = request.reader.text
    logger.info("Updating the submission: $metadata")
    Map<String, Object> working = [isUpdate: true, isUpdateOnExistingModel: true, isAmend: false, isMetadataSubmission: false]
    if (metadata) {
        makeSubmission(metadata, working)
    } else {
        logger.debug("Cannot update the model as requested because of the empty input.")
    }
}

private void makeSubmission(String metadata, Map working) {
    String uuid = request.getHeader("SubmissionFolder")
    working.put("submissionFolder", uuid)
    def currentUser = springSecurityService.currentUser
    working.put("submitterInfo", [userRealName: currentUser?.person?.userRealName,
                                      username: currentUser.username, email: currentUser.email])
    Map map
    try {
        submissionService.buildFromJSONFile(metadata, working)
    } catch (Exception e) {
       logger.error e.getMessage()
    } finally {
       working["repository_files"] = null
       if (!working["repository_files"]) {
           String msg = "Cannot find the model files. The submission process has to be terminated!"
           logger.error(msg)
           map = [message: msg, status: 400]
       } else {
           doValidateSubmissionData(working)
           map = doCompleteSubmission()
       }
    }

    withFormat {
        json { render map as JSON }
        xml { render map as XML }
        '*' { render status: 415, view: "/errors/error415" }
    }
}

当我启用调试模式(在 IntelliJ IDEA 中)时,入口点(例如,

update
)会被调用两次。请参阅屏幕录制此处

debugging grails
1个回答
0
投票

您使用哪个 http 动词?您如何调用端点?

我建议您检查是否是 Chrome 预加载页面导致的。一些 GET 路由可能会因此被“激活”两次。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.