Posted: 8 Jul 2016 11:30 EDT Last activity: 4 Oct 2018 13:54 EDT
Sending binary message body in Connect REST
I am connecting to a REST service that accepts a binary file as the message body, and I'm trying to setup my Connect REST invocation. I'm aware of using pyRequestAttachmentPage of class Data-ServiceMessage to send binary attachments, but this sends a multipart form message in the POST which is not what I want. Looking at Rule-Connect-REST.pyInvokeRESTConnector, it appears to read the referenced message body clipboard property as a String and then convert it to bytes.
byte mData = null;
if (paramMapFrom.length() != 0 || attachPage != null)
//get the only member of the reqMessageData map and put it as a stream
if (paramMapFrom.length() != 0)
messageData = (String) reqMessageData.get(paramName);
mData = messageData.getBytes();
//generate request content from the stream
com.pega.apache.http.HttpEntity entity = null;
if (attachPage != null)
entity = new com.pega.apache.http.entity.ByteArrayEntity(mData);
I've tried multiple ways to store the binary data on the clipboard, but I end up with a corrupted file after the service is invoked. Any suggestions?
I'm using Pega 7.1.5, although I just checked 7.1.9 and this activity does not appear to have changed much. Perhaps a future enhancement to allow the developer to indicate that the message body is binary and text-based content?
We are currently facing the same situation and Mapping a Java Object with the binary data as a Byte array throws an exception in Rule-Connect-REST.Invoke "Object value is not an instance of String".
Here´s how the configuration of the rules look like.
Java Object Property
Config on the REST Connector Rule
Activity with custom Java code to transform the Base64 encoded file from pyFileSource to byte Array (this ir run before calling the rest connector)
The only way to make it work is to send the Base64 encoded pyFileSource string as the Message body, and made the change mentioned above on Rule-Connect-REST.pyInvokeRESTConnector. We are currently working with PEGA 7.1.8
Please have a look at the Pega Storage API data page, D_pxCreateFile, for an example of how to work with a multipart/form-data request body. In particular, see the request data transform, Pega-Int-Storage-Box.pzCreateFileRequest. This DT uses a supported way to upload binary data. Note, the binary data must be in the form of a Base64 encoded String value.
As Chad points out above (good eye), as of 7.2.1, we do not directly support binary request bodies. However, we have made changes in 7.2.2 to add this support.
For our specific scenario, the Service were we are connecting, would not take multipart/form-data as a valid request. It is waiting for the Request Body to be the binary data, and it will simply not accept the request if it's send attached or as multipart/form-data.
This is mainly a problem with the service and not with pega, but client service has been programmed that way and there are many applications using it so it cannot be change.
It is good to hear that for v 7.2.2 the binary body will be added, but our only solution at the moment is to make the local change on pyInvokeRestConnector.