You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by st...@apache.org on 2002/11/11 08:21:19 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net SetProxy.java

stevel      2002/11/10 23:21:19

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional/net
                        SetProxy.java
  Log:
  added user/password support in the proxy, though I cant test it myself. Also added removal of http host in cleanup routine.
  
  Revision  Changes    Path
  1.8       +60 -15    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java
  
  Index: SetProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/net/SetProxy.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SetProxy.java	25 Jul 2002 15:21:18 -0000	1.7
  +++ SetProxy.java	11 Nov 2002 07:21:19 -0000	1.8
  @@ -66,9 +66,9 @@
    * Sets Java's web proxy properties, so that tasks and code run in
    * the same JVM can have through-the-firewall access to remote web sites,
    * and remote ftp sites.
  - * You can nominate an http and ftp proxy, or a socks server, reset the server 
  + * You can nominate an http and ftp proxy, or a socks server, reset the server
    * settings, or do nothing at all.
  - * <p> 
  + * <p>
    * Examples
    * <pre>&lt;setproxy/&gt;</pre>
    * do nothing
  @@ -82,14 +82,16 @@
    * use socks via socksy:1080
    * <pre>&lt;setproxy socksproxyhost=""/&gt;</pre>
    * stop using the socks server
  - 
  - 
  - 
  + * You can set a username and password for http with the <tt>proxyHost</tt>
  + * and <tt>proxyPassword</tt> attributes. On Java1.4 and above these can also be
  + * used against SOCKS5 servers.
  +
  +
    * @see <a href="http://java.sun.com/j2se/1.4/docs/guide/net/properties.html">
    *  java 1.4 network property list</a>
    * @author Steve Loughran
     *@since       Ant 1.5
  - * @ant.task
  + * @ant.task category="network"
    */
   public class SetProxy extends Task {
   
  @@ -107,7 +109,7 @@
        * socks host.
        */
       private String socksProxyHost = null;
  -    
  +
       /**
        * Socks proxy port. Default is 1080.
        */
  @@ -116,10 +118,20 @@
   
       /**
        * list of non proxy hosts
  -     */ 
  +     */
       private String nonProxyHosts = null;
   
       /**
  +     * user for http only
  +     */
  +    private String proxyUser=null;
  +
  +    /**
  +     * password for http only
  +     */
  +    private String proxyPassword=null;
  +
  +    /**
        * the HTTP/ftp proxy host. Set this to "" for the http proxy
        * option to be disabled
        *
  @@ -159,23 +171,40 @@
           this.socksProxyPort = port;
       }
   
  +
       /**
        * A list of hosts to bypass the proxy on. These should be separated
        * with the vertical bar character '|'. Only in Java 1.4 does ftp use
        * this list.
        * e.g. fozbot.corp.sun.com|*.eng.sun.com
        * @param nonProxyHosts lists of hosts to talk direct to
  -     */ 
  +     */
       public void setNonProxyHosts(String nonProxyHosts) {
           this.nonProxyHosts = nonProxyHosts;
       }
   
       /**
  +     * set the proxy user. Probably requires a password to accompany this
  +     * setting. Default=""
  +     * @param proxyUser
  +     */
  +    public void setProxyUser(String proxyUser) {
  +        this.proxyUser = proxyUser;
  +    }
  +
  +    /**
  +     * set the password for the proxy. used only if the proxyUser is set
  +     * @param proxyPassword
  +     */
  +    public void setProxyPassword(String proxyPassword) {
  +        this.proxyPassword = proxyPassword;
  +    }
  +
  +    /**
        * if the proxy port and host settings are not null, then the settings
        * get applied these settings last beyond the life of the object and
        * apply to all network connections
        * Relevant docs: buglist #4183340
  -     * @return true if the settings were applied
        */
   
       public void applyWebProxySettings() {
  @@ -196,11 +225,19 @@
                   sysprops.put("ftp.proxyPort", portString);
                   if (nonProxyHosts != null) {
                       sysprops.put("http.nonProxyHosts", nonProxyHosts);
  +                    sysprops.put("https.nonProxyHosts", nonProxyHosts);
                       sysprops.put("ftp.nonProxyHosts", nonProxyHosts);
  -                }                    
  +                }
  +                if(proxyUser!=null) {
  +                    sysprops.put("http.proxyUser", proxyUser);
  +                    sysprops.put("http.proxyPassword", proxyPassword);
  +                }
               } else {
                   log("resetting http proxy", Project.MSG_VERBOSE);
  +                sysprops.remove("http.proxyHost");
                   sysprops.remove("http.proxyPort");
  +                sysprops.remove("http.proxyUser");
  +                sysprops.remove("http.proxyPassword");
                   sysprops.remove("https.proxyHost");
                   sysprops.remove("https.proxyPort");
                   sysprops.remove("ftp.proxyHost");
  @@ -215,13 +252,21 @@
                   enablingProxy = true;
                   sysprops.put("socksProxyHost", socksProxyHost);
                   sysprops.put("socksProxyPort", Integer.toString(socksProxyPort));
  +                if (proxyUser != null) {
  +                    //this may be a java1.4 thingy only
  +                    sysprops.put("java.net.socks.username", proxyUser);
  +                    sysprops.put("java.net.socks.password", proxyPassword);
  +                }
  +
               } else {
                   log("resetting socks proxy", Project.MSG_VERBOSE);
                   sysprops.remove("socksProxyHost");
                   sysprops.remove("socksProxyPort");
  +                sysprops.remove("java.net.socks.username");
  +                sysprops.remove("java.net.socks.password");
               }
           }
  -        
  +
   
           //for Java1.1 we need to tell the system that the settings are new
           if (settingsChanged &&
  @@ -232,10 +277,10 @@
   
       /**
        * list out what is going on
  -     */ 
  +     */
       private void traceSettingInfo() {
  -        log("Setting proxy to " 
  -                + (proxyHost != null ? proxyHost : "''") 
  +        log("Setting proxy to "
  +                + (proxyHost != null ? proxyHost : "''")
                   + ":" + proxyPort,
                   Project.MSG_VERBOSE);
       }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>