This is an automated email from the ASF dual-hosted git repository.

snagel pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/nutch.git


The following commit(s) were added to refs/heads/2.x by this push:
     new fc586d4  NUTCH-2451 protocol-ftp to resolve relative URL when 
following redirects
fc586d4 is described below

commit fc586d4508dbd8f1f5d19fc943e3b43b9f6956ca
Author: Sebastian Nagel <[email protected]>
AuthorDate: Tue Dec 5 12:05:29 2017 +0100

    NUTCH-2451 protocol-ftp to resolve relative URL when following redirects
---
 .../src/java/org/apache/nutch/protocol/ftp/Ftp.java       | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git 
a/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/Ftp.java 
b/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/Ftp.java
index 76735a1..e3108ee 100644
--- a/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/Ftp.java
+++ b/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/Ftp.java
@@ -29,6 +29,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Collection;
 import java.util.HashSet;
@@ -139,7 +140,17 @@ public class Ftp implements Protocol {
         } else if (code >= 300 && code < 400) { // handle redirect
           if (redirects == MAX_REDIRECTS)
             throw new FtpException("Too many redirects: " + url);
-          u = new URL(response.getHeader("Location"));
+          
+          String loc = response.getHeader("Location");
+          try {
+            u = new URL(u, loc);
+          } catch (MalformedURLException mue) {
+            LOG.error("Could not create redirectURL for {} with {}", url, loc);
+            ProtocolStatus ps = ProtocolStatusUtils.makeStatus(
+                ProtocolStatusCodes.EXCEPTION, mue.toString());
+            return new ProtocolOutput(null, ps);
+          }
+          
           redirects++;
           if (LOG.isTraceEnabled()) {
             LOG.trace("redirect to " + u);
@@ -149,6 +160,8 @@ public class Ftp implements Protocol {
         }
       }
     } catch (Exception e) {
+      LOG.error("Could not get protocol output for {}: {}", url,
+          e.getMessage());
       ProtocolStatus ps = ProtocolStatusUtils.makeStatus(
           ProtocolStatusCodes.EXCEPTION, e.toString());
       return new ProtocolOutput(null, ps);

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to