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 file not being added to request when karate is executed from jar #1650

Closed
david-scott-ie opened this issue Jun 18, 2021 · 8 comments
Assignees

Comments

@david-scott-ie
Copy link

When using multipart file from karate executed from a jar the file content is not added to request

As part of our CICD Process we build out a jar file containing our karate features to run on the deployed code in each envirnment in order to validate the deployment.

We have a test which calls an endpoint to upload a multipart file which runs fine in the IDE.

However when we build the code out to jar and run it form the jar the content of the file is no longer part of the request.

The error we get in the actual test: org.springframework.web.multipart.support.MissingServletRequestPartException

I have attached a sample project which demonstrates this behaviour indirectly (i.e. by showing the content is empty when run from a jar)

Instructions.

unzip the karate-sample.zip file and open up the project in your ide.

Run the file TestApplication as a java app in the IDE.

The output of the test will indicate content:

Mixed: content-disposition: form-data; name="fileUpload"; filename="test.xlsx"
content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8
content-length: 8602
Completed: true
IsInMemory: true

Now run the maven clean install
karate-sample.zip
build, this will build out an executable jar called: sample-test-jar-with-dependencies.jar

Run this as a java jar file: java -jar sample-test-jar-with-dependencies.jar

The output of the test now indicates that the file is empty:

content-disposition: form-data; name="fileUpload"; filename="test.xlsx"
content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8
content-length: 0
Completed: true
IsInMemory: true

From debugging the issue it seems file is not getting set properly in the ReourceUtils when it is a jar resource, whereas it does when it is a file resource therefore the ScenarioFileReader's call here return null:

public File relativePathToFile(String relativePath) {
    return this.toResource(relativePath).getFile();
}

karate-sample.zip

@ptrthomas
Copy link
Member

@david-scott-ie it may take me a while to get to this - but I thought the use of classgraph should have solved all these problems: #751

2 questions: a) which version and b) the moment you are in a JAR you must use classpath: - so are you ?

@david-scott-ie
Copy link
Author

Version is 1.0.1
And yes, using classpath: this is the line in the feature:

And multipart file fileUpload = { read: 'classpath:/excel/test.xlsx', filename: 'test.xlsx', contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }

Note, I did try with and without the leading / both work in IDE but neither in packaged Jar

@ptrthomas ptrthomas self-assigned this Jun 18, 2021
@ptrthomas ptrthomas added the bug label Jun 18, 2021
@ptrthomas ptrthomas added this to the 1.1.0 milestone Jun 18, 2021
@ptrthomas
Copy link
Member

@david-scott-ie really appreciate the sample and instructions ! and your investigation helped. I've made the change so jar resources are grabbed as a byte-stream not a File.

can you test if it works, because this is something near impossible to write a unit-test for: https://github.com/intuit/karate/wiki/Developer-Guide

@david-scott-ie
Copy link
Author

@ptrthomas - yes it works! Thanks for turning that around so quickly.
Pulled the code and built it out locally and plugged it in and both the sample and the actual tests are now uploading the file in the same way in the IDE and when run as a jar.

Thanks again - do you have a date for the next release?

@ptrthomas
Copy link
Member

@david-scott-ie great. we should have 1.1.0.RC4 within a week

@ptrthomas
Copy link
Member

@david-scott-ie 1.1.0.RC4 has been released

@intest
Copy link

intest commented Jun 28, 2021

@ptrthomas File uploading finally works for me with RC4. I'm glad it occurred that it wasn't a problem with my script ;) Thanks for fixing that.

@ptrthomas
Copy link
Member

1.1.0 released

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

3 participants