Network programming in Java (DCU specific)
In DCU,
HTTP requests to remote sites (outside DCU)
are meant to go through
one of the DCU proxy servers.
How to make your Java programs use the DCU proxy
You may need this on Windows in DCU.
You may or may not need this on Linux in DCU.
Possible solution - Insert in code
You can put something like this in your code before you make HTTP requests:
System.setProperty( "proxySet", "true" );
System.setProperty( "proxyHost", "proxy.dcu.ie" );
System.setProperty( "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:
When inside DCU:
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:
When inside DCU:
Detect IP address
Could figure out automatically (by looking at your IP address) if you are in DCU
and if so automatically switch to using the DCU proxy.
ISP proxy
On some ISPs you may need to change this to go through
their proxy.