rjv9645

Asynchronous Document Upload

0 votes
Apologies if this is a duplicate. I may have trashed the last thread accidentally. Hello everyone, We've been seeing errors uploading documents asynchronously using jar with dependencies 11.0.2. com.silanis.esl.sdk.EslException: Could not upload document to package. at com.silanis.esl.sdk.service.PackageService.uploadApiDocument(PackageService.java:361) at com.silanis.esl.sdk.service.PackageService.uploadDocument(PackageService.java:344) at com.silanis.esl.sdk.EslClient.uploadDocument(EslClient.java:636) at com.silanis.esl.sdk.EslClient.uploadDocument(EslClient.java:648) Caused by: java.lang.IllegalArgumentException: id parameter cannot be null or empty at com.silanis.esl.sdk.DocumentId.(DocumentId.java:20)
      //Async
      docsToCreate.parallelStream().forEach(doc -> uploadDocument(doc, createdPackage));
      //Sync
      docsToCreate.stream().forEach(doc -> uploadDocument(doc, createdPackage));

  private static void uploadDocument(Document doc, DocumentPackage pack){
    System.out.println(">>> Uploading: " + doc.getName());
    Date starttime = new Date();
    eslClient.uploadDocument(doc, pack.getId());
    Date endPackageBuildTime = new Date();
    System.out.println( "

Note: when using the Synchronous version, all documents upload successfully. I do not believe it is an issue with the package.

Approved Answer

Reply to: Asynchronous Document Upload

0 votes
Unfortunately, there isn't a workaround as this is how the esignlive application is built. The cause behind this that when you too many upload documents are made in a short period of time for the same package, the application is trying to update a row in the database and a race condition occurs due to the number of calls being sent. You can go this route where you upload documents asynchronously but I cannot guarantee it will be successful 100% of the time as few our clients ran into issues and ended reverting to the createPackageOneStep() call. Fair warning has been given here :) As for your error, it seems pretty clear that the the id is empty when doing your document upload call(s).
Haris Haidary OneSpan Technical Consultant

Reply to: Asynchronous Document Upload

1 votes
Hi there, I don't recommend doing asynchronous document uploads as the esignlive application limits the number of requests that can be made for the same package in a short period of time (you will run into issues if you do). What I suggest is to add all your documents in your document package object and use the eslClient.createPackageOneStep() call. This will create a multipart/form-data request and upload all your documents in one request.
Haris Haidary OneSpan Technical Consultant

Reply to: Asynchronous Document Upload

0 votes
Thank you for the response harishaidary, much appreciated. Unfortunately, this does not solve our issue. Currently we experience slow performance from createPackage and createPackageOneStep when package sizes are large (8+ documents). One workaround we see to this is to create the package and obtain the Id first. This way we can perform business functions relating to the package while documents are being uploaded asynchronously. This has a faster response time for clients and overall would have better performance of the system. Is there a way to workaround this 'limit' being placed on the documentPackage?

Reply to: Asynchronous Document Upload

0 votes
Thanks for the quick turn around. I believe the "null" issue is a red herring. The java SDK covers up the actual errors that have occurred during create/upload a. During serialization, the JSON cannot be converted into a pojo if it was an error message. b. Instead, it throws an InvalidArgumentException due to the fact a required field is missing. (See below) In PackageService.java
    public com.silanis.esl.sdk.Document uploadApiDocument( String packageId, String fileName, byte[] fileBytes, Document document ) {
        String path = template.urlFor(UrlTemplate.DOCUMENT_PATH)
                              .replace("{packageId}", packageId)
                              .build();

        String documentJson = Serialization.toJson(document);

        try {
            String response = client.postMultipartFile(path, fileName, fileBytes, documentJson);
             //This will error because failure Json responses won’t be a document.
            com.silanis.esl.api.model.Document uploadedDocument = Serialization.fromJson(response, com.silanis.esl.api.model.Document.class);              return new DocumentConverter(uploadedDocument, getApiPackage(packageId)).toSDKDocument();
        } catch (RequestException e) {
            throw new EslServerException("Could not upload document to package.", e);
        } catch (Exception e) {
          //Creating a new exception here hides the original cause that can be found in the String ‘response’.
            throw new EslException("Could not upload document to package.", e);         }
    }
However, this may be a topic for another thread. I've marked your answer as accepted.

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