Error during downloading the attachment
Monday, January 13, 2020 at 10:04pmHello 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
Reply to: Error during downloading the attachment
Tuesday, January 14, 2020 at 03:45amReply to: Error during downloading the attachment
Tuesday, January 14, 2020 at 04:10amReply to: Error during downloading the attachment
Tuesday, January 14, 2020 at 04:19amReply to: Error during downloading the attachment
Tuesday, January 14, 2020 at 04:26amReply to: Error during downloading the attachment
Tuesday, January 14, 2020 at 04:38amReply to: Error during downloading the attachment
Tuesday, January 14, 2020 at 08:47pmReply to: Error during downloading the attachment
Wednesday, January 15, 2020 at 08:11amReply to: Error during downloading the attachment
Wednesday, January 15, 2020 at 08:35pmReply to: Error during downloading the attachment
Thursday, January 23, 2020 at 03:06amHello 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
Reply to: Error during downloading the attachment
Thursday, January 23, 2020 at 08:51amHi 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
Reply to: Hi Michail Below is a…
Monday, January 27, 2020 at 02:40amHello 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
Reply to: Error during downloading the attachment
Monday, January 27, 2020 at 11:33amHi 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
Reply to: Hi Michail, I tried your…
Tuesday, January 28, 2020 at 03:01amHello Duo,
The error is not happening always. In most of the cases it works fine.
4-5 times per day, it fails.
Regards,
Michail
Reply to: Error during downloading the attachment
Tuesday, January 28, 2020 at 03:40amHello 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