Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 关贸总协定中的邮政请求_Scala_Gatling - Fatal编程技术网

Scala 关贸总协定中的邮政请求

Scala 关贸总协定中的邮政请求,scala,gatling,Scala,Gatling,我在发布pdf文件时遇到了一个问题。在Gatling 2.1.7中录制了一个HAR文件后,我得到了以下信息: .exec(http("request_10") .post("/api/data/files?revisionId=e9af2c93-d8df-4424-b307-df4c4abbaad1&uploadType=read_only_file&fileType=application%2Fpdf&fileName=testdocument.pdf&

我在发布pdf文件时遇到了一个问题。在Gatling 2.1.7中录制了一个HAR文件后,我得到了以下信息:

.exec(http("request_10")
        .post("/api/data/files?revisionId=e9af2c93-d8df-4424-b307-df4c4abbaad1&uploadType=read_only_file&fileType=application%2Fpdf&fileName=testdocument.pdf&fileSize=10080&copyToEditable=true")
        .headers(Map(
            "Accept-Encoding" -> "gzip, deflate",
            "Content-Type" -> "multipart/form-data; boundary=----WebKitFormBoundaryawCJ4mjL1imiO7Ye"
            "Origin" -> url))
        .body(RawFileBody("RecordedSimulation_0010_request.txt")))
内容为
RecordedSimulation\u 0010\u request.txt

------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableChunkNumber"

1
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableChunkSize"

1048576
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableCurrentChunkSize"

10080
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableTotalSize"

10080
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableType"

application/pdf
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableIdentifier"

66dc65bf-265d-4363-96fd-7fc13f8ceda4
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableFilename"

testdocument.pdf
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableRelativePath"

testdocument.pdf
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="resumableTotalChunks"

1
------WebKitFormBoundaryawCJ4mjL1imiO7Ye
Content-Disposition: form-data; name="file"; filename="blob"
Content-Type: application/octet-stream


------WebKitFormBoundaryawCJ4mjL1imiO7Ye--
当我尝试回放时,这不起作用(可能是由于唯一的ID),因此(在Bodys文件夹中粘贴
testdocument.pdf
后),我执行了以下操作:

val documentFeeder = Iterator.continually(Map(
        "documentBoundary" -> (Random.alphanumeric.take(16).mkString),
        "documentUuid" -> ((Random.alphanumeric.take(8).mkString + "-" +
                           Random.alphanumeric.take(4).mkString + "-" + 
                           Random.alphanumeric.take(4).mkString + "-" +
                           Random.alphanumeric.take(4).mkString + "-" +
                           Random.alphanumeric.take(12).mkString).toLowerCase)))

...

.feed(documentFeeder)
// a previous exec POST with a check to grab the documentRevisionId

.exec(http("Post document: upload the file")
            .post("/api/data/files")
            .queryParamMap(Map(
                "revisionId" -> "${documentRevisionId}",
                "uploadType" -> "read_only_file",
                "fileType" -> "application%2Fpdf",
                "fileName" -> "testdocument.pdf",
                "fileSize" -> "10080",
                "copyToEditable" -> "true"))
            .headers(Map(
                "Accept-Encoding" -> "gzip, deflate",
                "Content-Type" -> "multipart/form-data; boundary=----WebKitFormBoundary${documentBoundary}"
                "Origin" -> url))

            .body(StringBody("""------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableChunkNumber"

                                1
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableChunkSize"

                                1048576
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableCurrentChunkSize"

                                10080
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableTotalSize"

                                10080
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableType"

                                application/pdf
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableIdentifier"

                                ${documentUuid}
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableFilename"

                                testdocument.pdf
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableRelativePath"

                                testdocument.pdf
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableTotalChunks"

                                1
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="file"; filename="blob"
                                Content-Type: application/octet-stream
                                Content-Transfer-Encoding: BINARY


                                ------WebKitFormBoundary${documentBoundary}--""")))
.exec(http("test post")
            .post("/api/data/files")
            .headers(Headers.headers_6)
            .formParamMap(Map(
                "revisionId" -> "${documentRevisionId}",
                "uploadType" -> "read_only_file",
                "fileType" -> "application%2Fpdf",
                "fileName" -> "testdocument.pdf",
                "fileSize" -> "10080",
                "copyToEditable" -> "true"))
            .bodyPart(StringBodyPart("""{ "resumableChunkNumber": "1",
                "resumableChunkSize": "1048576",
                "resumableCurrentChunkSize": "10080",
                "resumableTotalSize": "10080",
                "resumableType": "application/pdf",
                "resumableIdentifier": "${documentUuid}",
                "resumableFilename": "testdocument.pdf",
                "resumableRelativePath": "testdocument.pdf",
                "resumableTotalChunks": "1" }""")).asJSON
            .bodyPart(RawFileBodyPart("file", "testdocument.pdf")
                .fileName("testdocument.pdf")
                .transferEncoding("binary")).asMultipartForm)
最后,这里是Node.js代码,用于在我们的应用程序中发布虚拟数据(我使用它作为参考,因为我知道它可以工作):

我花了几天时间解决这个问题,这是我第一次涉足Scala和Gatling。我在这里错过了什么来获得这个职位

一个突出的问题(尽管这可能是一个转移视线的问题)是,我的应用程序在标题中使用了
内容长度
——考虑到盖特林遗漏了它,这是否有必要?如果有必要,我是否能够在不硬编码的情况下将数字插入Gatling

编辑

读完这篇文章后,我尝试了以下方法:

val documentFeeder = Iterator.continually(Map(
        "documentBoundary" -> (Random.alphanumeric.take(16).mkString),
        "documentUuid" -> ((Random.alphanumeric.take(8).mkString + "-" +
                           Random.alphanumeric.take(4).mkString + "-" + 
                           Random.alphanumeric.take(4).mkString + "-" +
                           Random.alphanumeric.take(4).mkString + "-" +
                           Random.alphanumeric.take(12).mkString).toLowerCase)))

...

.feed(documentFeeder)
// a previous exec POST with a check to grab the documentRevisionId

.exec(http("Post document: upload the file")
            .post("/api/data/files")
            .queryParamMap(Map(
                "revisionId" -> "${documentRevisionId}",
                "uploadType" -> "read_only_file",
                "fileType" -> "application%2Fpdf",
                "fileName" -> "testdocument.pdf",
                "fileSize" -> "10080",
                "copyToEditable" -> "true"))
            .headers(Map(
                "Accept-Encoding" -> "gzip, deflate",
                "Content-Type" -> "multipart/form-data; boundary=----WebKitFormBoundary${documentBoundary}"
                "Origin" -> url))

            .body(StringBody("""------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableChunkNumber"

                                1
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableChunkSize"

                                1048576
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableCurrentChunkSize"

                                10080
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableTotalSize"

                                10080
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableType"

                                application/pdf
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableIdentifier"

                                ${documentUuid}
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableFilename"

                                testdocument.pdf
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableRelativePath"

                                testdocument.pdf
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="resumableTotalChunks"

                                1
                                ------WebKitFormBoundary${documentBoundary}
                                Content-Disposition: form-data; name="file"; filename="blob"
                                Content-Type: application/octet-stream
                                Content-Transfer-Encoding: BINARY


                                ------WebKitFormBoundary${documentBoundary}--""")))
.exec(http("test post")
            .post("/api/data/files")
            .headers(Headers.headers_6)
            .formParamMap(Map(
                "revisionId" -> "${documentRevisionId}",
                "uploadType" -> "read_only_file",
                "fileType" -> "application%2Fpdf",
                "fileName" -> "testdocument.pdf",
                "fileSize" -> "10080",
                "copyToEditable" -> "true"))
            .bodyPart(StringBodyPart("""{ "resumableChunkNumber": "1",
                "resumableChunkSize": "1048576",
                "resumableCurrentChunkSize": "10080",
                "resumableTotalSize": "10080",
                "resumableType": "application/pdf",
                "resumableIdentifier": "${documentUuid}",
                "resumableFilename": "testdocument.pdf",
                "resumableRelativePath": "testdocument.pdf",
                "resumableTotalChunks": "1" }""")).asJSON
            .bodyPart(RawFileBodyPart("file", "testdocument.pdf")
                .fileName("testdocument.pdf")
                .transferEncoding("binary")).asMultipartForm)

但我仍然没有成功。有什么关于前进的建议吗?

如果这对其他人有帮助的话,我正试图设置一个自定义边界,而盖特林已经这样做了。以下是解决我问题的方法:

.exec(http("Post document: upload the file")
            .post("/api/data/files?revisionId=${documentRevisionId}&uploadType=read_only_file&fileType=application%2Fpdf&fileName=testdocument.pdf&fileSize=10080&copyToEditable=true") // ensure testdocument.pdf is in user-files/bodies
            .headers(Headers.headers_6)
            .formParamMap(Map(
                "resumableChunkNumber" -> "1",
                "resumableChunkSize" -> "1048576",
                "resumableCurrentChunkSize" -> "10080",
                "resumableTotalSize" -> "10080",
                "resumableType" -> "application/pdf",
                "resumableIdentifier" -> "${documentUuid}",
                "resumableFilename" -> "testdocument.pdf",
                "resumableRelativePath" -> "testdocument.pdf",
                "resumableTotalChunks" -> "1"))
            .bodyPart(RawFileBodyPart("file", "testdocument.pdf")
                .fileName("testdocument.pdf")
                .transferEncoding("binary")).asMultipartForm)

虽然@Chuck的答案是正确的,但最简单的代码应该是

  http("Create contentV2")
    .post("/some/path")
    .header("Content-Type", "multipart/form-data")
    .bodyPart(StringBodyPart("changeRequest", changeRequest)).asMultipartForm
    .bodyPart(StringBodyPart("payload", ElFileBody(filename))).asMultipartForm
    .check(status is 201)
现在我们可以用多种东西代替StringBodyPart,如RawFileBodyPart、ByteArrayBodyPart等。更多信息