Re: Java proxies connection to postgres - Mailing list pgsql-jdbc

From -
Subject Re: Java proxies connection to postgres
Date
Msg-id AANLkTi=xL6TOwZ2RbZhp0Fj8xfL8jZqmGpd58e_rjJOd@mail.gmail.com
Whole thread Raw
In response to Re: Java proxies connection to postgres  (Craig Ringer <craig@postnewspapers.com.au>)
Responses Re: Java proxies connection to postgres
Re: Java proxies connection to postgres
List pgsql-jdbc
Thanks for answering.

I planned to use free public proxy, which supports HTTPS

            //free public proxy finded in google.com
            System.setProperty("http.proxyHost", "189.19.44.164");
            System.setProperty("http.proxyPort", "3128");

            String url = "jdbc:postgresql://ipPublica:5432/DataBaseName";
            Properties props = new Properties();
            props.setProperty("user","User");
            props.setProperty("password","Pass");

            Class.forName("org.postgresql.Driver");
         
            Connection  connection = DriverManager.getConnection(url, props);

With this code I got to connect to postgres en server machine, but it fails in client machine whith firewall  :(
With that error

org.postgresql.util.PSQLException: Connection refused. Verify that the hostname and port are correct and that the postmaster is accepting TCP / IP.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl (ConnectionFactoryImpl.java: 136)
at org.postgresql.core.ConnectionFactory.openConnection (ConnectionFactory.java: 66)
at org.postgresql.jdbc2.AbstractJdbc2Connection. <init> (AbstractJdbc2Connection.java: 125)
at org.postgresql.jdbc3.AbstractJdbc3Connection. <init> (AbstractJdbc3Connection.java: 30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection. <init> (AbstractJdbc3gConnection.java: 22)
at org.postgresql.jdbc4.AbstractJdbc4Connection. <init> (AbstractJdbc4Connection.java: 30)
at org.postgresql.jdbc4.Jdbc4Connection. <init> (Jdbc4Connection.java: 24)
at org.postgresql.Driver.makeConnection (Driver.java: 393)
at org.postgresql.Driver.connect (Driver.java: 267)




2010/8/8 Craig Ringer <craig@postnewspapers.com.au>
On 08/08/10 17:24, - wrote:
> Could someone help me or suggest a solution? I want to connect from a
> computer that has firewall to other where the postgres server run. The
> problem is that computer (client) has a firewall and I have not access to
> configure it, or open ports, ping does not respond. The computer (server)
> where PostgreSQL has open ports but I can not connect to it from another
> because of firewall. I can only access the computer through proxy.
> How I could with Java programming access remotely through proxy to postgres
> forgetting firewall?
>  Java has a connection with proxies. But I dont now how put together with
> postgres connection.

What kind of proxy is it that you have access to?

Do you mean a regular HTTP proxy server? A SOCKS4 or SOCKS5 proxy? Or
something else?

If you can connect via a SOCKS proxy you should be able to set up a
socket to the PostgreSQL server via the socks proxy and use that with
the JDBC driver. You can specify the SOCKS proxy to use using the system
properties "socksProxyHost" and "socksProxyPort".

http://download.oracle.com/javase/7/docs/technotes/guides/net/properties.html

http://download-llnw.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

There are also ways to configure this at runtime via a custom
SocketFactory if you can't change system properties.

If you don't have a SOCKS proxy to work with, and your proxy is
HTTP-only, you're in trouble. If the proxy supports SSL/TLS you might be
able to use its CONNECT command to proxy traffic, but it's probably not
going to be something you can do without writing a custom SocketFactory.

I can't help but wonder if it'd be a good idea to be able to pass a
custom SocketFactory to the JDBC driver, in much the same way you can
pass an SSLSocketFactory with the "sslfactory" JDBC URL argument. That
way, someone needing to do funky things like tunnel a JDBC connection
via a HTTPs proxy could do so without having to patch the driver, just
by handing it a suitable Socket instance when asked.

--
Craig Ringer

pgsql-jdbc by date:

Previous
From: "John T. Dow"
Date:
Subject: Re: 9.0 Driver
Next
From: Dave Cramer
Date:
Subject: Re: Java proxies connection to postgres