Code works for normal files but not working on encrypted files

Hi,

I am trying to customize the groupdocs viewer code using CustomInputDataHandler class.I am using groupdocs-viewer-spring-slim( 2.5.0) version.

Objective:
Physical documents are encrypted,need to decrypt while showing on group docs
viewer.

Error:
Code works for normal files but not working on encrypted files
Shows “Exception” on groupDocs viewer. Can we check those exception on console?? Or how we can debug the exception?? Or any other way for achieving our objective??

check the below code snippet.
=====================

public InputStream getFile(String guid) {

try {
//decryption code

CipherInputStream cipherInputStream=new CipherInputStream(

fileInputStream,
cipher);

return cipherInputStream;

} catch (Exception e){
return null;
}
}

Hello Mehul,

Thank you for interest in the GroupDocs.

Sorry to see you get a problem. First, I encourage you to use the latest GroupDocs.Viewer for Java library available – the 2.8.0 version at the moment (http://groupdocs.com/Community/files/9/java-libraries/groupdocs_viewer_for_java/default.aspx), because we do not support previous versions.

You can check the exception when running the sample in the debug mode. Just place breakpoint in the InputDataHandler implementation methods and see where it occurs.

The InputDataHandler implementation to work correctly should provide as well the file description info. You need to implement the getFileDescription method except the getFile one.

Please, check if you correctly implemented all parts. If you still will have some problems, please provide us your or some test file so we can investigate your situation.

Hello,

Thanks for your reply.

As you mentioned I have downloaded the java library of 2.8.0 version from the provided link.

For test purpose I provided a path of file to view method.

viewerHandler = new ViewerHandler(config);

It is working fine.

Now while customizing using CustomInputDataHandler, we initialized the viewHandler as below,

viewerHandler = new ViewerHandler(config, new CustomInputDataHandler(config));

Then its not working properly,
Our debug results are:
In below function,

public GroupDocsFileDescription getFileDescription(String guid)

The parameter guid is not as per in FileMap.

example:
fileMap: {bvvb==x.png}
guid===>> b (b is nothing but the folder inside the temp folder of our file path)

How to solve this issue???



Strange, Mehul, just checked the sample again and on my side it runs ok with the changes you mentioned. I would ask you to archive all your project and attach to your post here so we can check it.

Guid - is the generated ID of the file. Actually there can be anything you want. But you should keep in mind that this value is transferred to the client JavaScript.
In the sample it is formed in the index method of the HomeController for the first file.
For other files (which are handled through the file tree dialog) guids are retrieved from the InputDataHandler.

As per our discussion please find the attachment below.
The attachment consist of the archive sample of my project without lib folder.

I am using,

OS: Windows 8,
Java: 1.7.0,
Maven: 3.2.3,
Servlet-container: Apache tomcat 7.0

Hello Mehul,

Thank you for the provided project. We’ve examined it and found few significant issues:
  1. pom.xml file is incorrectly formed (probably because of the copy-paste typo) – you need to remove the duplicate build section and make sure the xml structure is formed correctly
  2. I see you hard-coded some guids in the CustomInputDataHandler. I’ve changed it back to the original sample. These should be generic to function correctly.

As from your last chat contact we’ve understand that you are getting problems with loading files through GET parameters, like “http://localhost:8080/document-viewer?file=Document.pdf”.

This problem is caused by the difference of the file name encoding in the CustomInputDataHandler (when filling fileMap) and in the index (“/view”) HTTP handler. You can easily fix it just by changing the index method of the HomeController to set the initialFilePath like in the CustomInputDataHandler:
String initialFilePath = Base64.encodeBase64String(file.getBytes());

Hello,

Thank you for your response.

We made the changes as you mentioned in above post. Now its working fine.
Thanks for your co-operation.


Hello Mehul,

You are welcome! We are happy that things work for you. Feel free to contact us in case of need.