Network programming in Java (DCU specific)

On Windows and Linux machines inside DCU, HTTP requests to remote sites (outside DCU) have to go through one of the DCU proxy servers.


How to make your Java programs use the DCU proxy:



Possible solution - Insert in code

You can put something like this in your code before you make HTTP requests:

System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "proxy.dcu.ie" );
System.getProperties().put( "proxyPort", "8080" );

The problem is then your code won't work outside DCU (e.g. if you run the program at home).



Better solution - Use Java command-line arguments

A better solution is to leave your code alone and set the proxy via the $ java -D command-line option:

$ java -DproxySet=true -DproxyHost=proxy.dcu.ie -DproxyPort=8080 prog



How to automate the command-line arguments (Windows)

To avoid typing these command-line arguments every time, write a short BAT file to call java with the correct command-line options.
Write the program dcujava.bat:

@echo off
java    -DproxySet=true -DproxyHost=proxy.dcu.ie -DproxyPort=8080   %*  

And then, when outside DCU:

$ java prog (args)

When inside DCU:

$ dcujava prog (args)

And you don't have to change your code.



How to automate the command-line arguments (Linux)

Write the shell script dcujava:

java    -DproxySet=true -DproxyHost=proxy.dcu.ie -DproxyPort=8080   $*  

And then, when outside DCU:

$ java prog (args)

When inside DCU:

$ dcujava prog (args)



Outside DCU

You do not need to go through a proxy on Windows on my home ISP,
but on some other ISPs you may need to change this to go through their proxy.