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

ClassCastException Thrown when referring json file in request body with content type "multipart/form-data" #401

Open
srinivasa78 opened this issue Jun 9, 2020 · 7 comments · May be fixed by #435

Comments

@srinivasa78
Copy link

@srinivasa78 srinivasa78 commented Jun 9, 2020

Issue:

With content-type:"multipart/form-data" getting java.lang.ClassCastException when referring json file for additional payload in Request Body apart from "files": [ "file:media/test.wav" ]

Request step:

{
  "name": "save_config",
  "url": "/config",
  "operation": "POST",
  "request": {
    "headers": "${JSON.FILE:standard_headers_media.json}",
    "body": {
      "files": [
        "file:media/test.wav"
      ],
      "metadata": "${JSON.FILE:metadata.json}"
    }
  },
  "assertions": {
    "status": 201,
    "headers": {
      "${correlationId.header}": "$NOT.NULL"
    }
  }
}

metadata.json

{
  "name": "name",
  "fileName": "test.wav",
  "location": "location",
}

standard_headers_media.json:

{
  "Content-Type": "multipart/form-data"
}

Error:

java.lang.RuntimeException: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String
 (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')

Stactrace:

 Caused by: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String
  (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')
	at org.jsmart.zerocode.core.httpclient.utils.FileUploadUtils.buildOtherRequestParams(FileUploadUtils.java:60)
	at org.jsmart.zerocode.core.httpclient.BasicHttpClient.createFileUploadRequestBuilder(BasicHttpClient.java:356)
	at org.jsmart.zerocode.core.httpclient.BasicHttpClient.createRequestBuilder(BasicHttpClient.java:400)
	at org.jsmart.zerocode.core.httpclient.BasicHttpClient.execute(BasicHttpClient.java:126)
	at org.jsmart.zerocode.core.engine.executor.JsonServiceExecutorImpl.executeRESTInternal(JsonServiceExecutorImpl.java:131)
	at org.jsmart.zerocode.core.engine.executor.JsonServiceExecutorImpl.executeRESTService(JsonServiceExecutorImpl.java:92)
@authorjapps
Copy link
Owner

@authorjapps authorjapps commented Jun 9, 2020

@srinivasa78 , just checking...
have you tried this(below replacing the external content) in a manual testing tool or a REST client like Postman?

"body": {
      "files": [
        "file:media/test.wav"
      ],
      "metadata": {
           "name": "name",
           "fileName": "test.wav",
          "location": "location",
       }
    }

What does the API server responds with?

@srinivasa78
Copy link
Author

@srinivasa78 srinivasa78 commented Jun 18, 2020

@authorjapps My apologies for responding late.
Getting 201 Created response.
Please let me know if it's need to be fixed or something. I want to contribute to this project.
And though I got experience this would be my first open source contribution. (I know I know I am too late :) )

@authorjapps
Copy link
Owner

@authorjapps authorjapps commented Jun 20, 2020

Thanks @srinivasa78 for your ineterest in contribution. Yes, you can try to fix this.

The code is here needs fix:

org.jsmart.zerocode.core.httpclient.utils.FileUploadUtils#buildOtherRequestParams

Please raise a PR once it's stable.

Do you know how to fork etc?
Otherwise, here are the guidelines - CONTRIBUTING.md(Click)

Also please join Slack(click to join) channel if you haven't already!

@authorjapps
Copy link
Owner

@authorjapps authorjapps commented Jul 30, 2020

@srinivasa78, did you have a chance to look at it?

@rebugged
Copy link

@rebugged rebugged commented Sep 26, 2020

Forked the repo, started working on this. Will raise PR when build is stable.

@rebugged rebugged linked a pull request Sep 27, 2020 that will close this issue
12 tasks
@rebugged
Copy link

@rebugged rebugged commented Sep 27, 2020

@authorjapps Raised a PR, please let me know if I need to add this specific scenario in the test cases for HTTP.
Check #435

@rebugged
Copy link

@rebugged rebugged commented Oct 4, 2020

@authorjapps reminder! the PR has been pending for a while. Please can you help to merge it.

@authorjapps authorjapps linked a pull request Jan 26, 2021 that will close this issue
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants