Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fix for NUTCH-2129 - Add protocol status tracking to crawl datum contributed by Michael Joyce <[email protected]> this closes #68.

Chris Mattmann80c15661ad23
diff --git a/CHANGES.txt b/CHANGES.txt
index eaed06046..29b3c893e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Nutch Current Development 1.11-SNAPSHOT
+* NUTCH-2129 Add protocol status tracking to crawl datum (Michael Joyce via mattmann)
+
* NUTCH-2142 Nutch File Dump - FileNotFoundException (Invalid Argument) Error (Karanjeet Singh via mattmann)
* NUTCH-2136 Implement a different version of Naive Bayes Parse Filter (Asitang Mishra)
diff --git a/src/java/org/apache/nutch/metadata/Nutch.java b/src/java/org/apache/nutch/metadata/Nutch.java
index ca0d17c53..de80399cd 100644
--- a/src/java/org/apache/nutch/metadata/Nutch.java
+++ b/src/java/org/apache/nutch/metadata/Nutch.java
@@ -41,6 +41,8 @@ public interface Nutch {
public static final Text WRITABLE_GENERATE_TIME_KEY = new Text(
GENERATE_TIME_KEY);
+ public static final Text PROTOCOL_STATUS_CODE_KEY = new Text("nutch.protocol.code");
+
public static final String PROTO_STATUS_KEY = "_pst_";
public static final Text WRITABLE_PROTO_STATUS_KEY = new Text(
diff --git a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
index d3b45213b..9f616fe14 100644
--- a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
+++ b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
@@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
// Nutch imports
import org.apache.nutch.crawl.CrawlDatum;
+import org.apache.nutch.metadata.Nutch;
import org.apache.nutch.net.protocols.Response;
import org.apache.nutch.protocol.Content;
import org.apache.nutch.protocol.Protocol;
@@ -265,6 +266,9 @@ public abstract class HttpBase implements Protocol {
}
int code = response.getCode();
+ datum.getMetaData().put(Nutch.PROTOCOL_STATUS_CODE_KEY,
+ new Text(Integer.toString(code)));
+
byte[] content = response.getContent();
Content c = new Content(u.toString(), u.toString(),
(content == null ? EMPTY_CONTENT : content),
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 9c16539eb..772f3bb39 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.apache.nutch.net.protocols.Response;
import org.apache.hadoop.conf.Configuration;
import org.apache.nutch.protocol.Content;
+import org.apache.nutch.metadata.Nutch;
import org.apache.nutch.protocol.Protocol;
import org.apache.nutch.protocol.ProtocolOutput;
import org.apache.nutch.protocol.ProtocolStatus;
@@ -129,6 +130,9 @@ public class Ftp implements Protocol {
response = new FtpResponse(u, datum, this, getConf()); // make a request
int code = response.getCode();
+ datum.getMetaData().put(Nutch.PROTOCOL_STATUS_CODE_KEY,
+ new Text(Integer.toString(code)));
+
if (code == 200) { // got a good response
return new ProtocolOutput(response.toContent()); // return it