0

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.

D. Pesc.
  • 196
  • 15
  • Rule #0 when asking about an exception: POST THE STACK TRACE, and also identify the statement in your code that throws the exception. – Jim Garrison Apr 28 '16 at 15:20

1 Answers1

2

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.
Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
  • i have the same problem, when running wildfly as a service. when running it from the standalone.bat it work normally. – bob-cac Sep 11 '17 at 05:40
  • Have a look at the documentation where running as a service is an extra segment. – Rafael Winterhalter Sep 11 '17 at 05:51
  • running wildfly. not the documents4j. i am using documents4j as a localconverter. where to look? pre thank u – bob-cac Sep 11 '17 at 05:55
  • That does not matter, it is about the user who runs the application. Have a look at documents4j.com where there is a description about what configuration the service user requires. – Rafael Winterhalter Sep 11 '17 at 12:21
  • after adding the folder desktop in the system32 as indicated by documentation. a FileSystemInteractionExcpetion "could not access target file " is thrown. also the MSword is starting in the backend as process and locking the temp resource file – bob-cac Sep 12 '17 at 15:21
  • Did you assign the correct acces rights? The service user must be able to read the file. – Rafael Winterhalter Sep 13 '17 at 04:22
  • yes they are assigned. the service user is the administrator. and the service already creating the temp file on the same directory. the problem is that the output vb script cannot access the target file. note that when running the vb script from windows it converted successfully – bob-cac Sep 13 '17 at 05:24
  • giving access right as the domain administrator not the machine administrator solved the problem. thank a lot rafael – bob-cac Sep 13 '17 at 06:37