Support Article
Pega cannot set filename parameter in multipart request header
SA-69287
Summary
Pega 7.1.5 does not pass both the name and filename parameters in a multipart request header. This occurs when sending a multipart Connect-REST request to a service provider.
When sending a multipart Connect-REST request to a service provider, the name and filename parameters are not set in the multipart request header.
Error Messages
Not Applicable
Steps to Reproduce
- Create a Connect-REST Integration on Pega side to send a multipart attachment request.
- Set the filename parameter in the multipart request header.
Root Cause
A defect in Pegasystems’ code or rules.
In the Pega generated Connect-REST multipart request header, the name and filename parameter values for Content-Disposition header are set based on the pyAttachNames property value in pyRequestAttachmentPage. This pyAttachFileName property is not present in Pega 7.1.5. The property is introduced in later releases to set the filename parameter value for Content-Disposition header of each part.
Resolution
Perform the following local-change to set a different values for the filename parameter and name parameter of the Content-Disposition header:
- Create a ValueList property by name AttachFileNames which applies to the Data-ServiceMessage class.
- In Step 5 of the Rule-Connect-REST.pyInvokeRESTConnector activity, replace the if (attachPage != null) {} block with the below code,
if (attachPage != null)
{
entity = new com.pega.apache.http.entity.mime.MultipartEntity();
ClipboardProperty attachKeys = attachPage.getProperty("pyAttachNames");
ClipboardProperty attachVals = attachPage.getProperty("pyAttachValues");
ClipboardProperty attachTypes = attachPage.getProperty("pyAttachTypes");
ClipboardProperty attachFileNames = attachPage.getIfPresent("AttachFileNames");
int attachCount = attachKeys.size();
if (oLog.isDebugEnabled())
oLog.debug("Adding " + attachCount + " binary attachment(s)");
boolean hasTypes = (attachTypes.size() == attachCount);
java.util.ArrayList partList = new java.util.ArrayList();
if(messageData != null && !"".equals(messageData))
{
((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart("PostData", new com.pega.apache.http.entity.mime.content.StringBody(messageData));
}
for (int i = 1; i <= attachCount; i++)
{
String attachKey = attachKeys.getStringValue(i);
String attachVal = attachVals.getStringValue(i);
String attachType = attachTypes.getStringValue(i);
byte[] buf = Base64Util.decodeToByteArray(attachVal);
String attachFileName = null;
if(attachFileNames!=null) {
attachFileName = attachFileNames.getStringValue(i);
}
if(attachFileName==null || attachFileName.length()==0) {
attachFileName = attachKey;
}
svcUtil.incrementConnectRequestDataVolume(buf.length);
if (attachType != null && !"".equals(attachType))
{
((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart(attachKey, new com.pega.apache.http.entity.mime.content.ByteArrayBody(buf, attachType, attachFileName));
}
else
{
((com.pega.apache.http.entity.mime.MultipartEntity) entity).addPart(attachKey, new com.pega.apache.http.entity.mime.content.ByteArrayBody(buf, attachFileName));
}
}
3. Set the value for the AttachFileNames valuelist property on the pyRequestAttachmentPage to set the filename parameter.
Published March 2, 2019 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.