Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.stormcrawler.protocol;

import java.net.URL;
import org.apache.stormcrawler.Metadata;

public class ProtocolResponse {
Expand Down Expand Up @@ -81,11 +82,17 @@ public enum TrimmedContentReason {
private final byte[] content;
private final int statusCode;
private final Metadata metadata;
private final URL url;

public ProtocolResponse(byte[] c, int s, Metadata md) {
this(c, s, md, null);
}

public ProtocolResponse(byte[] c, int s, Metadata md, URL url) {
content = c;
statusCode = s;
metadata = md == null ? new Metadata() : md;
this.url = url;
}

public byte[] getContent() {
Expand All @@ -99,4 +106,8 @@ public int getStatusCode() {
public Metadata getMetadata() {
return metadata;
}

public URL getUrl() {
return url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ public class FileResponse {
private byte[] content;
private int statusCode;
private final Metadata metadata;
private final URL url;

public FileResponse(String u, Metadata md, FileProtocol fileProtocol) throws IOException {

metadata = new Metadata();
content = new byte[0];
statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR;

URL url = URLUtil.toURL(u);
this.url = URLUtil.toURL(u);

if (!url.getPath().equals(url.getFile())) {
LOG.warn("url.getPath() != url.getFile(): {}.", url);
Expand Down Expand Up @@ -125,7 +126,7 @@ public FileResponse(String u, Metadata md, FileProtocol fileProtocol) throws IOE
}

public ProtocolResponse toProtocolResponse() {
return new ProtocolResponse(content, statusCode, metadata);
return new ProtocolResponse(content, statusCode, metadata, this.url);
}

private void getFileAsHttpResponse(File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ public ProtocolResponse getProtocolOutput(String url, final Metadata metadata)
responsemetadata.setValue("metrics.dns.resolution.msec", dnsResolution.toString());
}

return new ProtocolResponse(bytes, response.code(), responsemetadata);
return new ProtocolResponse(
bytes, response.code(), responsemetadata, request.url().url());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.stormcrawler.protocol.Protocol;
import org.apache.stormcrawler.protocol.ProtocolResponse;
import org.apache.stormcrawler.util.ConfUtils;
import org.apache.stormcrawler.util.URLUtil;
import org.slf4j.LoggerFactory;

public class HttpProtocol extends AbstractHttpProtocol {
Expand Down Expand Up @@ -318,7 +319,8 @@ public ProtocolResponse getProtocolOutput(String url, Metadata md) throws Except

responseMetaData.addValue(MD_KEY_END, Instant.now().toString());

return new ProtocolResponse(content, status.get(), responseMetaData);
return new ProtocolResponse(
content, status.get(), responseMetaData, URLUtil.toURL(url));

} finally {
if (isTracing && responseMetaData.getFirstValue(MD_TRACE) == null) {
Expand Down