[英]ConversionInputException on a complex web application
I've got this ConversionInputException
when I invoke both execute()
or schedule()
methods on a specific converter. 当我在特定的转换器上调用execute()
或schedule()
方法时,就遇到了ConversionInputException
。
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. 我认为代码是正确的,因为如果我将代码作为简单的Java应用程序执行,则可以与输入相同的文件完美地工作。
When I deploy the code as a jar and call the code from a complex web application I always had this ConversionInputException
. 当我将代码部署为jar并从复杂的Web应用程序调用代码时,我始终会遇到此ConversionInputException
。
I've also tried with the InputStream
insted of File object but I've got the same exception. 我也尝试用File对象的InputStream
插入,但是有相同的异常。
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. 我可以用MS-Word打开文件,没有任何问题,而且我还可以在运行相同代码的独立Java应用程序中对其进行转换。
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. 这是StackTrace,显然在convert()
函数上是例外。
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: 我对代码进行了更深入的分析,并将一些日志添加到word_convert.vbs中,获得了如下错误消息:
Error # 424 Object required
I know it's a little bit generic message, but I hope it could help a little more. 我知道这是一些通用信息,但我希望它可以有所帮助。
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. 我是documents4j的作者,通常,我认为这是一个用户问题,因为我已经在许多环境中成功运行documents4j,并且从未遇到过此类问题。
It is difficult to say what the problem is as I do not know what exactly it is that makes your web application complex . 很难说是什么问题,因为我不知道到底是什么使您的Web应用程序变得复杂 。 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: 我可以建议您尝试调试的内容:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.