Open rcoulonv opened 1 month ago
Hi @rcoulonv, thanks for raising this.
Here's an example using Imposter 3.40: example.zip
Testing the mock:
curl -F "text=hello" -F "file1=@text.txt" localhost:8080
The script prints the following in the log:
21:51:09 DEBUG i.g.i.h.AbstractResourceMatcher - Matched resource config for POST http://localhost:8080/
21:51:09 INFO s.56328dc5-ee6f-4fa0-a203-3c5a08e26823_step0_inline - DEBUG - context.request = Request{path='/', method='POST', uri='http://localhost:8080/', pathParams={}, queryParams={}, headers={host=localhost:8080, content-length=511, content-type=multipart/form-data; boundary=------------------------jZ8Y7C3RIWc8uNYBZOocnh, user-agent=curl/8.6.0, accept=*/*}, body=<null>}
21:51:09 INFO s.56328dc5-ee6f-4fa0-a203-3c5a08e26823_step0_inline - DEBUG - context.request.body = null
21:51:09 INFO s.56328dc5-ee6f-4fa0-a203-3c5a08e26823_step0_inline - DEBUG - context.request.formParams = [text:hello]
21:51:09 DEBUG i.g.i.s.s.ScriptedResponseServiceImpl - Executed script '56328dc5-ee6f-4fa0-a203-3c5a08e26823_step0_inline.groovy' for request: POST http://localhost:8080/ in 232.03ms
21:51:09 INFO i.g.i.p.r.RestPluginImpl - Handling object request for: POST http://localhost:8080/
21:51:09 WARN i.g.i.s.ResponseServiceImpl - Response file and data are blank for [d3282636-90fa-4999-92f2-9d9da3f68974] POST http://localhost:8080/
21:51:09 DEBUG i.g.i.s.ResponseServiceImpl - Returning empty response for [d3282636-90fa-4999-92f2-9d9da3f68974] POST http://localhost:8080/
I am using Java jdk-11.0.22 to run imposter-3.22.0.jar --plugin rest
How is it possible to retrieve using a Groovy script the parts of a REST request whose content-type=multipart/form-data ? The Groovy script returns a null body while the content-length=48199 - see below:
Groovy script extract: logger.info "DEBUG - context.request = " + context.request logger.info "DEBUG - context.request.body = " + context.request.body logger.info "DEBUG - context.request.formParams = " + context.request.formParams
Log console extract at execution 10:51:26 INFO s.r.a.s.c.v1 - DEBUG - context.request = Request{path='/myapi', method='POST', uri='http://127.0.0.1:8080/myapi', pathParams={}, queryParams={}, headers={mime-version=1.0, content-length=48199, host=127.0.0.1:8080, content-type=multipart/form-data; boundary="----=_Part_86_1037032677.1716281485976", connection=Keep-Alive, accept-encoding=gzip,deflate,br, user-agent=Apache-HttpClient/4.5.14 (Java/17.0.10)}, body=}
10:51:26 INFO s.r.a.s.c.v1 - DEBUG - context.request.body = null
10:51:26 INFO s.r.a.s.c.v1 - DEBUG - context.request.formParams = [:]
Thanks for your support