documents4j / documents4j

documents4j is a Java library for converting documents into another document format
http://documents4j.com
Apache License 2.0
555 stars 144 forks source link

Is there a timeout for the documents-4j-server-standalone due to inactivity? #45

Closed tadeubonatti closed 7 years ago

tadeubonatti commented 7 years ago

Hello,

Is there a timeout for the documents-4j-server-standalone due to inactivity? I've used the server normally for a few times, but after a few hours without use it, the server goes down (operational "false"), and I don't know why. The server throws FileSystemInteractionException, but it doens't make any sense for me, the system did the same request, with same file, more than once few hours ago. After then, I restart server and it works.

I've read the documentation but I haven't found any information about this. Can you help me?

How I get the remote converter (I only create one instance in the context with a Factory): RemoteConverter.builder().workerPool(20, 25, 20, TimeUnit.SECONDS).requestTimeout(20, TimeUnit.SECONDS).baseUri(baseUri).build();

How I convert:

private void convertByDocuments4j(File fileToConvert, File newFile) throws IOException {
    try (InputStream fileInputStream = new BufferedInputStream(new FileInputStream(fileToConvert.getPath()))) {
        try (OutputStream fileOutStream = new FileOutputStream(newFile)) {
            IConverter converter = getConverter();
            convert(fileInputStream, fileOutStream, converter);
        }
    }
}

private void convert(InputStream fileInputStream, OutputStream fileOutStream, IConverter converter) {
    try {
        LOGGER.info("Documents4j: conversion initializing");
        boolean conversion = converter.convert(fileInputStream).as(DocumentType.MS_WORD).to(fileOutStream)
                .as(DocumentType.PDF).execute();
        LOGGER.info("Documents4j: conversion result = " + conversion);
    } catch (Exception e) {
        LOGGER.error("Documents4j: conversion error", e);
    }
}
raphw commented 7 years ago

There should not be a timeout, but it can happen that the Word process is killed by Windows? There is a wrapper implementation for a converter that automatically restarts the server when it becomes inactive, maybe you can try to use this?

tadeubonatti commented 7 years ago

This implementation looks like what I want, but, I haven't found it. Can I restart the server by the client? How?

raphw commented 7 years ago

Have a look at this wrapper: https://github.com/documents4j/documents4j/blob/master/documents4j-aggregation/src/main/java/com/documents4j/job/FailureAwareConverter.java

Using it, you can shut down a converter on a failure. Also have a look at the other classes to add redundancy to your cluster to better overcome failures.

tadeubonatti commented 7 years ago

I've looked your suggestion, but, I think isn't my solution. I'm gonna explain my problem again, with more details:

I start a Conversion Server in this way: java -jar documents4j-server-standalone-shaded.jar http://localhost:9998

My client makes a RemoteConverter and use it normally few times. In a moment, the Conversion Server goes down (operational "false")... If I access it in a browser, it shows:

<remote-converter>
   <operational>false</operational>
   <protocolVersion>1</protocolVersion>
   <supportedConversions>...</supportedConversions>
   <timeout>120000</timeout>
</remote-converter>

After then, I can create various remote converters in the client, all of them can't make the conversion, because the server isn't operational. So, in this moment I need to restart the Conversion Server.

The Conversion Server is my problem, not the Remote Converter, do you understand? What Am I doing wrong?

raphw commented 7 years ago

In this case, you need to have some server redundancy and a broker who restarts the service upon failure. On the client side, you can then add the failover.

tadeubonatti commented 7 years ago

Ok! Will be develop.

Thanks for the replies.