Changeset 5226


Ignore:
Timestamp:
2003-08-20T16:10:44+12:00 (21 years ago)
Author:
kjdon
Message:

now looks for proxy element in site config file - if its there, it sets the system proxyHost etc properties. this will enable http connections from teh servlet to the outside world - eg for InfomineProxy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r5112 r5226  
    3838import java.io.Reader;
    3939import java.io.StringReader;
     40import java.net.Authenticator;
     41import java.net.PasswordAuthentication;     
    4042
    4143/**
     
    148150        this.site_http_address = http_address.getAttribute(GSXML.VALUE_ATT);
    149151    }
    150    
     152
     153    Element proxy = (Element)GSXML.getChildByTagName(config, "proxy");
     154    if (proxy != null) {
     155        String host = proxy.getAttribute("host");
     156        String port = proxy.getAttribute("port");
     157        final String user = proxy.getAttribute("user");
     158        final String passwd = proxy.getAttribute("password");
     159        if (host.equals("") || port.equals("") || user.equals("")||passwd.equals("")) {
     160        System.err.println("MessageRouter.configure Error: A proxy was specified in the config file, but attributes host, port, user, password were not all present");
     161        } else {
     162        try {
     163            // set up the proxy
     164            System.setProperty("http.proxyType", "4");
     165            System.setProperty("http.proxyHost", host);
     166            System.setProperty("http.proxyPort", port);
     167            System.setProperty("http.proxySet", "true");
     168            Authenticator.setDefault(new Authenticator(){
     169                protected PasswordAuthentication getPasswordAuthentication(){
     170                return new PasswordAuthentication(user, new
     171                    String(passwd).toCharArray());
     172                }
     173            });
     174           
     175        } catch (Exception e) {
     176            System.err.println("MessageRouter Error: couldn't set up the proxy");
     177        }
     178        }
     179    }
     180                     
    151181    // load up the services
    152182    Element service_rack_list = (Element)GSXML.getChildByTagName(config, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
     
    845875    }
    846876    }
    847 
    848877   
    849878}
Note: See TracChangeset for help on using the changeset viewer.