java.net.ConnectException Connection Error

2,922 views
Skip to first unread message

bapu rout

unread,
May 16, 2011, 7:17:11 AM5/16/11
to JODConverter
Hi,
I am very first to jodconverter.
I am trying to convert a .docx to .HTML.
I have written following source code:

----******Code Start Here*****-------


import java.io.*;
import java.net.ConnectException;
import java.net.Socket;


import com.artofsolving.jodconverter.openoffice.connection.*;
import com.artofsolving.jodconverter.openoffice.converter.*;
import com.artofsolving.jodconverter.*;


public class Test {



public static boolean checkServerAvailability(String host,int port) {
try {
Socket testSocket = new Socket(host,port);
return(true);
}
catch(Exception e) {
return(false);
}
}

public static void runOpenOfficeServer(String serverExecutable,String
host,int port,long delay,boolean runInvisibly) throws Exception {
String execString = serverExecutable;
if(runInvisibly) {
execString = execString + " -invisible";
}
execString = execString + " -quickstart -accept=socket,host=" + host
+ ",port=" + port + ";urp;StarOffice.ServiceManager";
Process p = Runtime.getRuntime().exec(execString);
/*Wait for OpenOffice server to sort its life out. Kludgy, but cant
find a better way to do this,
as the process doesn't write anything to it output stream*/
Thread.sleep(delay);
}
public static void main(String a[])
{

String openOfficeServerHost = "localhost";
int openOfficeServerPort = 8100;
if(!
Test.checkServerAvailability(openOfficeServerHost,openOfficeServerPort))
{
try {

Test.runOpenOfficeServer("/Users/priyaranjan/Desktop/
jodconverter-2.2.2/MacOS/
soffice",openOfficeServerHost,openOfficeServerPort,20000,false);

}
catch(Exception e) {
System.out.println("Unable to start the OpenOffice server");
e.printStackTrace();

}
}


File inputFile = new File("/Users/priyaranjan/Desktop/Hello.docx");
File outputFile = new File("/Users/priyaranjan/Desktop/Hello.html");



// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new
SocketOpenOfficeConnection(8100);
try
{
connection.connect();
// convert
DocumentConverter converter = new
OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);

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

}



-------********Code Ends Here-----*******


But while trying to run it as java application it is showing an error
messages like:

java.net.ConnectException: connection failed:
socket,host=localhost,port=8100,tcpNoDelay=1:
java.net.ConnectException: Connection refused
at
com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.connect(AbstractOpenOfficeConnection.java:
79) at Test.main(Test.java:66)


So can anyone help me to solve this error.
Thanks in advance.



Brian Fenton

unread,
May 16, 2011, 8:13:32 AM5/16/11
to jodcon...@googlegroups.com
Hi Bapu

Check that the OpenOffice server is listening. Try 'telnet localhost 8100' and you should get something like this
$> telnet localhost 8100
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
`��'com.sun.star.bridge.XProtocolPropertiesUrpProtocolProperties


cheers
Brian




--
You received this message because you are subscribed to the Google Groups "JODConverter" group.
To post to this group, send email to jodcon...@googlegroups.com.
To unsubscribe from this group, send email to jodconverter...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jodconverter?hl=en.


bapu rout

unread,
May 17, 2011, 12:12:45 AM5/17/11
to JODConverter
Hi Brian,

I have visited the site http://www.artofsolving.com/node/10.
I have also tried various method like :

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -
nofirststartwizard


$ unset DISPLAY
$ soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -
nofirststartwizard


But when ever i tried accept="socket,host=127.0.0.1,port=8100;urp;" in
the terminal it is taking with no error.

But then I type telnet localhost 8100 it is showing same error:


Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
Priyaranjan-K-Rout:MacOS priyaranjan$


Can You please guide me how to make OpenOffice server is listening.



Thanks and Regards,
bapu



On May 16, 5:13 pm, Brian Fenton <brian.fen...@gmail.com> wrote:
> Hi Bapu
>
> Check that the OpenOffice server is listening. Try 'telnet localhost 8100'
> and you should get something like this
>
> $> telnet localhost 8100
> Trying 127.0.0.1...
> Connected to localhost.localdomain (127.0.0.1).
> Escape character is '^]'.
> ` 'com.sun.star.bridge.XProtocolPropertiesUrpProtocolProperties
>
> cheers
> Brian
>

Richard Gathogo

unread,
May 17, 2011, 1:56:30 AM5/17/11
to jodcon...@googlegroups.com
Hi Bapu,

I don't know why it say this "Unable to connect to remote host" since you are within the same computer. Please check this thread http://www.oooforum.org/forum/viewtopic.phtml?t=60176. It could lead you to the solution.

Have a blessed day.
Regards Richard Gathogo.
--
+4521843194
Java Developer,
Skype: muraguri2005


kalpana Reddy

unread,
Jan 9, 2013, 2:19:55 AM1/9/13
to jodcon...@googlegroups.com

Hi,

I am facing the same problem while converting the HTML file to PDF file by using JOD converter .

Here is the error :

java.net.ConnectException: connection failed: socket,host=localhost,port=8100,tcpNoDelay=1: java.net.ConnectException: Connection refused: connect
    at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.connect(AbstractOpenOfficeConnection.java:79)
    at OpenOfficeConverter.openConnection(OpenOfficeConverter.java:115)

I am new to this concept , Can anyone please suggest me on this issue.

If anyone running the openoffice 3.0 services, please share me the hostName and port .

Thanks for your reply in advance .

Rams B

unread,
Jan 9, 2013, 2:24:32 AM1/9/13
to jodcon...@googlegroups.com
Better to use JOD Coverter beta version. This version will take care about opening and closing the connections.
Link to get Beta Version: http://code.google.com/p/jodconverter/downloads/detail?name=jodconverter-core-3.0-beta-4-dist.zip
Ramesh

To view this discussion on the web visit https://groups.google.com/d/msg/jodconverter/-/zfq80S0j8u0J.

To post to this group, send email to jodcon...@googlegroups.com.
To unsubscribe from this group, send email to jodconverter...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jodconverter?hl=en.



--
Thanks & Regards,
B. Ramesh Kumar,

kalpana Reddy

unread,
Jan 9, 2013, 4:07:58 AM1/9/13
to jodcon...@googlegroups.com
Hi Ramesh,

I am using the same jodconverter-core-3.0-beta-4.jar for open and close the connection. But i am getting the error .

Thanks,
Kalpana Reddy.
Reply all
Reply to author
Forward
0 new messages