I am trying to send a request that has form and multipart params to a spring MVC controller. The problem is that I am getting an error from the server that a required parameter is not present, although I see in the logging that I am sending it.
protected Response doMultiPartPostRequest(Map<String,String> headers, List<Cookie> cookies, String uri, String sessionId,
Map<String,String> formParams, Map<String, File> multiPartParams){
Response response = null;
if(formParams == null){
formParams = new HashMap<>();
}
formParams.put("sid", sessionId);
RequestSpecification specification = given();
if (multiPartParams != null) {
for (Entry<String, File> namePathPair : multiPartParams.entrySet()) {
specification = specification.multiPart(namePathPair.getKey(), namePathPair.getValue());
}
}
if (formParams != null) {
specification = specification.formParams(formParams);
}
if (!isDevEnv()) {
specification = specification.cookies(new Cookies(cookies));
}
response = specification.log().all().sessionId(sessionId).headers(headers).when().post(uri);
response.then().log().all();
return response;
}
Request method: POST
Request params: <none>
Query params: <none>
Form params: deviceID=28d520aec6f84d2fa771316470c60b73
sid=vzt27whgrsxz13i12fwptfyrv
Path params: <none>
Headers: Content-Type=application/json
...
Cookies: JSESSIONID=vzt27whgrsxz13i12fwptfyrv
Body: <none>
HTTP/1.1 400 Required String parameter 'deviceID' is not present
...
com.jayway.restassured.path.json.exception.JsonPathException: Failed to parse the JSON document
at com.jayway.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:876)
at com.jayway.restassured.path.json.JsonPath$4.doParseWith(JsonPath.java:837)
at com.jayway.restassured.path.json.JsonPath$JsonParser.parseWith(JsonPath.java:917)
at com.jayway.restassured.path.json.JsonPath.get(JsonPath.java:182)
at com.jayway.restassured.path.json.JsonPath.getBoolean(JsonPath.java:194)
at com.websense.tsaas.portal.ui.devices.DevicesControllerRESTTest.testCertificateUpdate(DevicesControllerRESTTest.java:663)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized.
at groovy.json.JsonLexer.nextToken(JsonLexer.java:82)
at groovy.json.JsonLexer$nextToken.call(Unknown Source)
at com.jayway.restassured.internal.path.json.ConfigurableJsonSlurper.parse(ConfigurableJsonSlurper.groovy:99)
at com.jayway.restassured.internal.path.json.ConfigurableJsonSlurper$parse.callCurrent(Unknown Source)
at com.jayway.restassured.internal.path.json.ConfigurableJsonSlurper.parseText(ConfigurableJsonSlurper.groovy:85)
at com.jayway.restassured.path.json.JsonPath$4$1.method(JsonPath.java:839)
at com.jayway.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:874)
... 26 more
Thanks in advance...