ConversionInputException on a complex web application

897 Views Asked by At

I've got this ConversionInputException when I invoke both execute() or schedule() methods on a specific converter.

I think the code it's correct because if I execute the code as a simple java application it work perfectly with the same file as input.

When I deploy the code as a jar and call the code from a complex web application I always had this ConversionInputException.

I've also tried with the InputStream insted of File object but I've got the same exception.

I'm able to open the file with MS-Word without any problem, and I also I'm able to convert it in a standalone java application running the same code.

Here is the code I use

private void convert(File inputFile, File outputFile) {
     boolean conversion=false;
     IConverter converter=com.b80.common.d2.wf.utility.CustomConverter.getInstance().getConverter();
     conversion = converter.convert(inputFile).as(DocumentType.MS_WORD)
                          .to(outputFile).as(DocumentType.PDF)
                          .prioritizeWith(1000).execute();
}

And the converter class it's developed as follows - I had to use synchronized methods because that instance of the converter could be accessed by multiple thread on the server:

import java.io.File;
import java.util.concurrent.TimeUnit;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;

public class CustomConverter {
    private static IConverter converter=null;
    private static final String CONVERSION_FOLDER="E:\\temp\\document4j";

    private static CustomConverter instance = null;
    private CustomConverter() {
      // Exists only to defeat instantiation.
    }
    public static synchronized CustomConverter getInstance() {
      if(instance == null) {
         instance = new CustomConverter();
      } 
      return instance;
   }

    public synchronized IConverter getConverter() {
    if(converter==null || !converter.isOperational()) {
        converter=LocalConverter.builder().baseFolder(new File(CONVERSION_FOLDER)).workerPool(20, 25, 5, TimeUnit.MINUTES)
                .processTimeout(10, TimeUnit.MINUTES)
                .build(); 
    }       
    return converter;
  }
}

Here is the StackTrace, obviously the exception is on the convert() function.

2016-04-28 16:52:21,483 ERROR [STDERR] (http-0.0.0.0-9080-1) com.documents4j.throwables.ConversionInputException: The input file seems to be corrupt
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at com.documents4j.util.Reaction$ConversionInputExceptionBuilder.make(Reaction.java:159)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at com.documents4j.util.Reaction$ExceptionalReaction.apply(Reaction.java:75)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at com.documents4j.conversion.ExternalConverterScriptResult.resolve(ExternalConverterScriptResult.java:70)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at com.documents4j.conversion.ProcessFutureWrapper.evaluateExitValue(ProcessFutureWrapper.java:48)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:36)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:11)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at com.documents4j.job.AbstractFutureWrappingPriorityFuture.run(AbstractFutureWrappingPriorityFuture.java:78)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
2016-04-28 16:52:21,484 ERROR [STDERR] (http-0.0.0.0-9080-1)    at java.lang.Thread.run(Thread.java:662)

I analyzed more deeply the code and added some logs into word_convert.vbs, I obtained an error message like this:

Error # 424 Object required

I know it's a little bit generic message, but I hope it could help a little more.

1

There are 1 best solutions below

8
On

I am the author of documents4j and generally, I think this is a user problem as I have run documents4j successfully from many environments and never encountered such a problem.

It is difficult to say what the problem is as I do not know what exactly it is that makes your web application complex. As the response suggests that your file is corrupt and since the converter does work without the complex part of your application, I assume that you do corrupt the file at some point.

What I can suggest you to try for debugging:

  1. Implement a pseudo converter that only receives the byte array and sends a dummy file back. Check the received bytes to be equal to the bytes of the original file. Maybe you are cutting off some values?
  2. Reduce your application step-by-step to the simple application that works and see what step in the process breaks your premise.