Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises


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.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.