Support Article

HFix-28081 for multipart form-data in REST Connect is partial

SA-31610

Summary



The HFix-28081 was provided to back-port the functionality of Pega 7.21 of multipart form-data in REST Connect.
But when installed and used it it was found the payload is empty and REST Server responded with 500 HTTP error.

Further investigation bring the fact the payload depends from which fields are filled.

For example when only .pyAttachTypes(1) and .pyAttachValues(1) are filled, the request body will be empty.
For when .pyAttachNames(1) and/or .pyAttachFileNames(1) are filled or both – then body has the content.

Also, when user performs Run for test activity having all 4 properties filled as Property-Set step and then try to run the activity again
having only 2 properties set – the body is still generated but contains previous data.


Error Messages



Error messages are present in the Tracer.


Steps to Reproduce



1. Create mock REST Service.
2. Setup TcpMon to be proxy for mock REST Service.
3. Create REST Connect rule pointing the TcpMon to intercept the traffic.
4. Create activity with 2 steps: Property-Set with pyRequestAttachmentPage as Step Page and Connect-REST-Property-Set must have the following:
  • .pyAttachTypes(1) with value "application/json"
  • .pyAttachValues(1) with value "{\"firstname\":\"abcd\" }"


5.Save and trace the Activity RUN and check the TcpMon output, the content looks like below:

POST /api/test HTTP/1.1
Content-Length: 44
Content-Type: multipart/form-data; boundary=cB8aCTHmu_Sak87VuISkC5KcnB_U7Cz7AsJSWs
Host: 127.0.0.1:81
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)

--cB8aCTHmu_Sak87VuISkC5KcnB_U7Cz7AsJSWs--

6. Add the following in Property-Set step:

  • .pyAttachNames(1) with value "testing.here"
  • .pyAttachFileNames(1) with value "some.file.name.txt"

7. Save and Run - see TcpMon output like:

POST /api/test HTTP/1.1
Content-Length: 238
Content-Type: multipart/form-data; boundary=QBIsVYbptrkduEgAgZQvvlGxI_8p_f-M
Host: 127.0.0.1:81
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)

--QBIsVYbptrkduEgAgZQvvlGxI_8p_f-M
Content-Disposition: form-data; name="testing.here"; filename="some.file.name.txt"
Content-Type: application/json
Content-Transfer-Encoding: binary

~*ì¶v¦y¦Ü
--QBIsVYbptrkduEgAgZQvvlGxI_8p_f-M--

7. Now delete these properties added in step 6.
8. Save and Run activity. Observe the same output generated despite the name and file name are not set.


Root Cause



A software use or operation error as pyAttachname,pyAttachValues is mandatory to be set, pyAttachtype and pyAttachFilename are optional.
Also the user need to remove the header encoding from the REST Methods and rely on Activity used to ser required properties to trigger correct boundary.

Resolution



Here’s the explanation for the reported behavior: use mandatory fields and do not set encoding in REST Methods.

In general we have four properties to be set on pyRequestAttachmentPage(Data-ServiceMessage)
The generation of multipart request depends on the four properties which is present in Data-ServiceMessage class
1)pyAttachFileNames
2)pyAttachTypes
3)pyAttachValues
4)pyAttachNames


UseCase-1

Setting all the properties - Generates the following message:

POST / HTTP/1.1
Content-Length: 220
Content-Type: multipart/form-data; boundary=QHdb-kDg6LLU0cJOgInu1ExR_GY95o
Host: xxxxxxxxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)

--QHdb-kDg6LLU0cJOgInu1ExR_GY95o
Content-Disposition: form-data; name="attachname"; filename="santy.txt"
Content-Type: application/json
Content-Transfer-Encoding: binary

?©ž±©í
--QHdb-kDg6LLU0cJOgInu1ExR_GY95o--

Here is the summary of each type
Value of pyAttachTypes is content type –see highlighted in blue
Value of pyAttachNames and pyAttachFileNames is a part of content disposition header-see highlighted text in yellow

Over all content type of the message is multipart/form-data-highlighted in red

Usecase-2
pyAttachTypes is not set - content type of individual part is defaulted to application/octetstream

POST / HTTP/1.1
Content-Length: 248
Content-Type: multipart/form-data; boundary=Qj8f74fBMDunqoRSdJqh38KRUxJIzXMN6hLe2njS
Host: xxxxxxxxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)

--Qj8f74fBMDunqoRSdJqh38KRUxJIzXMN6hLe2njS
Content-Disposition: form-data; name="attachname"; filename="santy.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

ž±©í
--Qj8f74fBMDunqoRSdJqh38KRUxJIzXMN6hLe2njS--



Usecase-3
pyAttachFileNames is not set

pyAttachFileNames is defaulted to pyAttachnames

POST / HTTP/1.1
Content-Length: 229
Content-Type: multipart/form-data; boundary=b4S38RrAPScj8swlzOyPRB79OzD0f6Uxhy
Host: xxxxxxxxxxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)

--b4S38RrAPScj8swlzOyPRB79OzD0f6Uxhy
Content-Disposition: form-data; name="attachname"; filename="attachname"
Content-Type: application/json
Content-Transfer-Encoding: binary

ž±©í
--b4S38RrAPScj8swlzOyPRB79OzD0f6Uxhy--

Usecase-4
pyAttachname and pyAttachFileNames are not set
No data is sent as binary attachment, at least setting pyAttachname is mandatory

POST / HTTP/1.1
Content-Length: 37
Content-Type: multipart/form-data; boundary=q75QKTzvoo0A_ZoTMqSZhaDh3AVQgua
Host: xxxxxxxxxxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.5)

--q75QKTzvoo0A_ZoTMqSZhaDh3AVQgua--

Published December 19, 2016 - Updated January 30, 2017

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.