commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/http HttpFileSystemConfigBuilder.java HttpFileSystem.java
Date Fri, 14 May 2004 18:38:35 GMT
imario      2004/05/14 11:38:35

  Modified:    vfs/src/java/org/apache/commons/vfs/provider/http
                        HttpFileSystem.java
  Added:       vfs/src/java/org/apache/commons/vfs/provider/http
                        HttpFileSystemConfigBuilder.java
  Log:
  Allow to set the proxyHost and proxyPort.
  
  Do not set user credentials if no user is provided.
  Reported by Adam R. B. Jack.
  I couldnt reproduce it, but thought it is generally a good idea not to set the credentials
if no username is used.
  
  Revision  Changes    Path
  1.8       +21 -4     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/http/HttpFileSystem.java
  
  Index: HttpFileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/http/HttpFileSystem.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HttpFileSystem.java	10 May 2004 20:09:49 -0000	1.7
  +++ HttpFileSystem.java	14 May 2004 18:38:35 -0000	1.8
  @@ -72,10 +72,27 @@
               client = new HttpClient(new MultiThreadedHttpConnectionManager());
               final HostConfiguration config = new HostConfiguration();
               config.setHost(rootName.getHostName(), rootName.getPort());
  +
  +            FileSystemOptions fso = getFileSystemOptions();
  +            if (fso != null)
  +            {
  +                String proxyHost = HttpFileSystemConfigBuilder.getInstance().getProxyHost(fso);
  +                int proxyPort = HttpFileSystemConfigBuilder.getInstance().getProxyPort(fso);
  +
  +                if (proxyHost != null && proxyPort > 0)
  +                {
  +                    config.setProxy(proxyHost, proxyPort);
  +                }
  +            }
  +
               client.setHostConfiguration(config);
  -            final UsernamePasswordCredentials creds =
  -                new UsernamePasswordCredentials(rootName.getUserName(), rootName.getPassword());
  -            client.getState().setCredentials(null, rootName.getHostName(), creds);
  +
  +            if (rootName.getUserName() != null)
  +            {
  +                final UsernamePasswordCredentials creds =
  +                    new UsernamePasswordCredentials(rootName.getUserName(), rootName.getPassword());
  +                client.getState().setCredentials(null, rootName.getHostName(), creds);
  +            }
           }
           return client;
       }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java
  
  Index: HttpFileSystemConfigBuilder.java
  ===================================================================
  /*
   * Copyright 2002, 2003,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.vfs.provider.http;
  
  import org.apache.commons.vfs.FileSystemConfigBuilder;
  import org.apache.commons.vfs.FileSystemOptions;
  
  /**
   * Description
   * 
   * @author <a href="mailto:imario@apache.org">Mario Ivanovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/05/14 18:38:35 $
   */
  public class HttpFileSystemConfigBuilder extends FileSystemConfigBuilder
  {
      private final static HttpFileSystemConfigBuilder builder = new HttpFileSystemConfigBuilder();
  
      public static HttpFileSystemConfigBuilder getInstance()
      {
          return builder;
      }
  
      /**
       * Set the proxy to use for http connection.<br>
       * You have to set the ProxyPort too if you would like to have the proxy relly used.
       *
       * @param proxyHost the host
       * @see #setProxyPort
       */
      public void setProxyHost(FileSystemOptions opts, String proxyHost)
      {
          setParam(opts, "proxyHost", proxyHost);
      }
  
      /**
       * Set the proxy-port to use for http connection
       * You have to set the ProxyHost too if you would like to have the proxy relly used.
       *
       * @param proxyPort the port
       * @see #setProxyHost
       */
      public void setProxyPort(FileSystemOptions opts, int proxyPort)
      {
          setParam(opts, "proxyPort", new Integer(proxyPort));
      }
  
      /**
       * Get the proxy to use for http connection
       * You have to set the ProxyPort too if you would like to have the proxy relly used.
       *
       * @return proxyHost
       * @see #setProxyPort
       */
      public String getProxyHost(FileSystemOptions opts)
      {
          return (String) getParam(opts, "proxyHost");
      }
  
      /**
       * Get the proxy-port to use for http the connection
       * You have to set the ProxyHost too if you would like to have the proxy relly used.
       *
       * @return proxyPort: the port number or 0 if it is not set
       * @see #setProxyHost
       */
      public int getProxyPort(FileSystemOptions opts)
      {
          if (!hasParam(opts, "proxyPort"))
          {
              return 0;
          }
  
          return ((Number) getParam(opts, "proxyPort")).intValue();
      }
  
      protected Class getConfigClass()
      {
          return HttpFileSystem.class;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message