Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

My big idea: Ancient Brain

Search:

CA114      CA170

CA668      CA669      Projects


Using the DCU proxy in Java

In DCU, HTTP requests may (or may not) have to go through one of the DCU proxy servers.

If so, you will need this page.




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.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:

$ 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)



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.



ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.

Wikipedia: Sometimes I link to Wikipedia. I have written something In defence of Wikipedia. It is often a useful starting point but you cannot trust it. Linking to it is like linking to a Google search. A starting point, not a destination. I automatically highlight in red all links to Wikipedia and Google search and other possibly-unreliable user-generated content.