Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multipart request fails randomly #1933

Closed
rsmaan4u8 opened this issue Mar 3, 2022 · 8 comments
Closed

multipart request fails randomly #1933

rsmaan4u8 opened this issue Mar 3, 2022 · 8 comments

Comments

@rsmaan4u8
Copy link
Contributor

rsmaan4u8 commented Mar 3, 2022

I initially asked this question on stack overflow Stack Overflow and I was advised to submit issue with working example.

In my tests I am using multipart requests as below . This test is hitting springboot endpoint and if I run the test repeatedly sometimes I get 500 response.

  Scenario: multipart test
    And def f1 = '<http://example1.com/Thing>  <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>  <http://www.w3.org/2002/07/owl#Class>.'
    And def f2 = '<http://example2.com/Thing>  <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>  <http://www.w3.org/2002/07/owl#Class>.'
    And multipart file files = { value: "#(f1)", filename: "org-emp-img.ttl", contentType: 'text/turtle' }
    And multipart file files = { value: "#(f2)", filename: "prefix-only.ttl" , contentType: 'text/turtle'}
    And multipart field baseIRIForData = 'http://example.com/'
    And multipart field baseIRIForSchema = 'http://example.com/'
    And multipart field defaultLanguageCode = 'en'
    And multipart field enableDataReset = 'YES'
    And multipart field idSetup = 'readOnly'
    And multipart field dryRun = 'true'
    And multipart field existingConfiguration = 'wipe'
    And path path
    When method post

    Then status 200

The error which I see on the server side is

2022-03-02 22:38:32.466 ERROR 29771 --- [io-8080-exec-10] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: The length of a boundary token cannot be changed] with root cause

org.apache.tomcat.util.http.fileupload.MultipartStream$IllegalBoundaryException: The length of a boundary token cannot be changed

I am not sure if it is defo issue on Karate side but it might be the case that Karate is not setting content length or boundry correctly which is causing server side error.

A minimal example to reproduce the issue can be downloaded below. Please note this example is based on Spring Boot Example from karate documentation.

hello-karate-master.zip

After downloading start spring boot application by running below in terminal

mvn spring-boot:run

and to run the test run below in another terminal

mvn test -Dtest=TestRunner
@ptrthomas
Copy link
Member

tagging as help wanted. see if you can contribute code, else this may take time.

@rsmaan4u8
Copy link
Contributor Author

I have done some debugging and will continue to look into it. But no luck yet. Any pointers where I should focus?

@ptrthomas
Copy link
Member

@rsmaan4u8 note that ideally you should follow the instructions here EXACTLY: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue - this is not a "minimal" POM. if it is simpler for us to run, resolution can be quicker

@ptrthomas
Copy link
Member

@rsmaan4u8 sorry no pointers come to my mind at this time

@rsmaan4u8
Copy link
Contributor Author

@rsmaan4u8 note that ideally you should follow the instructions here EXACTLY: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue - this is not a "minimal" POM. if it is simpler for us to run, resolution can be quicker

@ptrthomas Sorry I should have removed the extra deps. I have now removed those and updated the zip link.

@ptrthomas
Copy link
Member

@rsmaan4u8 a suggestion - if you follow the write-up here, you will be able to create a Karate mock that handles the file upload: #1645 (comment)

if you can get that working with your test, you will be able to prove whether it is a problem with Karate or the spring boot side / your code

@rsmaan4u8
Copy link
Contributor Author

@ptrthomas thanks for pointer. I did what is suggested in the write-up and it works. So maybe a bug on spring boot side.

@ptrthomas
Copy link
Member

@rsmaan4u8 thanks for the update ! closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants