How do I use the remote jodconverter service?

190 views Asked by At

I deployed the libreoffice service to a public server, and after successfully starting it and opening the port, I called the service on my project, and when I used its execute method, it reported an error:

2023-11-09 17:27:58.675 ERROR 15750 --- [ter-poolentry-0] o.j.remote.task.RemoteConversionTask     : Remote conversion failed.

java.lang.NullPointerException: null
    at java.base/java.util.Objects.requireNonNull(Objects.java:221) ~[na:na]
    at org.jodconverter.remote.task.RemoteConversionTask.execute(RemoteConversionTask.java:135) ~[jodconverter-remote-4.3.0.jar:4.3.0]
    at org.jodconverter.remote.office.RemoteOfficeManagerPoolEntry.doExecute(RemoteOfficeManagerPoolEntry.java:306) ~[jodconverter-remote-4.3.0.jar:4.3.0]
    at org.jodconverter.core.office.AbstractOfficeManagerPoolEntry.lambda$execute$0(AbstractOfficeManagerPoolEntry.java:83) ~[jodconverter-core-4.3.0.jar:4.3.0]
    at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[na:na]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

org.jodconverter.core.office.OfficeException: Remote conversion failed
    at org.jodconverter.remote.task.RemoteConversionTask.execute(RemoteConversionTask.java:153)
    at org.jodconverter.remote.office.RemoteOfficeManagerPoolEntry.doExecute(RemoteOfficeManagerPoolEntry.java:306)
    at org.jodconverter.core.office.AbstractOfficeManagerPoolEntry.lambda$execute$0(AbstractOfficeManagerPoolEntry.java:83)
    at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
    at java.base/java.util.Objects.requireNonNull(Objects.java:221)
    at org.jodconverter.remote.task.RemoteConversionTask.execute(RemoteConversionTask.java:135)
    ... 7 more
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.alibaba.fastjson2.util.JDKUtils (file:/Users/jayleonc/Developer/Environment/apache-maven-3.8.4/maven-repo/com/alibaba/fastjson2/fastjson2/2.0.17/fastjson2-2.0.17.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of com.alibaba.fastjson2.util.JDKUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Here is some code, config:

jodconverter.
  remote.
    url: http://xxx.xx.xx.xxx:9980
  local: # office-home: /Applications/LibreOffice.app/Contents/
    # office-home: /Applications/LibreOffice.app/Contents/
    enabled: false
package com.xxx.supt.infra.config;

import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.office.OfficeManager;
import org.jodconverter.remote.RemoteConverter;
import org.jodconverter.remote.office.RemoteOfficeManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class LibreofficeConfig {

    @Value("${jodconverter.remote.url:''}")
    private String jodconverterUrl;

    @Bean(
        initMethod = "start",
        destroyMethod = "stop"
    )
    public OfficeManager officeManager() {
        RemoteOfficeManager.Builder builder = RemoteOfficeManager.builder();
        builder.urlConnection(jodconverterUrl);
        builder.poolSize(10);
        builder.taskExecutionTimeout(60000L);
        builder.taskQueueTimeout(60000L);
        return builder.build();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnBean({OfficeManager.class})
    public DocumentConverter jodConverter(OfficeManager officeManager) {
        return RemoteConverter.make(officeManager);
    }

}
public void convertToPdfAndOutput(File file) throws IOException, OfficeException {
        File tempFile = File.createTempFile("temp", ".pdf");
        converter.convert(file).to(tempFile).execute();
        outputToResponse(tempFile, "application/pdf");
    }

When I debugged this line,

converter.convert(file).to(tempFile).execute();

it reported an error, what happened? What should I do? Help me, thanks!

Also, when I deploy the libreoffice service on my laptop, everything works fine! I'm wondering if something is wrong with the file transfer process, I'm not sure, what do you suggest?

Again, thanks!

0

There are 0 answers