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();
svcUtil.incrementConnectRequestDataVolume(mData.length);
}
//generate request content from the stream
com.pega.apache.http.HttpEntity entity = null;
//attachment code
if (attachPage != null)
{
// ...
}
else
{
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 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();
svcUtil.incrementConnectRequestDataVolume(mData.length);
}
//generate request content from the stream
com.pega.apache.http.HttpEntity entity = null;
//attachment code
if (attachPage != null)
{
// ...
}
else
{
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?
ClipboardProperty contentProp = myStepPage.getProperty(".request.Content");
String base64Content = tools.getParameterPage().getString("FileContent");
contentProp.setValue(new String(Base64Util.decodeToByteArray(base64Content)));
**Moderation Team has archived post**
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.