VMware Cloud Community
bdamian
Expert
Expert
Jump to solution

HTTP-REST 2.0 - Accept application/json

It seems that the "request.setHeader("Accept","application/json")" is not working with HTTP-REST plugin 2.0.

I've configured an HTTP-REST host pointing to NSX and an Operation to get an Edge using the URL "/api/4.0/edges/{edgeId}". In the "Invoke Operation workflow" I add the following line:

request.setHeader("Accept","application/json")

This is working perfectly find on a vRealize Orchestrator 6.0.3 with HTTP-REST plugin version 1.0.9 and returns a JSON response. But with vRealize Orchestrator 7.0.0 using HTTP-REST plugin version 2.0.0 it returns a XML response.

How can I get the JSON response using version 2.0.0?

Thanks a lot!

D.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
bdamian
Expert
Expert
Jump to solution

I found the answer myself.

Incredibly, with this version, this command doesn't work:

request.setHeader("Accept","application/json")


Instead, I need to use only lowercases:

request.setHeader("accept","application/json")

OMG!

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian

View solution in original post

0 Kudos
5 Replies
bdamian
Expert
Expert
Jump to solution

I found the answer myself.

Incredibly, with this version, this command doesn't work:

request.setHeader("Accept","application/json")


Instead, I need to use only lowercases:

request.setHeader("accept","application/json")

OMG!

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

The problem seems to be that REST plug-in handles request headers in case-sensitive manner. The code responsible for request creation adds a default header 'accept=*/*', and if the user code adds a header like 'Accept=application/json', the request object will end up with 2 headers - accept and Accept. Later, when the code calls Apache httpclient, one of the values will overwrite the other (in your case, */* will overwrite application/json).

I opened a new PR to track this for next release.

0 Kudos
bdamian
Expert
Expert
Jump to solution

The real problem is the backward compatibility. Now I need to change a lot of code.

D.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

I know this is a bit dated and you have identified a work-around, but I want to close the loop on this issue: vRO 7.0.1 just released a couple days ago. From my tests, it appears that this issue has been resolved.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
bdamian
Expert
Expert
Jump to solution

Thanks a lot, Burke, this is a very good news for me.

D.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
0 Kudos