I want to communicate to Oracle DB Server which sits outside my network via the proxy server.
I can access the web application hosted on the same machine via Browser with proxy settings.
Can a simple Java program establish JDBC Connection thru the proxy server?
*To provide an example will be better *
Regards.
If the proxy is only a HTTP proxy, then no.
But if the proxy transfers TCP/IP trafic, then you can.
How to do that, look at How do I set the proxy to be used by the JVM or http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
Oracle JDBC (and any other JDBC connections to that extent) are not HTTP-based protocols, so the proxying has to be done at TCP layer.
For this reason, you can't use Squid Proxy for example (which only does proxying at HTTP layer), but there are many other proxying services that can work at TCP layer:
nginx proxy
haproxy
On the former there is a nice step by step guide how to setup JDBC proxying using NGINX
https://kwjrnl.wordpress.com/2015/07/27/tcp-proxy-with-nginx-for-jdbc-connection/
Related
I am new to proxy servers implementations in micro service architecture. So In micro-service architecture what are forward and reverse proxy? what are the best practices for implementing them in java and what are the advantages of having both in place?
A proxy is a service which forward data between two points.
A forward proxy is a proxy which will initiate a connection to a server on the client demand. It is commonly used in company networks to control employees connections to forbid some sites. If you want more informations about proxy protocols, you can look for SOCKS4, SOCKS5 or HTTP Connect proxies.
A reverse proxy however, will act as the server: you connect to it as if it was the real server, it hides it. It is commonly used to hide the real location of the server or to distribute the network load between multiple servers. A popular one is NGINX.
Thrift provides several different non-blocking server models, like TNonblockingServer, THsHaServer, and TThreadedSelectorServer. But, I'd like to enable SSL on the server. It seems SSL only works on blocking servers in Thrift.
Anyone has any clues of a non-blocking SSL server in Thrift? Java example would be highly appreciated.
One alternative to worrying about SSL in your Java App is to stand up something like nginx (http://wiki.nginx.org/SSL-Offloader) as a reverse proxy.
This has the upside of your application not needing to care about SSL but does require one more layer in your stack.
Clients will connect to the nginx server instead of directly to your client and nginx will forward those connections to your Thrift server.
You don't necessarily need two different servers for this approach, just configure your Thrift server to only listen on localhost (127.0.0.1 for ipv4) and have nginx listen on your external interfaces and forward to localhost.
Edit: client -> server in last paragraph
What protocol is used for communication between App server and DB server in Java EE if they are both hosted on different machines?
I mean if I use JDBC, then can I just specify IP of DB server in the config file(connection string)
and the connection will be established?
And if it does get established then what protocol is used to communicate across the two servers?
Is this protocol database dependent?
Or should I have web services on the DB server to communicate with the App server?
The protocol to communicate with the DB is database dependant. The JDBC driver takes care of communicating with the DB for you.
The URL of the database is also database dependant, and contains the information necessary for the driver to connect to the database server.
Using web services on the DB server is definitely a bad idea:
it would forbid the use of transactions in the Java EE application
you wouldn't be able to scroll to results without loading them all in memory
it would be horribly slow
the web service on the DB server would still communicate with the same native protocol with the database server.
Read the JDBC tutorial for more information.
Usually the connection is implemented in the JDBC driver. The driver allows to work with some specific DB server. There are propriaetary drivers (like for Oracle for example) or open-source ones.
What to specify usually depends on the DB you work with and how its configured.
You say "just IP", how about user/password, schema (if it exists), port, etc. This stuff is best to be found by Google I believe :)
Regarding the Protocol, usually its custom protocol implemented again in driver. From the point of view of application developer it should be ok as long as the driver implements the specific version of JDBC.
Regarding Web Services, I don't see why should you use them...
Hope, this helps
It may be that I'm not understanding the UDP protocol...
I'm trying to receive data from a server using the UDP protocol, but I'm sitting behind a firewall. The URLConnection constructor can take an instance of Proxy (as well as a way to set up user name and password of such a proxy server).
How do I connect through a proxy server using the UDP protocol (DatagramSocket)?
Best regards,
TX
Most Proxy servers support the HTTP protocol which is TCP based, so you don't have to do anything with the proxy server to do this.
To pass UDP over a proxy server, you need a proxy which supports UDP. I don't know of any proxy server which supports this so you may have to write one yourself. It is worth noting that UDP is a connectionless protocol which means you have have to authenticate every packet.
SOCKS5, which is an extension of SOCKS4, includes support for UDP in addition to authentication. One implementation of a SOCKS5 Server written in Java is JSOCKS. You can check this project out at http://jsocks.sourceforge.net/.
Refer to RFC 1928 (https://www.rfc-editor.org/rfc/rfc1928) for more information on SOCKS5.
I want to set up an FTP connection using a proxy server with Apache's commons-net.
But looking at this Does FTPClient support FTP connections through an FTP proxy server? has me worried.
I have to meddle with the system properties and the Sun docs state that "If socksProxyHost is specified then all TCP sockets will use the SOCKS proxy server to establish a connection or accept one."
WTH? All TCP sockets? What about my database connections? Or other FTP connections i might want to open at the same time not using a proxy? Will they all be affected?
Is there some other way to do it that doesn't mess with the rest of my application?
You have several ways of using proxies in Java, especially from version 1.5.
Using System Properties: quick & powerfull but limited flexibility
You can use use a SOCKS proxy for all TCP connections.
You can also set a proxy per protocol, doable for HTTP, FTP and HTTPS
For both methods, you can specify a list of hosts that will not use proxy
Using the java.net.Proxy class (Java 1.5+) to set (or not) a Proxy per Connection
Impleting a java.net.ProxySelector (idem) which will determine a Proxy for each Connection according to your criteria
See the detailled Sun technote on networking & proxies.