ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r696829 - in /ant/ivy/core/branches/2.0.x: ./ src/java/org/apache/ivy/core/settings/ src/java/org/apache/ivy/util/url/
Date Thu, 18 Sep 2008 21:53:25 GMT
Author: maartenc
Date: Thu Sep 18 14:53:24 2008
New Revision: 696829

URL: http://svn.apache.org/viewvc?rev=696829&view=rev
Log:
FIX: Resolve failed on certain proxy environment (IVY-911)

Modified:
    ant/ivy/core/branches/2.0.x/CHANGES.txt
    ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
    ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/AbstractURLHandler.java
    ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/BasicURLHandler.java
    ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/HttpClientHandler.java
    ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandler.java
    ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java

Modified: ant/ivy/core/branches/2.0.x/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.x/CHANGES.txt?rev=696829&r1=696828&r2=696829&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.x/CHANGES.txt (original)
+++ ant/ivy/core/branches/2.0.x/CHANGES.txt Thu Sep 18 14:53:24 2008
@@ -81,6 +81,7 @@
 
 - FIX: Cannot configure items with java.io.File attributes (IVY-905)
 - FIX: Environment properties in ivy settings are no longer resolved (IVY-907)
+- FIX: Resolve failed on certain proxy environment (IVY-911)
 
 
    2.0.0-rc1

Modified: ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java?rev=696829&r1=696828&r2=696829&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
(original)
+++ ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
Thu Sep 18 14:53:24 2008
@@ -46,6 +46,7 @@
 import org.apache.ivy.util.Configurator;
 import org.apache.ivy.util.FileResolver;
 import org.apache.ivy.util.Message;
+import org.apache.ivy.util.url.URLHandler;
 import org.apache.ivy.util.url.URLHandlerRegistry;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
@@ -364,6 +365,16 @@
         defaultCM = (String) attributes.get("defaultConflictManager");
         defaultLatest = (String) attributes.get("defaultLatestStrategy");
         defaultCircular = (String) attributes.get("circularDependencyStrategy");
+        
+        String requestMethod = (String) attributes.get("httpRequestMethod");
+        if ("head".equalsIgnoreCase(requestMethod)) {
+            URLHandlerRegistry.getHttp().setRequestMethod(URLHandler.REQUEST_METHOD_HEAD);
+        } else if ("get".equalsIgnoreCase(requestMethod)) {
+            URLHandlerRegistry.getHttp().setRequestMethod(URLHandler.REQUEST_METHOD_GET);
+        } else if ((requestMethod != null) && (requestMethod.trim().length() >
0)) {
+            throw new IllegalArgumentException("Invalid httpRequestMethod specified, must
be " +
+            		"one of {'HEAD', 'GET'}");
+        }
     }
 
     private void includeStarted(Map attributes) throws IOException, ParseException {
@@ -561,7 +572,7 @@
             ivy.setDefaultResolver(ivy.substitute(defaultResolver));
         }
         if (defaultCM != null) {
-            ConflictManager conflictManager = ivy.getConflictManager(defaultCM);
+            ConflictManager conflictManager = ivy.getConflictManager(ivy.substitute(defaultCM));
             if (conflictManager == null) {
                 throw new IllegalArgumentException("unknown conflict manager "
                         + ivy.substitute(defaultCM));

Modified: ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/AbstractURLHandler.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/AbstractURLHandler.java?rev=696829&r1=696828&r2=696829&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/AbstractURLHandler.java (original)
+++ ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/AbstractURLHandler.java Thu
Sep 18 14:53:24 2008
@@ -22,6 +22,10 @@
 import java.io.IOException;
 
 public abstract class AbstractURLHandler implements URLHandler {
+    
+    // the request method to use. TODO: don't use a static here
+    private static int requestMethod = REQUEST_METHOD_HEAD;
+
     public boolean isReachable(URL url) {
         return getURLInfo(url).isReachable();
     }
@@ -67,4 +71,12 @@
                     + statusCode + (statusMessage == null ? "" : ": " + statusMessage));
         }
     }
+    
+    public void setRequestMethod(int requestMethod) {
+        AbstractURLHandler.requestMethod = requestMethod;
+    }
+    
+    public int getRequestMethod() {
+        return requestMethod;
+    }
 }

Modified: ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/BasicURLHandler.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/BasicURLHandler.java?rev=696829&r1=696828&r2=696829&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/BasicURLHandler.java (original)
+++ ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/BasicURLHandler.java Thu
Sep 18 14:53:24 2008
@@ -75,7 +75,9 @@
             con.setRequestProperty("User-Agent", "Apache Ivy/" + Ivy.getIvyVersion());
             if (con instanceof HttpURLConnection) {
                 HttpURLConnection httpCon = (HttpURLConnection) con;
-                httpCon.setRequestMethod("HEAD");
+                if (getRequestMethod() == URLHandler.REQUEST_METHOD_HEAD) {
+                    httpCon.setRequestMethod("HEAD");
+                }
                 if (checkStatusCode(url, httpCon)) {
                     return new URLInfo(true, httpCon.getContentLength(), con.getLastModified());
                 }

Modified: ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/HttpClientHandler.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/HttpClientHandler.java?rev=696829&r1=696828&r2=696829&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/HttpClientHandler.java (original)
+++ ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/HttpClientHandler.java Thu
Sep 18 14:53:24 2008
@@ -92,7 +92,7 @@
     }
 
     public InputStream openStream(URL url) throws IOException {
-        GetMethod get = doGet(url);
+        GetMethod get = doGet(url, 0);
         if (!checkStatusCode(url, get)) {
             throw new IOException(
                     "The HTTP response code for " + url + " did not indicate a success."
@@ -102,7 +102,7 @@
     }
 
     public void download(URL src, File dest, CopyProgressListener l) throws IOException {
-        GetMethod get = doGet(src);
+        GetMethod get = doGet(src, 0);
         // We can only figure the content we got is want we want if the status is success.
         if (!checkStatusCode(src, get)) {
             throw new IOException(
@@ -141,11 +141,15 @@
     }
 
     public URLInfo getURLInfo(URL url, int timeout) {
-        HeadMethod head = null;
+        HttpMethodBase method = null;
         try {
-            head = doHead(url, timeout);
-            if (checkStatusCode(url, head)) {
-                return new URLInfo(true, getResponseContentLength(head), getLastModified(head));
+            if (getRequestMethod() == URLHandler.REQUEST_METHOD_HEAD) {
+                method = doHead(url, timeout);
+            } else {
+                method = doGet(url, timeout);
+            }
+            if (checkStatusCode(url, method)) {
+                return new URLInfo(true, getResponseContentLength(method), getLastModified(method));
             }
         } catch (HttpException e) {
             Message.error("HttpClientHandler: " + e.getMessage() + ":" + e.getReasonCode()
+ "="
@@ -160,8 +164,8 @@
             // thrown by HttpClient to indicate the URL is not valid, this happens for instance
             // when trying to download a dynamic version (cfr IVY-390)
         } finally {
-            if (head != null) {
-                head.releaseConnection();
+            if (method != null) {
+                method.releaseConnection();
             }
         }
         return UNAVAILABLE;
@@ -199,7 +203,7 @@
         }
     }
 
-    private long getResponseContentLength(HeadMethod head) {
+    private long getResponseContentLength(HttpMethodBase head) {
         return getHttpClientHelper().getResponseContentLength(head);
     }
 
@@ -230,8 +234,9 @@
         return helper.getHttpClientMajorVersion();
     }
 
-    private GetMethod doGet(URL url) throws IOException {
+    private GetMethod doGet(URL url, int timeout) throws IOException {
         HttpClient client = getClient(url);
+        client.setTimeout(timeout);
 
         GetMethod get = new GetMethod(url.toExternalForm());
         get.setDoAuthentication(useAuthentication(url) || useProxyAuthentication());
@@ -372,8 +377,8 @@
         private HttpClientHelper3x() {
         }
 
-        public long getResponseContentLength(HeadMethod head) {
-            return head.getResponseContentLength();
+        public long getResponseContentLength(HttpMethodBase method) {
+            return method.getResponseContentLength();
         }
 
         /**
@@ -390,8 +395,8 @@
         private HttpClientHelper2x() {
         }
 
-        public long getResponseContentLength(HeadMethod head) {
-            Header header = head.getResponseHeader("Content-Length");
+        public long getResponseContentLength(HttpMethodBase method) {
+            Header header = method.getResponseHeader("Content-Length");
             if (header != null) {
                 try {
                     return Integer.parseInt(header.getValue());
@@ -411,7 +416,7 @@
     }
 
     public interface HttpClientHelper {
-        long getResponseContentLength(HeadMethod head);
+        long getResponseContentLength(HttpMethodBase method);
 
         int getHttpClientMajorVersion();
     }

Modified: ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandler.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandler.java?rev=696829&r1=696828&r2=696829&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandler.java (original)
+++ ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandler.java Thu Sep 18
14:53:24 2008
@@ -29,6 +29,18 @@
  * check reachability, ...).
  */
 public interface URLHandler {
+    
+    /**
+     * Using the slower REQUEST method for getting the basic URL infos. Use this when getting
errors
+     * behind a problematic/special proxy or firewall chain.
+     */
+    public static final int REQUEST_METHOD_GET = 1;
+
+    /**
+     * Using the faster HEAD method for getting the basic URL infos. Works for most common
networks.
+     */
+    public static final int REQUEST_METHOD_HEAD = 2;
+
     public static class URLInfo {
         private long contentLength;
 
@@ -141,4 +153,6 @@
     public void download(URL src, File dest, CopyProgressListener l) throws IOException;
 
     public void upload(File src, URL dest, CopyProgressListener l) throws IOException;
+    
+    public void setRequestMethod(int requestMethod);
 }

Modified: ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java?rev=696829&r1=696828&r2=696829&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java
(original)
+++ ant/ivy/core/branches/2.0.x/src/java/org/apache/ivy/util/url/URLHandlerDispatcher.java
Thu Sep 18 14:53:24 2008
@@ -22,6 +22,7 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.ivy.util.CopyProgressListener;
@@ -80,6 +81,14 @@
     public void upload(File src, URL dest, CopyProgressListener l) throws IOException {
         getHandler(dest.getProtocol()).upload(src, dest, l);
     }
+    
+    public void setRequestMethod(int requestMethod) {
+        defaultHandler.setRequestMethod(requestMethod);
+        for (Iterator it = handlers.values().iterator(); it.hasNext(); ) {
+            URLHandler handler = (URLHandler) it.next();
+            handler.setRequestMethod(requestMethod);
+        }
+    }
 
     public void setDownloader(String protocol, URLHandler downloader) {
         handlers.put(protocol, downloader);



Mime
View raw message