Skip to main content

Trying to call a REST service from within Uniface code. 

Using the following code. 

			putitem/id v_headers,"X-PCI-Token",<token>
			putitem/id v_headers,"content-type","application/json"
			v_data = $newstruct
			.... some code to build the struct correctly....... 
			structtojson/whitespace  v_content, v_data
			$api$->set_flags(15)
			v_status = $api$->SEND($uri$, "POST", "", "", v_Headers, v_Content, v_Response)

v_headers, v_contact and v_response are all strings. 

I have checked v_content just before the send operation, and it contains correctly formatted JSON. Pasting this JSON into SoapUI activates the far end correctly. 

However, logging on the far end shows blank content when send from uniface. 

Is there any way I can catch/log the output of UHTTP to get the raw data sent to the far end? Or can anyone spot why UHTTP might be clearing the content before sending (bad parsing or something?

Iain

JSON content sample for reference. 

 { 
  "subscription_type" : "company.creation",
  "properties" : { 
   "name" : "St, Vat, Eom, No stdisc. Doc Email",
   "phone" : "+44114201220",
   "address_line_1" : "23 PCI House ims",
   "address_line_2" : "Woodseats Avenue",
   "city" : "Sheffield",
   "county" : "S. Yorkshire",
   "country" : "UK",
   "post_code" : "S8 0TB",
   "company_tier" : ""
 }
}


------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

Trying to call a REST service from within Uniface code. 

Using the following code. 

			putitem/id v_headers,"X-PCI-Token",<token>
			putitem/id v_headers,"content-type","application/json"
			v_data = $newstruct
			.... some code to build the struct correctly....... 
			structtojson/whitespace  v_content, v_data
			$api$->set_flags(15)
			v_status = $api$->SEND($uri$, "POST", "", "", v_Headers, v_Content, v_Response)

v_headers, v_contact and v_response are all strings. 

I have checked v_content just before the send operation, and it contains correctly formatted JSON. Pasting this JSON into SoapUI activates the far end correctly. 

However, logging on the far end shows blank content when send from uniface. 

Is there any way I can catch/log the output of UHTTP to get the raw data sent to the far end? Or can anyone spot why UHTTP might be clearing the content before sending (bad parsing or something?

Iain

JSON content sample for reference. 

 { 
  "subscription_type" : "company.creation",
  "properties" : { 
   "name" : "St, Vat, Eom, No stdisc. Doc Email",
   "phone" : "+44114201220",
   "address_line_1" : "23 PCI House ims",
   "address_line_2" : "Woodseats Avenue",
   "city" : "Sheffield",
   "county" : "S. Yorkshire",
   "country" : "UK",
   "post_code" : "S8 0TB",
   "company_tier" : ""
 }
}


------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

$api$->set_flags(15)
this includes
4  = Do not calculate the content-length of the payload itself for a POST method.

Have you tried set_flags(11).
I usually use set_flags(10) or set_flags(8). But that depends on your environment.



------------------------------
Roger Wallin
Abilita Oy
------------------------------

$api$->set_flags(15)
this includes
4  = Do not calculate the content-length of the payload itself for a POST method.

Have you tried set_flags(11).
I usually use set_flags(10) or set_flags(8). But that depends on your environment.



------------------------------
Roger Wallin
Abilita Oy
------------------------------
If I do, or if I try to calculate and add it manually, I get "Bad Gateway" from the other end.
Regards,
Iain

[cid:image001.jpg@01D9AFF9.9501C920]

[cid:image002.png@01D9AFF9.9501C920][cid:image003.png@01D9AFF9.9501C920] [cid:image004.png@01D9AFF9.9501C920]
Iain Sharp
Head of Technical Services
PCI Systems Ltd., Unit One Acorn Business Park
Woodseats Close, Sheffield S8 0TB
e: isharp@pcisystems.co.uk w: pcisystems.co.uk
t: +44 (0)114 201 2200
Our Partners
[X][X][cid:image005.png@01D9AFF9.9501C920]

[cid:image006.jpg@01D9AFF9.9501C920]

STATEMENT OF CONFIDENTIALITY: This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender immediately and do not copy, distribute or take any action in reliance upon it. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

PCI Systems Limited is a limited company registered in England and Wales with registered number 03336338. Our registered office is at Unit One, Acorn Business Park, Woodseats Close, Sheffield, S8 0TB. Our VAT number is 691 3168 24. PCI Systems Limited is part of the Jonas Group of companies.

If I do, or if I try to calculate and add it manually, I get "Bad Gateway" from the other end.
Regards,
Iain

[cid:image001.jpg@01D9AFF9.9501C920]

[cid:image002.png@01D9AFF9.9501C920][cid:image003.png@01D9AFF9.9501C920] [cid:image004.png@01D9AFF9.9501C920]
Iain Sharp
Head of Technical Services
PCI Systems Ltd., Unit One Acorn Business Park
Woodseats Close, Sheffield S8 0TB
e: isharp@pcisystems.co.uk w: pcisystems.co.uk
t: +44 (0)114 201 2200
Our Partners
[X][X][cid:image005.png@01D9AFF9.9501C920]

[cid:image006.jpg@01D9AFF9.9501C920]

STATEMENT OF CONFIDENTIALITY: This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender immediately and do not copy, distribute or take any action in reliance upon it. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

PCI Systems Limited is a limited company registered in England and Wales with registered number 03336338. Our registered office is at Unit One, Acorn Business Park, Woodseats Close, Sheffield, S8 0TB. Our VAT number is 691 3168 24. PCI Systems Limited is part of the Jonas Group of companies.

And you don't have problems with whitespaces?
Have you tried leaving out  /whitespace in structtojson?



------------------------------
Roger Wallin
Abilita Oy
------------------------------

Trying to call a REST service from within Uniface code. 

Using the following code. 

			putitem/id v_headers,"X-PCI-Token",<token>
			putitem/id v_headers,"content-type","application/json"
			v_data = $newstruct
			.... some code to build the struct correctly....... 
			structtojson/whitespace  v_content, v_data
			$api$->set_flags(15)
			v_status = $api$->SEND($uri$, "POST", "", "", v_Headers, v_Content, v_Response)

v_headers, v_contact and v_response are all strings. 

I have checked v_content just before the send operation, and it contains correctly formatted JSON. Pasting this JSON into SoapUI activates the far end correctly. 

However, logging on the far end shows blank content when send from uniface. 

Is there any way I can catch/log the output of UHTTP to get the raw data sent to the far end? Or can anyone spot why UHTTP might be clearing the content before sending (bad parsing or something?

Iain

JSON content sample for reference. 

 { 
  "subscription_type" : "company.creation",
  "properties" : { 
   "name" : "St, Vat, Eom, No stdisc. Doc Email",
   "phone" : "+44114201220",
   "address_line_1" : "23 PCI House ims",
   "address_line_2" : "Woodseats Avenue",
   "city" : "Sheffield",
   "county" : "S. Yorkshire",
   "country" : "UK",
   "post_code" : "S8 0TB",
   "company_tier" : ""
 }
}


------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

You could add the following to your ASN and check the resulting tracing of the UHTTP component:

[SETTINGS]
$trc_levels=9U
$trc_info=num,cat,lvl
$trc_start=uhttp.trc

This should show you what the content is that is send. E.g.

2;   10U;uhttp> uhttp_send> contents={"authorization_id":"ABC123","..., size=239

If I, however, really want to be sure what is going over the line then I usually use a web debugging tool (like e.g. Fiddler) or a network packet analyzer (like e.g. WireShark).

I hope this helps.



------------------------------
Daniel Iseli
Principal Technical Support Engineer
Uniface Services
Rocket Software, Switzerland
------------------------------

And you don't have problems with whitespaces?
Have you tried leaving out  /whitespace in structtojson?



------------------------------
Roger Wallin
Abilita Oy
------------------------------

The problem started when I didn't have whitespace, I added whitespace in case the other end required prettier JSON. 



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

You could add the following to your ASN and check the resulting tracing of the UHTTP component:

[SETTINGS]
$trc_levels=9U
$trc_info=num,cat,lvl
$trc_start=uhttp.trc

This should show you what the content is that is send. E.g.

2;   10U;uhttp> uhttp_send> contents={"authorization_id":"ABC123","..., size=239

If I, however, really want to be sure what is going over the line then I usually use a web debugging tool (like e.g. Fiddler) or a network packet analyzer (like e.g. WireShark).

I hope this helps.



------------------------------
Daniel Iseli
Principal Technical Support Engineer
Uniface Services
Rocket Software, Switzerland
------------------------------

I will try this and see if it shows me the necessary. 



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

I will try this and see if it shows me the necessary. 



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

Attached are the two outputs with flags set to 10 and 15. One (flags at 15) results in blank contents logged at the other end, the other (10) results in a 502 error from the other end, and I have not yet had feedback as to what is logged. 
Servername changed to protect the (not so) innocent. 



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

Attached are the two outputs with flags set to 10 and 15. One (flags at 15) results in blank contents logged at the other end, the other (10) results in a 502 error from the other end, and I have not yet had feedback as to what is logged. 
Servername changed to protect the (not so) innocent. 



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

It seems that the request is forwarded from:

http://apiserver/webhooks/pci.php

To:

https://apiserver/webhooks/pci.php

I do not think that the content should change when the request is repeated to the new URL. Did you already try if it makes a difference when you call the https URL directly?



------------------------------
Daniel Iseli
Principal Technical Support Engineer
Uniface Services
Rocket Software, Switzerland
------------------------------

It seems that the request is forwarded from:

http://apiserver/webhooks/pci.php

To:

https://apiserver/webhooks/pci.php

I do not think that the content should change when the request is repeated to the new URL. Did you already try if it makes a difference when you call the https URL directly?



------------------------------
Daniel Iseli
Principal Technical Support Engineer
Uniface Services
Rocket Software, Switzerland
------------------------------

And it might also be an idea to try the UHTTP flag 16 (for details see SET_FLAGS). This will disable the redirect and you then can handle each request individually. You just have to check if the SEND operation returned a status in the range of 3xx and then re-send the request with the redirected URL (that should be returned by the first request).

If this works then the content is somehow deleted because of the redirect. I do not think that we have seen this problem before. The redirect normally works (as far as I remember).



------------------------------
Daniel Iseli
Principal Technical Support Engineer
Uniface Services
Rocket Software, Switzerland
------------------------------

It seems that the request is forwarded from:

http://apiserver/webhooks/pci.php

To:

https://apiserver/webhooks/pci.php

I do not think that the content should change when the request is repeated to the new URL. Did you already try if it makes a difference when you call the https URL directly?



------------------------------
Daniel Iseli
Principal Technical Support Engineer
Uniface Services
Rocket Software, Switzerland
------------------------------

Ding, ding. ding. ding! we have a Winner!

I tried the flags at 26 to catch the redirect, and then changed it to call the https: site directly. This worked. I will look at fixing it to catch a new server and repeat loop call resetting the contents. 

I would not expect it to wipe the contents on a redirect though? It seems it does though. 

Regards, 

Iain



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

Ding, ding. ding. ding! we have a Winner!

I tried the flags at 26 to catch the redirect, and then changed it to call the https: site directly. This worked. I will look at fixing it to catch a new server and repeat loop call resetting the contents. 

I would not expect it to wipe the contents on a redirect though? It seems it does though. 

Regards, 

Iain



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

Thanks for sharing this. Good to hear that you have got it working now.

And I did a quick web search and it seems that the 302 code should only be given for a GET method (see here). If another method is used then it apparently is possible that the user-agent changes the method to GET, which probably explains why the content is empty when the redirect is done. It seems that the server should reply with the 307 code (and this should prevent the method change).

Anyway, it probably is safer to use the flag 16 and do the redirect manually. At least then you can be sure what is sent.

I hope this helps.



------------------------------
Daniel Iseli
Principal Technical Support Engineer
Uniface Services
Rocket Software, Switzerland
------------------------------