question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom multipart/form-data fails with Karate 1.1.0

See original GitHub issue

A custom built multipart/form-data request unexpectedly fails with Karate 1.1.0 with a java.lang.NullPointerException.

The issue occurs in following line https://github.com/karatelabs/karate/blob/e3d8874cf18ad607582fb2b7a761813d7a9b98e0/karate-core/src/main/java/com/intuit/karate/http/HttpLogger.java#L129

The reason is that request.getBodyForDisplay() returns null which causes the subsequent getBytes() call to fail with a java.lang.NullPointerException.

This might be a regression introduced by replacing RequestLoggingInterceptor (Karate 0.9.6) with HttpLogger (Karate 1.1.0).

With Karate 0.9.6 ✔️

$ java -jar karate-0.9.6.jar issue.feature
10:27:00.993 [main]  INFO  com.intuit.karate.Main - Karate version: 0.9.6
10:27:01.492 [main]  INFO  com.intuit.karate.Runner - waiting for parallel features to complete ...
10:27:01.569 [ForkJoinPool-1-worker-1]  WARN  com.intuit.karate - skipping bootstrap configuration: could not find or read file: classpath:karate-config.js
10:27:02.454 [ForkJoinPool-1-worker-1]  DEBUG com.intuit.karate - request:
1 > POST https://httpbin.org/post
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 504
1 > Content-Type: multipart/form-data; boundary=Lhn4b4B7_HwoKBZ6MRRN2cbFOfR2Zt
1 > Host: httpbin.org
1 > User-Agent: Apache-HttpClient/4.5.12 (Java/1.8.0_302)

10:27:03.168 [ForkJoinPool-1-worker-1]  DEBUG com.intuit.karate - response time in milliseconds: 710,48
1 < 200
1 < Access-Control-Allow-Credentials: true
1 < Access-Control-Allow-Origin: *
1 < Connection: keep-alive
1 < Content-Length: 925
1 < Content-Type: application/json
1 < Date: Wed, 22 Dec 2021 09:27:03 GMT
1 < Server: gunicorn/19.9.0
{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "REQUEST": "{\"originator\":{\"id\":\"A\"},\"recipients\":[{\"id\":\"B\"}],\"service\":\"Karate\"}",
    "file.bin": "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u00004\u0003\ufffd\u0003A(QGh\ufffd\ufffdM\ufffd\ufffd\b\ufffd(\u064d\u03c8\ufffd\ufffd\ufffd\ufffdI\ufffd\ufffdv\ufffd\ufffd\ufffd\ufffdv\ufffd\ufffd\ufffd\ufffdv\ufffd\ufffd\ufffd8O\u0358\ufffdE\ufffd\u0347\uf
ffd\ufffd\ufffd\ufffd\ufffdY\ufffd\ufffdE\ufffd\ufffd\u0000d"
  },
  "headers": {
    "Accept-Encoding": "gzip,deflate",
    "Content-Length": "504",
    "Content-Type": "multipart/form-data; boundary=Lhn4b4B7_HwoKBZ6MRRN2cbFOfR2Zt",
    "Host": "httpbin.org",
    "User-Agent": "Apache-HttpClient/4.5.12 (Java/1.8.0_302)",
    "X-Amzn-Trace-Id": "Root=1-61c2ef67-0806205f092f51394dde07b8"
  },
  "json": null,
  "origin": "95.223.228.155",
  "url": "https://httpbin.org/post"
}


10:27:03.220 [pool-1-thread-1]  INFO  com.intuit.karate.Runner - <<pass>> feature 1 of 1: issue.feature
---------------------------------------------------------
feature: issue.feature
report: target\surefire-reports\issue.json
scenarios:  1 | passed:  1 | failed:  0 | time: 1,6149
---------------------------------------------------------

HTML report: (paste into browser to view) | Karate version: 0.9.6
file:/D:/karateIssue/target/surefire-reports/karate-summary.html
===================================================================

Karate version: 0.9.6
======================================================
elapsed:   2,09 | threads:    1 | thread time: 1,61
features:     1 | ignored:    0 | efficiency: 0,77
scenarios:    1 | passed:     1 | failed: 0
======================================================

With Karate 1.1.0

$ java -jar karate-1.1.0.jar issue.feature
10:24:32.465 [main]  INFO  com.intuit.karate - Karate version: 1.1.0
10:24:32.676 [main]  INFO  com.intuit.karate.Suite - backed up existing 'target\karate-reports' dir to: target\karate-reports_1640165072675
10:24:34.296 [main]  ERROR com.intuit.karate - java.lang.NullPointerException, http call failed after 53 milliseconds for url: https://httpbin.org/post
10:24:34.296 [main]  ERROR com.intuit.karate - issue.feature:10
When method POST
http call failed after 53 milliseconds for url: https://httpbin.org/post
issue.feature:10
---------------------------------------------------------
feature: issue.feature
scenarios:  1 | passed:  0 | failed:  1 | time: 0,9619
---------------------------------------------------------

10:24:34.929 [main]  INFO  com.intuit.karate.Suite - <<fail>> feature 1 of 1 (0 remaining) issue.feature
Karate version: 1.1.0
======================================================
elapsed:   2,34 | threads:    1 | thread time: 0,96
features:     1 | skipped:    0 | efficiency: 0,41
scenarios:    1 | passed:     0 | failed: 1
======================================================
>>> failed features:
http call failed after 53 milliseconds for url: https://httpbin.org/post
issue.feature:10
<<<

HTML report: (paste into browser to view) | Karate version: 1.1.0
file:///D:/karateIssue/target/karate-reports/karate-summary.html
===================================================================

com.intuit.karate.KarateException: there are test failures !
    at ...(.)

Feature used for testing

Feature: Custom multipart/form-data

Scenario:
    Given url "https://httpbin.org"
    And path "/post"
    And header Content-Type = "multipart/form-data; boundary=Lhn4b4B7_HwoKBZ6MRRN2cbFOfR2Zt"
    And request "--Lhn4b4B7_HwoKBZ6MRRN2cbFOfR2Zt\r\nContent-Disposition: form-data; name=\"REQUEST\"\r\nContent-Type: application/json; charset=UTF-8\r\nContent-Transfer-Encoding: 8bit\r\n\r\n{\"originator\":{\"id\":\"A\"},\"recipients\":[{\"id\":\"B\"}],\"service\":\"Karate\"}\r\n--Lhn4b4B7_HwoKBZ6MRRN2cbFOfR2Zt\r\nContent-Disposition: form-data; name=\"file.bin\"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: binary\r\n\r\n\x00\x00\x00\x00\x00\x00\x00\x004\x03\x94\x03A(QGh\x9c\x82M\xf2\xc7\x08\xdc(\xd9\x8d\xcf\x88\xe3\xcd\xf7\x85I\xed\xcfv\x85\x94\xed\xcfv\x85\x94\xed\xcfv\x85\x8f\xd98O\xcd\x98\xe3E\xf9\xcd\x87\xe4\xf9\xc8\xd7\xe4Y\xf8\xdeE\x98\xfd\x00d\r\n--Lhn4b4B7_HwoKBZ6MRRN2cbFOfR2Zt--"
    When method POST
    And status 200

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
a-stcommented, Dec 22, 2021

@ptrthomas many thanks for the fast bugfix commit 👍

We are aware of the multipart file / multipart field options (we are using them for different testcases), but for our very specific testcase, we would like to build our own multipart/form-data request in order to remove required fields (i.e. the name attribute of Content-Disposition: form-data; name="fieldname")

0reactions
ptrthomascommented, May 9, 2022

1.2.0 released

Read more comments on GitHub >

github_iconTop Results From Across the Web

Karate - multipart fields with json value getting response code ...
Post upgrade to Karate 1.1.0, I am facing an error with response code 400. ... 'multipart/form-data' When method post Then status 200.
Read more >
Karate | Test Automation Made Simple.
Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.
Read more >
V1.1.0 - Jsondata in Multipart/formdata header APIs defaults to ...
Version: 1.1.0 Problem Statement: In new version of karate, multipart/formdata header APIs are not working as expected when we send both ...
Read more >
7 New Features in Karate Test Automation Version 1.0
Version 1.0 of the Karate Test Automation Framework is within reach. I checked out the new features, and here are my 7 key...
Read more >
Guidewire PolicyCenter
As a general rule, the custom actions that trigger ... Faults (server-side) An error condition occurred on the server side ... April: 1.1.0....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found