Apache Nutch is an extensible and scalable web crawler
fix for NUTCH-384 (contributed by Heiko Dietze)
Chris Mattmann6ca07a531475
diff --git a/CHANGES.txt b/CHANGES.txtindex 5c4acbd2e..b419ee035 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -155,6 +155,9 @@ Unreleased changes (0.9-dev)52. NUTCH-167 - Observation of robots "noarchive" directive. (ab)+53. NUTCH-384 - Protocol-file plugin does not allow the parse plugins+ framework to operate properly (Heiko Dietze via mattmann)+Release 0.8 - 2006-07-25diff --git a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/File.java b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/File.javaindex 624551b88..811ee5b5b 100644--- a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/File.java+++ b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/File.java@@ -34,6 +34,7 @@ import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.ProtocolOutput;import org.apache.nutch.protocol.ProtocolStatus;import org.apache.nutch.protocol.RobotRules;+import org.apache.nutch.util.NutchConfiguration;import java.net.URL;@@ -100,6 +101,7 @@ public class File implements Protocol {}}} catch (Exception e) {+ e.printStackTrace();return new ProtocolOutput(null, new ProtocolStatus(e));}}@@ -137,6 +139,7 @@ public class File implements Protocol {}File file = new File();+ file.setConf(NutchConfiguration.create());if (maxContentLength != Integer.MIN_VALUE) // set maxContentLengthfile.setMaxContentLength(maxContentLength);diff --git a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.javaindex ce2967bc3..cf730ff8b 100644--- a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java+++ b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java@@ -26,6 +26,8 @@ import java.io.IOException;// Nutch importsimport org.apache.nutch.crawl.CrawlDatum;import org.apache.nutch.protocol.Content;+import org.apache.nutch.util.mime.MimeType;+import org.apache.nutch.util.mime.MimeTypes;import org.apache.nutch.metadata.Metadata;import org.apache.nutch.net.protocols.Response;@@ -191,9 +193,12 @@ public class FileResponse {// set headersheaders.set(Response.CONTENT_LENGTH, new Long(size).toString());- headers.set(Response.LAST_MODIFIED,- this.file.httpDateFormat.toString(f.lastModified()));- headers.set(Response.CONTENT_TYPE, ""); // No Content-Type at file protocol level+ headers.set(Response.LAST_MODIFIED, this.file.httpDateFormat.toString(f+ .lastModified()));+ MimeTypes mimeTypes = MimeTypes.get(conf.get("mime.types.file"));+ MimeType mimeType = mimeTypes.getMimeType(f);+ String mimeTypeString = mimeType != null ? mimeType.getName() : "";+ headers.set(Response.CONTENT_TYPE, mimeTypeString);// response codethis.code = 200; // http OKdiff --git a/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/TestProtocolFile.java b/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/TestProtocolFile.javanew file mode 100644index 000000000..8c3cf0aac--- /dev/null+++ b/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/TestProtocolFile.java@@ -0,0 +1,82 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You 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.nutch.protocol.file;++// Hadoop imports+import org.apache.hadoop.io.Text;++// Nutch imports+import org.apache.nutch.crawl.CrawlDatum;+import org.apache.nutch.net.protocols.Response;+import org.apache.nutch.protocol.ProtocolOutput;+import org.apache.nutch.protocol.ProtocolStatus;+import org.apache.nutch.util.NutchConfiguration;++// Junit imports+import junit.framework.TestCase;++/**+ * @author mattmann+ * @version $Revision$+ *+ * <p>+ * Unit tests for the {@link File}Protocol.+ * </p>.+ */+public class TestProtocolFile extends TestCase {++ private static final org.apache.nutch.protocol.file.File fileProtocol =+ new org.apache.nutch.protocol.file.File();++ private static final String testTextFile = "testprotocolfile.txt";++ private static final CrawlDatum datum = new CrawlDatum();++ private static final String expectedMimeType = "text/plain";++ static {+ fileProtocol.setConf(NutchConfiguration.create());+ }++ /**+ * Tests the setting of the <code>Response.CONTENT_TYPE</code> metadata+ * field.+ *+ * @since NUTCH-384+ *+ */+ public void testSetContentType() {+ Text fileUrl = new Text(this.getClass().getResource(testTextFile)+ .toString());+ assertNotNull(fileUrl);+ ProtocolOutput output = fileProtocol.getProtocolOutput(fileUrl, datum);+ assertNotNull(output);+ assertEquals("Status code: [" + output.getStatus().getCode()+ + "], not equal to: [" + ProtocolStatus.SUCCESS + "]: args: ["+ + output.getStatus().getArgs() + "]", ProtocolStatus.SUCCESS, output+ .getStatus().getCode());+ assertNotNull(output.getContent());+ assertNotNull(output.getContent().getContentType());+ assertEquals(expectedMimeType, output.getContent().getContentType());+ assertNotNull(output.getContent().getMetadata());+ assertEquals(expectedMimeType, output.getContent().getMetadata().get(+ Response.CONTENT_TYPE));++ }++}diff --git a/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/testprotocolfile.txt b/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/testprotocolfile.txtnew file mode 100644index 000000000..fbe8a8acf--- /dev/null+++ b/src/plugin/protocol-file/src/test/org/apache/nutch/protocol/file/testprotocolfile.txt@@ -0,0 +1 @@+Protocol File Test