Ask a Question

ReadyAPI is not reading a json file

SOLVED
abirHajali
Occasional Contributor

ReadyAPI is not reading a json file

I have a post request in which i attach two files, the first one must be a json file.

Using postman, the api works fine but using soap ui it seems like it's not reading the right format.

How is it possible ?

abirHajali_0-1606724797294.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Khouloud
New Member

Re: Soap ui (free version) is not reading a json file

Hello @abirHajali,

Your Content-type in both parts are not well sended

Instead of Content-Type: application/json; name=***.json you should send Content-Type: application/json;

My advice is to modify your request and correct Content-type, the way to do it is to use Event handlers (Filtering requests)

Use: RequestFilter.filterRequest to modify request before sending, this script aim to retreive and enter the correct Content-type

def bodyPartAttach = context.getProperty("httpMethod").requestEntity.message.content.getBodyPart(0) // get a part by number, it starts with 0
bodyPartAttach.removeHeader("Content-Type")
bodyPartAttach.addHeader("Content-Type", "application/json")

 

Do the same with the second part (index = 1)

 

 

 

 

 

View solution in original post

7 REPLIES 7
richie
Community Hero

Re: Soap ui (free version) is not reading a json file

Hey @abirHajali,

I have this a lot where the request works fine in postman, but doesnt in readyapi! or soapui. You gotta remember postman doesnt include all the functionality that soapui and readyapi! include to allow the user to tailor their requests....thats why i think this occurs so much.

What i do in this situation is i use Fiddler to proxy the requests. Fiddler is a tool that extracts all the RAW content from any tool that uses it as a proxy and allows you to compare the difference between what soapui sends and what postman sends. This then allows you to make the appropriate changes in soapui to get it to work.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
ZDGN
Contributor

Re: Soap ui (free version) is not reading a json file

Hi @abirHajali,

 

Did you fill the "Attachments" part of your POST request ?

ZDGN_0-1607087020334.png

Be aware that SoapUI will automatically fill in the "Content type" field, and it should be changed for a json file.
You can also have a look at the documentation page:
https://www.soapui.org/docs/soap-and-wsdl/attachments/ 

 

David.

abirHajali
Occasional Contributor

Re: Soap ui (free version) is not reading a json file

Hello @ZDGN ,

This is exactly what i did.

Still having the same error.

abirHajali_0-1608029368725.png

 

Thanks for your help ! 

abirHajali
Occasional Contributor

Re: Soap ui (free version) is not reading a json file

Update :

 

Hello @richie ,

Thanks for the recommandatipn. Fiddler is a great tool.

But still couldn't find the right solution, can you tell the diffrence please :

 

ReadyAPI request (we upgraded)

POST ****** HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/form-data; boundary="----=_Part_0_1896884270.1608028565346"
MIME-Version: 1.0
vaapiuser: ***
Content-Length: 96806
Host: ***
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/15)


------=_Part
Content-Type: application/json; name=***.json
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="***.json"; filename="***.json"

{"documents":
[
{***
]
}
------=_Part
Content-Type: application/pdf; name=test.pdf
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="test.pdf"; filename="test.pdf"

%PDF-1.3
................................................................

 

Response

{"status":"ERROR","message":"\"Error in document #1 - [DM_SYSOBJECT_E_NO_CONTENT_TYPE]error: \\\"No content type specified for DA sysobject.\\\"\"","documentIds":null}

 

Postman Request

POST **** HTTP/1.1
vaapiuser: *****
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Postman-Token: 6a419ee7-dfca-4543-834e-cdc23e6ca78c
Host: ***
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------264662573644671205416351
Content-Length: 96673

----------------------------
Content-Disposition: form-data; name=""; filename="***.json"
Content-Type: application/json

{"documents":
[
***]
}
----------------------------
Content-Disposition: form-data; name=""; filename="test.pdf"
Content-Type: application/pdf

%PDF-1.3
......................................................................

 

Response

{"status":"OK","message":"Document(s) have been tasklisted in ***.","documentIds":["***"]}

 

Thanks for your help !

Khouloud
New Member

Re: Soap ui (free version) is not reading a json file

Hello @abirHajali,

Your Content-type in both parts are not well sended

Instead of Content-Type: application/json; name=***.json you should send Content-Type: application/json;

My advice is to modify your request and correct Content-type, the way to do it is to use Event handlers (Filtering requests)

Use: RequestFilter.filterRequest to modify request before sending, this script aim to retreive and enter the correct Content-type

def bodyPartAttach = context.getProperty("httpMethod").requestEntity.message.content.getBodyPart(0) // get a part by number, it starts with 0
bodyPartAttach.removeHeader("Content-Type")
bodyPartAttach.addHeader("Content-Type", "application/json")

 

Do the same with the second part (index = 1)

 

 

 

 

 

View solution in original post

richie
Community Hero

Re: Soap ui (free version) is not reading a json file

Sorry. Post submitted in error

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Digitalneo
Regular Visitor

Re: Soap ui (free version) is not reading a json file

Having just ran into this scenario, this is what we did based on the solution provided here:

Note: assumes first attachment is the JSON and the Test Step Name is "Post - Documents"

def currentStep = context.getCurrentStep().name

if (currentStep == "Post - Documents") {

	def bodyPartAttach = context.getProperty("httpMethod").requestEntity.message.content.getBodyPart(0) // get a part by number, it starts with 0
	bodyPartAttach.removeHeader("Content-Type")
	bodyPartAttach.addHeader("Content-Type", "application/json")
}
cancel
Showing results for 
Search instead for 
Did you mean: