Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA249      CA318      CA425      CA651

w2mind.computing.dcu.ie      w2mind.org


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:

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



Feeds      HumphrysFamilyTree.com

Bookmark and Share           On Internet since 1987.