Page 1 of 1

ConnectionSetupException: no Connector for socket

Posted: Mon Dec 14, 2015 5:10 pm
by Dimitrios
Hi,
having been interested in finding a reliable PDF Converter Library for a pertinent Java Project I am preparing, I recently found out about JodConverter.

At a first stage, I have been attempting to convert a dummy Doc file to PDF, and to this end I have followed all recommended guidelines to set this up (for Windows 8.1 that I'm using), but have been receiving the same error.

Particularly:
* I downloaded OpenOffice 4.1.2
* I followed all guidelines for setting this up for Windows ( http://www.artofsolving.com/node/11.html ). I thus now have a running OpenOfficeUnoServer that has been configured as per the above guidelines.
* I also created my Java Code to perform the conversion. Running the code, I can confirm that the service is indeed created (following the pertinent 'Runtime.getRuntime().exec' function). Therefore, running 'netstat -anp tcp' I can indeed see a listening on port 8100:
TCP 127.0.0.1:8100 0.0.0.0:0 LISTENING
OpenOffice also appears as having been started, at Task Manager.
*However, my code keeps failing right afterwards in the code, when trying to actually connect to this port (using 'OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100)' ). The error I have been receiving, no matter what I have tried, is:
Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.O
penOfficeException: could not obtain service: com.sun.star.ucb.FileContentProvid
er; com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: con
nection failed: socket,host=127.0.0.1,port=8100,tcpNoDelay=1; com.sun.star.conne
ction.ConnectionSetupException: no Connector for socket


Below is my Java Code:

Code: Select all

package JodConverter;

import java.io.ByteArrayInputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.DocumentFamily;
import com.artofsolving.jodconverter.DocumentFormat;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;


public class OpenOfficeConverter {
	   public static void main(String[] args) throws ConnectException, InterruptedException, IOException {


		File inputFile = new File("C:\\JodConverter\\Dummy_Doc_Document.doc");
		System.out.println("Input File Created.");
        File outputFile = new File("C:\\JodConverter\\Dummy_Doc_Document.pdf");
		System.out.println("Output File Created.");
		
		System.out.println("About to run the CMD command.");	

		try {
            Runtime.getRuntime().exec(new String[]{"C:\\Program Files (x86)\\OpenOffice 4\\program\\soffice","-headless","\"-accept=socket,host=127.0.0.1,port=8100;urp;\"","-nofirststartwizard"});
     } catch (IOException ex) {
            System.out.println("IOException on 'getRuntime.exec' .");
        }
		
		OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);

		if (connection == null || !connection.isConnected())
				{System.out.println("No connection.");}
		else
		{System.out.println("Connection has been initiated.");}	

		
		try{
				connection.connect();
			}
		catch(Exception e){
			    System.out.println("Yup, no connection.");	
			}

        // convert
        DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
		System.out.println("Converter Set. Conversion Following.");		
        converter.convert(inputFile, outputFile);
		System.out.println("Conversion has taken place.");
		//connection.disconnect();
        // close the connection
        closeConnection(connection);
		System.out.println("Disconnected..");


}


	public static void closeConnection(OpenOfficeConnection connection) {
		// close the connection
		try {
			System.out.println("Checking whether connection had been established.");
			if (connection != null && connection.isConnected())
				System.out.println("Performing the disconnect command.");	
				connection.disconnect();
		} catch (Exception e) {
			System.out.println("Disconnect failed.");
		}
	}	
}
And that is the exact output I have been constantly receiving (in CMD), after running my code above.
Input File Created.
Output File Created.
About to run the CMD command.
No connection.
Yup, no connection.
Converter Set. Conversion Following.
Dec 14, 2015 2:23:26 PM com.artofsolving.jodconverter.openoffice.connection.Abst
ractOpenOfficeConnection getService
INFO: trying to (re)connect
Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.O
penOfficeException: could not obtain service: com.sun.star.ucb.FileContentProvid
er; com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: con
nection failed: socket,host=127.0.0.1,port=8100,tcpNoDelay=1; com.sun.star.conne
ction.ConnectionSetupException: no Connector for socket
at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOffic
eConnection.getService(AbstractOpenOfficeConnection.java:115)
at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOffic
eConnection.getFileContentProvider(AbstractOpenOfficeConnection.java:125)
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocument
Converter.convertInternal(OpenOfficeDocumentConverter.java:102)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOffice
DocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:90)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOffice
DocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:60)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOffice
DocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:56)
at JodConverter.OpenOfficeConverter.main(OpenOfficeConverter_f
or_Forum.java:64)
I would really appreciate any inputs/ ideas. For some days now, I have been inspecting the internet for answers, have tried several different things but have still been receiving the error above.

Thanks in advance.

Dimitrios

Re: ConnectionSetupException: no Connector for socket

Posted: Mon Dec 14, 2015 11:26 pm
by Greengiant224
IIRC You need to have AOO/LO running FIRST before you can get a connection to it via java.

example:

Code: Select all

    soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
It may be quicker to use a batch file on windows or a shell script for linux.

Does this help?

Greengiant224

Re: ConnectionSetupException: no Connector for socket

Posted: Tue Dec 15, 2015 11:52 am
by Dimitrios
Hi Greengiant224,
thanks for your response.

Let me confirm that I indeed:
  • Have a running OpenOffice Server before attempting the connection in Java (server being OpenOfficeUnoServer, as per the Online guidelines for Windows)
  • Do try the command you sent me in my Java Code, before addressing the connection. As mentioned, the command appears to be indeed working given that the listening on port 8100 gets established (and I can subsequently spot OpenOffice at my Task Manager).
What I would like to somewhat clarify is that thing you mentioned about 'using a batch file on windows'? Could you please explain that, just a bit more?

Many Thanks,
Dimitrios