Support Article
After restart, images no longer appear in correspondence
SA-34447
Summary
There are number of images that are used on email correspondences in the application.
Whenever the environment is restarted, the images can still be seen in the correspondence rule.
However when the email is actually sent, the images are not shown on the email.
Error Messages
Not Applicable
Steps to Reproduce
- Restart an environment, and send an email using the correspondence with linked images.
- Observe that the email will not include the images (displays an x symbol).
- Save the binary files, and send the email again. The images then appear.
Root Cause
A defect in Pegasystems’ code or rules.
The Image Content rules created when uploading Images to correspondence rules, also saves the image binary data into StaticContent folder.
Restart of Pega server with PegaRULES_Extract_Marker file delete also deletes the StaticContent directory. and subsequent runs of corresponding rules does not find the image data.
Resolution
Perform the following local-change steps:
- Save-as @baseclass.SendEmailNotification (Pega-EventProcessing:07-10-09) activity to your application ruleset and add a new Java Step 2.
- Paste the following code into the new activity java step.
// Local change to address linked images static content issues
// replace. .. src="https://community.pega.com/file"...> with ... src="cid:file"... >
String imgExp = "((<[iI][mM][gG][\\s\\S]*?)|([iI][mM][aA][gG][eE][dD][aA][tT][aA][\\s\\S]*?))((\\s[sS][rR][cC])(\\s*=\\s*[\"|']))(\\S+)([\"|'][\\s\\S]*?>)";
java.util.regex.Pattern referencePattern = java.util.regex.Pattern.compile(imgExp);
java.util.regex.Matcher match = referencePattern.matcher(Message);
StringBuffer updatedMarkup = new StringBuffer(Message.length() + 1024);
while (match.find()) {
String originalURL = match.group(7);
// avoid references to remote images, i.e. that don't have http://,
// ftp:// in them
if (originalURL.indexOf(":") == -1) {
boolean fileExists = true;
PRFile prfile = null;
// if (!filesInZip.contains(originalURL)) {
try {
// https://gcsprdsa.lab.pega.com/articles/datacontent/Image/rteImages/avatar1487791223164.png
prfile = pega.getStaticContentUtils().getResolvedFile(originalURL);
} catch (java.io.IOException e) {
fileExists = false;
}
if (prfile == null) {
fileExists = false;
}
if (!fileExists) {
String dcImagePath = "/datacontent/Image/";
int beginIndex = originalURL.indexOf(dcImagePath);
int endIndex = originalURL.lastIndexOf("/");
String filePath = originalURL.substring(beginIndex + dcImagePath.length() - 1, endIndex + 1);
String fileName = originalURL.substring(originalURL.lastIndexOf("/") + 1, originalURL.lastIndexOf("."));
String fileExt = originalURL.substring(originalURL.lastIndexOf(".") + 1);
ClipboardPage cpResult = null;
HashStringMap hsmKeys = new HashStringMap();
hsmKeys.putString("pxObjClass", "Data-Content-Image");
hsmKeys.putString("pyFileName", fileName);
hsmKeys.putString("pyFileType", fileExt);
hsmKeys.putString("pyFilePath", filePath);
oLog.infoForced("Open Image Content rule - filePath:" + filePath + " fileName:" + fileName + " fileExt:"+ fileExt);
try {
PRThread thread = (PRThread) ThreadContainer.get();
Database db = (Database) thread.getDatabase();
cpResult = db.open(hsmKeys, false);
} catch (DatabaseException dbEx) {
oLog.error("Database Exception reading Data-Content-Image instance from database :"
+ dbEx.getMessage(), dbEx);
}
if (cpResult != null) {
String pyFileSource = cpResult.getString("pyFileSource");
String aFilePath = "file://web:/StaticContent" + originalURL.substring(2);
boolean isSucces = false;
com.pega.pegarules.priv.util.HTTPPrepOutputStream hposExtracted = null;
try {
hposExtracted = new com.pega.pegarules.priv.util.HTTPPrepOutputStream(new PRFile(aFilePath),
false, false);
byte buffer[] = null;
try {
String sFileContent = pyFileSource;
byte bContent[] = null;
int nContentLength;
if (hsmKeys.getString("pxObjClass").equals("Data-Content-Image")) {
bContent = Base64Util.decode(sFileContent.getBytes("UTF-8"));
nContentLength = bContent.length;
} else {
bContent = sFileContent.getBytes("UTF-8");
nContentLength = bContent.length + PRFileUtil.UTF8_BOM.length;
buffer = com.pega.pegarules.priv.factory.ByteArrayFactory.acquire(nContentLength);
buffer[0] = PRFileUtil.UTF8_BOM[0];
buffer[1] = PRFileUtil.UTF8_BOM[1];
buffer[2] = PRFileUtil.UTF8_BOM[2];
System.arraycopy(bContent, 0, buffer, PRFileUtil.UTF8_BOM.length, bContent.length);
bContent = buffer;
}
hposExtracted.write(bContent, 0, nContentLength);
isSucces = true;
} catch (Exception ioEx) {
String sErrorMsg = StringUtils.concat(StringUtils.ASIS, "Error while writing ", ioEx,
"\n", ioEx.getMessage());
oLog.error(sErrorMsg);
if (hposExtracted != null) {
hposExtracted.cleanupAfterFailure();
}
isSucces = false;
} finally {
if (buffer != null) {
com.pega.pegarules.priv.factory.ByteArrayFactory.release(buffer);
}
}
if (isSucces) {
hposExtracted.close();
} else {
if (oLog.isDebugEnabled()) {
oLog.debug(StringUtils.concat(StringUtils.ASIS, "Error while writing ", aFilePath));
}
hposExtracted.cleanupAfterFailure();
}
} catch (Exception ioEx) {
String sErrorMsg = StringUtils.concat(StringUtils.ASIS, "Error while writing ", ioEx, "\n",
ioEx.getMessage());
oLog.error(sErrorMsg);
if (hposExtracted != null) {
hposExtracted.cleanupAfterFailure();
}
} finally {
}
}
}
}
}
Published March 16, 2017 - 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.