复杂的Web应用程序上的ConversionInputException [英] ConversionInputException on a complex web application

查看:153
本文介绍了复杂的Web应用程序上的ConversionInputException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在特定的转换器上调用 execute() schedule()方法时,我得到了 ConversionInputException .

我认为代码是正确的,因为如果我将代码作为一个简单的Java应用程序执行,那么它可以与输入相同的文件完美地工作.

当我将代码部署为jar并从复杂的Web应用程序中调用代码时,我总是会遇到此 ConversionInputException .

我也尝试在File对象的 InputStream 中插入,但是我遇到了同样的异常.

我可以使用MS-Word打开文件,没有任何问题,而且我还可以在运行相同代码的独立Java应用程序中对其进行转换.

这是我使用的代码

  private void convert(File inputFile,File outputFile){布尔值转换=假;IConverter converter = com.b80.common.d2.wf.utility.CustomConverter.getInstance().getConverter();转换= converter.convert(inputFile).as(DocumentType.MS_WORD).to(outputFile).as(DocumentType.PDF).prioritizeWith(1000).execute();} 

其转换器类的开发如下:我必须使用同步方法,因为可以通过服务器上的多个线程访问该转换器的实例:

  import java.io.File;导入java.util.concurrent.TimeUnit;导入com.documents4j.api.IConverter;导入com.documents4j.job.LocalConverter;公共类CustomConverter {私有静态IConverter转换器= null;私有静态最终字符串CONVERSION_FOLDER ="E:\\ temp \\ document4j";私有静态CustomConverter实例= null;私人CustomConverter(){//仅存在以击败实例化.}公共静态同步的CustomConverter getInstance(){if(instance == null){实例=新的CustomConverter();}返回实例;}公开同步的IConverter getConverter(){if(converter == null ||!converter.isOperational()){converter = LocalConverter.builder().baseFolder(新文件(CONVERSION_FOLDER)).workerPool(20,25,5,TimeUnit.MINUTES).processTimeout(10,TimeUnit.MINUTES).建造();}返回转换器}} 

这里是StackTrace,显然是 convert()函数上的例外.

  2016-04-28 16:52:21,483错误[STDERR](http-0.0.0.0-9080-1)com.documents4j.throwables.ConversionInputException:输入文件似乎已损坏2016-04-28 16:52:21,484在com.documents4j.util.Reaction $ ConversionInputExceptionBuilder.make(Reaction.java:159)时发生[STDERR]错误(http-0.0.0.0-9080-1)2016-04-28 16:52:21,484在com.documents4j.util.Reaction $ ExceptionalReaction.apply(Reaction.java:75)时发生[STDERR]错误(http-0.0.0.0-9080-1)2016-04-28 16:52:21,484在com.documents4j.conversion.ExternalConverterScriptResult.resolve(ExternalConverterScriptResult.java:70)上出现[STDERR]错误(http-0.0.0.0-9080-1)2016-04-28 16:52:21,484在com.documents4j.conversion.ProcessFutureWrapper.evaluateExitValue(ProcessFutureWrapper.java:48)上出现[STDERR]错误(http-0.0.0.0-9080-1)2016-04-28 16:52:21,484在com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:36)上出现[STDERR]错误(http-0.0.0.0-9080-1)2016-04-28 16:52:21,484在com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:11)​​上出现[STDERR]错误(http-0.0.0.0-9080-1)2016-04-28 16:52:21,484在com.documents4j.job.AbstractFutureWrappingPriorityFuture.run(AbstractFutureWrappingPriorityFuture.java:78)上出现[STDERR](http-0.0.0.0-9080-1)错误2016-04-28 16:52:21,484在java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886)出现[STDERR](http-0.0.0.0-9080-1)错误2016-04-28 16:52:21,484在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908)出现[STDERR](http-0.0.0.0-9080-1)错误2016-04-28 16:52:21,484错误[STDERR](http-0.0.0.0-9080-1)at java.lang.Thread.run(Thread.java:662) 

我对代码进行了更深入的分析,并将一些日志添加到word_convert.vbs中,获得了如下错误消息:

 错误#424需要对象 

我知道这是一些通用信息,但我希望它可以有所帮助.

解决方案

我是documents4j的作者,通常,我认为这是一个用户问题,因为我已经在许多环境中成功运行了document4j,并且从未遇到过这样的问题./p>

很难说是什么问题,因为我不知道到底是什么使您的Web应用程序变得复杂.由于响应表明您的文件已损坏,并且由于转换器在没有应用程序的 complex 部分的情况下也可以正常工作,因此我认为您确实在某个时刻损坏了文件.

我可以建议您尝试进行调试的内容:

  1. 实现一个伪转换器,该伪转换器仅接收字节数组并向后发送一个伪文件.检查接收到的字节等于原始文件的字节.也许您切断了一些价值?
  2. 将您的应用程序逐步简化为可以运行的简单应用程序,并查看该过程中的哪一步破坏了您的前提.

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.

解决方案

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.

这篇关于复杂的Web应用程序上的ConversionInputException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆