tmixalis | Posts: 13

Error during downloading the attachment

0 votes
Hello Team, I face an issue, when in my application, I try to download the attached documents, which the customers have uploaded in One Span. Actually it is not happening always, but it is quite often. When the customer is uploading an attachment, after the signing of the contract, this attachment is sent to my application. Then, I try to download and save it. But sometimes, this is the error I get: Error: com.silanis.esl.sdk.EslException: at com.silanis.esl.sdk.io.Files.saveTo(Files.java:30) at com.silanis.esl.sdk.io.Files.saveTo(Files.java:16) at com.ge.cse.minerva.esl.service.ESLDocExchangeService.downloadAttachment(ESLDocExchangeService.java:205) at com.ge.cse.minerva.esl.service.ESLDocExchangeService.downloadAndSaveDocuments(ESLDocExchangeService.java:101) at com.ge.cse.minerva.esl.endpoint.ESLNotificationsEndPoint.processESLNotification(ESLNotificationsEndPoint.java:57) at sun.reflect.GeneratedMethodAccessor1062.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at com.ge.cse.minerva.ui.server.CrossScriptingFilter.doFilter(CrossScriptingFilter.java:31) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:98) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.FileNotFoundException: /appli/MINF/var/www-espacepartenaires-cmcic-leasing-fr.cm-cic.fr/usr/elisa42/application/tmp/hpHHaUoNRWlgACRIpRmKcKWIQ_E=/Carte d'identite Yohann Brusseau 09-01-2_20190109145700.pdf (No such file or directory) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.(FileOutputStream.java:221) at java.io.FileOutputStream.(FileOutputStream.java:171) at com.silanis.esl.sdk.io.Files.saveTo(Files.java:27) ... 50 more The JSon Payload which is sent by OneSpan to my application is: JSON Payload: {"name":"PACKAGE_ATTACHMENT","sessionUser":"customer","packageId":"hpHHaUoNRWlgACRIpRmKcKWIQ_E=","message":"PIECE D'IDENTITE","documentId":""} Could you please advise? Thank you, Michail

Duo_Liang | Posts: 3776

Reply to: Error during downloading the attachment

0 votes
Hi Michail, From the error message "java.io.FileNotFoundException: /appli/MINF/var/www-espacepartenaires-cmcic-leasing-fr.cm-cic.fr/usr/elisa42/application/tmp/hpHHaUoNRWlgACRIpRmKcKWIQ_E=/Carte d’identite Yohann Brusseau 09-01-2_20190109145700.pdf (No such file or directory)" Can we make sure the temporary folder exists by using the code like below:
new File("/appli/MINF/var/www-espacepartenaires-cmcic-leasing-fr.cm-cic.fr/usr/elisa42/application/tmp/hpHHaUoNRWlgACRIpRmKcKWIQ_E=").mkdirs();
Also, since the attachment's file name("Carte d’identite Yohann Brusseau 09-01-2_20190109145700.pdf") was retrieved, I doubt the error was caused by the download failure. Duo

tmixalis | Posts: 13

Reply to: Error during downloading the attachment

0 votes
Hello Duo, Thanks for your answer. I already check in some steps before if the temporary folder exists and if not, I create it. In the same way you suggested. But sometimes I get the error. Regards, Michail

Duo_Liang | Posts: 3776

Reply to: Error during downloading the attachment

0 votes
Hi Michail, For this specific folder "/appli/MINF/var/www-espacepartenaires-cmcic-leasing-fr.cm-cic.fr/usr/elisa42/application/tmp/hpHHaUoNRWlgACRIpRmKcKWIQ_E=" can you console onto the server and find it? If the folder exists, can you run the script in a stand alone application once again and see if the download successful? Duo

tmixalis | Posts: 13

Reply to: Error during downloading the attachment

0 votes
Hi Duo, I have checked and the folder does not exist. But it should, as I check if it exists or not and I create it with the mkdir Regards, Michail

Duo_Liang | Posts: 3776

Reply to: Error during downloading the attachment

0 votes
Hi Michail, Does the code use the "mkdir" vs "mkdirs"? The mkdir() function will only return false when it failed. Duo

tmixalis | Posts: 13

Reply to: Error during downloading the attachment

0 votes
Hello Duo, Yes, the code uses mkdir(). Should I change it to mkdirs()? Regards, Michail

Duo_Liang | Posts: 3776

Reply to: Error during downloading the attachment

0 votes
Hi Michail, There're many articles out there describing the differences between mkdir and mkdirs, for example this stackoverflow post. In order to make sure the folder exists, it's worth a try replacing the function and see whether it resolved the issue. Duo

tmixalis | Posts: 13

Reply to: Error during downloading the attachment

0 votes
Hello Duo, All the directories until /appli/MINF/var/www-espacepartenaires-cmcic-leasing-fr.cm-cic.fr/usr/elisa42/application/tmp exist. They are not created by the application. The application is trying to create only the last directory: hpHHaUoNRWlgACRIpRmKcKWIQ_E= Regards, Michail

tmixalis | Posts: 13

Reply to: Error during downloading the attachment

0 votes

Hello Duo,

The JSON Payload I receive from OneSpan, when it fails, looks like this:

JSON Payload:
{"name":"PACKAGE_ATTACHMENT","sessionUser":"customer","packageId":"hpHHaUoNRWlgACRIpRmKcKWIQ_E=","message":"PIECE D'IDENTITE","documentId":""} 

Could it be that it fails because the documentId is coming as empty?

 

Best Regards,

MIchail


Duo_Liang | Posts: 3776

Reply to: Error during downloading the attachment

0 votes

Hi Michail

 

Below is a raw JSON example sent from server side:

 {"@class":"com.silanis.esl.packages.event.ESLProcessEvent","name":"PACKAGE_ATTACHMENT","sessionUser":"00c0060a-652e-4c06-89eb-9c124d44f2b9","packageId":"njCnHi7iLWeliCxXC2JEErWA2so=","message":"driver license","documentId":null,"createdDate":"2020-01-23T14:42:01.265Z"}

 

It is normal that the "documentId" field is null or handled as empty string, instead of the attachment ID.

 

If you preferred, could you share the code snippets regarding to "parse the callback JSON and download the attachment" here or send to [email protected] so that I can help you analyze the code?

 

Duo


tmixalis | Posts: 13

Reply to:

0 votes

Hello Duo,

Here is the code:

String attachmentType = trimToEmpty(notification.getMessage());
        String attachmentId = null;
        ESLAttachment attachmentDoc = null;
        
        Signer signer = eslClient.getPackageService().getSigner(new PackageId(prospectESignTransaction.getPackageId()), "customer");
        AttachmentRequirement attachment = signer.getAttachmentRequirement(attachmentType);
        attachmentId = null != attachment ? attachment.getId() : null;
        
        RestClient client = new RestClient(prospectESignTransaction.getApiKey());
        String path = MinConstant.ESL_API_URL + "/packages/" + prospectESignTransaction.getPackageId() 
                + "/attachment/" + attachmentId;
        Map<String, Object> responseMap = client.get(path, "application/octet-stream");
        
        if (null != responseMap && null != responseMap.get("responseBody")) {
            String attachmentName = "attachment.pdf";
            CloseableHttpResponse response = (CloseableHttpResponse) responseMap.get("response");
            byte[] byteArray = (byte[]) responseMap.get("responseBody");
            HeaderElement[] headerElements = response.getFirstHeader("Content-Disposition").getElements();
            
            if (null != headerElements && headerElements.length > 0) {
                for (int i=0; i<headerElements.length; i++) {
                    if (null != headerElements[i].getParameterByName("filename")) {
                        attachmentName = headerElements[i].getParameterByName("filename").getValue();
                        break;
                    }
                }
            }
            File dir = new File(tempFolder);
            if (!dir.exists()) {
                dir.mkdir();
            }
            
            List<ESLAttachment> eslAttachments = eslDAO.getAttachmentsForPlatform(prospectESignTransaction.getPlatformId());
            if (CollectionUtils.isNotEmpty(eslAttachments)) {
                for (ESLAttachment eslAttachment : eslAttachments) {
                    if (equalsIgnoreCase(attachmentType, eslAttachment.getName())) {
                        attachmentDoc = eslAttachment;
                        break;
                    }
                }
            }
            
            attachmentName = Normalizer.normalize(attachmentName, Normalizer.Form.NFC).replaceAll("[^\\p{ASCII}]", "");
            
            Files.saveTo(byteArray, tempFolder + File.separator + attachmentName);
            FileUtils.deleteQuietly(dir);            

                }
            }
        }

 

Best Regards,

Michail


Duo_Liang | Posts: 3776

Reply to: Error during downloading the attachment

0 votes

Hi Michail,

 

I tried your code and it works fine at my local machine. (Not exact the same, but I got the idea how you implement the function)

Is the "No such file or directory" error consistent or only happened once? Can you try to save the file at a fixed folder and perform some tests?

 

Duo

 


tmixalis | Posts: 13

Reply to: Error during downloading the attachment

0 votes

Hello Duo,

 

I just tried again with the package id "7ZZM9aLdt2iUPaAU93YTU9T6SPA=".

I pre-checked that the full path and the final directory exists and pushed the JSON Payload via the SOAPUI.

Unfortunately, the error happened again. Attached you can find the JSON which was pushed and the error which was triggered.

 

Best Regards,

Michail


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off