0
votes

This is not a repost, I am asking for the Amazon ec2 instance ! Questions that others asked worked fine on my local machine, and those were solved, but not on Amazon.

There have been several reports regarding this problem, but nothing solved this issue for me. To post a few solutions:

https://forum.openoffice.org/en/forum/viewtopic.php?p=88088

https://forum.openoffice.org/en/forum/viewtopic.php?f=16&t=4767&p=21890&hilit=jodconverter#p21890

https://forum.openoffice.org/en/forum/viewtopic.php?f=16&t=4767&p=21948&hilit=jodconverter#p21948

These are the steps I took:

  1. On a fresh EC2 Amazon instance, I have installed the libre office commons

$sudo apt-get install libreoffice-common

  1. And then Maven

  2. To run the service I am using (tried as sudo as well)

$soffice -nologo -nofirststartwizard -headless -norestore -invisible "-accept=socket,host=localhost,port=8100,tcpNoDelay=1;urp;"

  1. All ports and all securities are open for the ec2 instance

  2. This is my code

import com.artofsolving.jodconverter.DocumentConverter;

import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;

import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;

import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;

import java.io.File;

/** * soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard */ public class testrun {

public static void main(String[] args){ try { File inputFile = new File("./test.html"); File outputFile = new File("./OK.pdf");

// connect to an OpenOffice.org instance running on port 8100 SocketOpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100); connection.connect();

// convert DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(inputFile, outputFile);

// close the connection connection.disconnect(); }catch (Exception e){e.printStackTrace();} }

}

  1. This is my pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>

<groupId>izbr</groupId> <artifactId>izbr</artifactId> <version>1.0-SNAPSHOT</version>

<dependencies> <!-- https://mvnrepository.com/artifact/com.artofsolving/jodconverter --> <dependency> <groupId>com.artofsolving</groupId> <artifactId>jodconverter</artifactId> <version>2.2.1</version> </dependency>

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.4.3</version> </dependency>

</dependencies>

  1. My Java version is openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~14.04-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

  2. When I run

$mvn exec:java -Dexec.mainClass="testrun"

error is: 116 [testrun.main()] INFO com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection - connected com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: conversion failed: could not save output document at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(OpenOfficeDocumentConverter.java:144) at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.convertInternal(OpenOfficeDocumentConverter.java:120) at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:104) at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:74) at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:70) at testrun.main(testrun.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.reflect.UndeclaredThrowableException at com.sun.proxy.$Proxy26.storeToURL(Unknown Source) at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.storeDocument(OpenOfficeDocumentConverter.java:156) at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(OpenOfficeDocumentConverter.java:140) ... 11 more Caused by: com.sun.star.ucb.InteractiveAugmentedIOException: an error occurred during file opening at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:187) at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:153) at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:349) at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:318) at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:106) at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:657) at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:159) at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:141) ... 14 more

I have tried all suggestions such listing the listening ports and then changing the port number for soffice. Also running as sudo, and so on. No solution helped. I have done a chmod 777 on /usr/bin/soffice /usr/bin/X11/soffice but that did not work.

Please note that it is working on my mahcine, but not on Amazon ec2 even if all ports and services are open!

1

1 Answers

0
votes

EDIT: This worked for me, adjust the steps to your code. Changing the permission to folders and other answers I found were simply not helpful at all. I figured this out myself.

Upgrade/Update the instance

$ sudo apt-get upgrade

$ sudo apt-get update

  1. Install java jdk 8

$ sudo add-apt-repository ppa:webupd8team/java

$ sudo apt-get update

$ sudo apt-get install oracle-java8-installer

$ sudo apt-get install oracle-java8-set-default

  1. Install Maven

$ sudo add-apt-repository "deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main"

$ sudo apt-get update

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6DTHIS_IS_HEX_FROM_ERRORFA0101

$ sudo apt-get install maven3

$ sudo ln -s /usr/share/maven3/bin/mvn /usr/bin/mvn

$ sudo apt-get update

  1. Install LibreOffice (full!), and then check if there is a common, ususally there is

$ sudo apt-get install libreoffice

$ sudo apt-get install libreoffice-common

  1. Open a new tab just for testing the connection, ssh to EC2 and do

$ soffice -nologo -nofirststartwizard -headless -norestore -invisible "-accept=socket,host=localhost,port=8100,tcpNoDelay=1;urp;"

  1. Go to a project/testing and adjust the pom.xml

$ nano pom.xml

<dependency>

    <groupId>com.artofsolving</groupId>

    <artifactId>jodconverter</artifactId>

    <version>2.2.1</version>

</dependency>
  1. Adjust the source code so that the line A is changed with the line B, making sure that in-file and out-file (if any) are the right paths, and that they exist

A: OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);

B: SocketOpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);

  1. clean install the project with maven

$ mvn clean install

  1. Run the project/test for example:

$ mvn exec:java -Dexec.mainClass="testrun"