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.