Question

26
Views
Sonkard5 Member since 2019 3 posts
Infosys Ltd
Posted: October 30, 2019
Last activity: October 30, 2019
Closed

Issue with Pdf attachment to the created cases

Business requirement:

Attaching pdfs to the created cases.

Descriptions: Pega is getting two types of files in the Pega cloud folder location with the same name one is pdf and another one is csv, using the csv files details Pega is creating the case and attaching the pdf of the same name (with only difference in file extension).

Using file listener to reads the csv and create the case, and below is the java code i am using to attach the pdf to the case.

//******

Modifying the csv file as processed by file listener by getting it from Log-Service-File with pdf file extension like TestPdfSample.csv withTestPdfSample.pdf

***//

Observations: 1. The functionalities are working fine and everything is working as expected in Dev environment(case creation and attachment of pdf).

2. The same functionalities are working fine for most of the files in Prod environment, but the pdf attachment is not happening for only very few cases.

I could not figure out the reason of its occurance as it is not that frequent in nature and the same code is working fine for most of the files(includes pdf and csv).

Note: The pdf files are correct only which Pega is getting and tested with the same files(which are causing issues in Production) in Dev env manually, and observed the functionalities are working as expected.

Could anyone help me here with the possible reason of this issue.

//***************************************************************************************************************

Java Code to attach the pdf into the case

byte buffer [] = null;
String strFileData = null;
// FilePath includes file location and file name
String strFilePath = FilePath; (Get the pdf file from Pega cloud server file location like /usr/Abc/TestPdfSample.pdf)
java.io.File fileName = null;
java.io.FileInputStream fos = null;
//read the file into a buffer.
try
{
fileName = new java.io.File(strFilePath);
fos = new java.io.FileInputStream(fileName);
java.io.DataInputStream dis = new java.io.DataInputStream(fos);
buffer = new byte[dis.available()];
dis.readFully(buffer);
}
catch (Exception e)
{
tools.getThread().getThreadPage().putString("pyXMLStream", "Can't continue with file attachment. Can't read File is unreadable."+e.getMessage());
nextBlock = "Err";
}
//encode the file to Base64 so that we can store it on the database
try
{
java.io.ByteArrayInputStream inByteStream = new java.io.ByteArrayInputStream(buffer);
java.io.InputStream inStream = new java.io.BufferedInputStream(inByteStream);
java.io.ByteArrayOutputStream outByteStream = new java.io.ByteArrayOutputStream();
java.io.OutputStream outStream = new java.io.BufferedOutputStream(outByteStream);
java.io.OutputStream encStream = Base64Util.createEncodingOutputStream(outStream);
java.io.DataOutputStream doStream = new java.io.DataOutputStream(encStream);
byte[] buffer2 = new byte[4096];
int len;
while(( len = inStream.read(buffer2)) != -1)
{
doStream.write(buffer2, 0, len);
}
inStream.close();
doStream.flush();
outStream.flush();
doStream.close();
outStream.close();
strFileData = outByteStream.toString();
ClipboardPage cpNFAttach = tools.findPage("AttachmentPage", false);
cpNFAttach.putString("pyAttachStream", strFileData);
cpNFAttach.putString("pxAttachName", FName);// FName is the file name here(like TestPdfSample.pdf)
//cpNFAttach.putString("pyNote", strFilePath);
// close the fos and delete the file
fos.close();
fileName.delete();
}
catch (Exception e)
{
tools.putParamValue("ErrorBuffer", e.toString() + " " + e.getMessage());
nextBlock = "Err";
}
*************************************************************************************************************//

Pega Version:8.1.5 cloud instance

Thanks in Advance

Cloud Services
Moderation Team has archived post
Share this page LinkedIn