Skip to content
Merged
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 @@ -24,8 +24,6 @@
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHeaders;
Expand All @@ -37,8 +35,9 @@

public class FileResponse {

static final SimpleDateFormat dateFormat =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
static final java.time.format.DateTimeFormatter DATE_FORMATTER =
java.time.format.DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
.withZone(java.time.ZoneId.systemDefault());
static final org.slf4j.Logger LOG =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

Expand Down Expand Up @@ -101,8 +100,8 @@ private void getFileAsHttpResponse(File file) {
return;
}

try {
content = IOUtils.toByteArray(new FileInputStream(file), size);
try (FileInputStream fis = new FileInputStream(file)) {
content = IOUtils.toByteArray(fis, size);
} catch (IOException | IllegalArgumentException e) {
LOG.error("Exception while fetching file response {} ", file.getPath(), e);
statusCode = HttpStatus.SC_METHOD_FAILURE;
Expand All @@ -122,7 +121,7 @@ private void getDirAsHttpResponse(File file) {
}

private static String formatDate(long date) {
return dateFormat.format(new Date(date));
return DATE_FORMATTER.format(java.time.Instant.ofEpochMilli(date));
}

private byte[] generateSitemap(File dir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package org.apache.stormcrawler.util;

import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand All @@ -30,8 +28,8 @@
/** Helper to extract cookies from cookies string. */
public class CookieConverter {

private static final SimpleDateFormat DATE_FORMAT =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(CookieConverter.class);

/**
* Get a list of cookies based on the cookies string taken from response header and the target
Expand Down Expand Up @@ -110,17 +108,17 @@ public static List<Cookie> getCookies(String[] cookiesStrings, URL targetURL) {
// check expiration
if (expires != null) {
try {
Date expirationDate = DATE_FORMAT.parse(expires);
cookie.setExpiryDate(expirationDate);

// check that it hasn't expired?
if (cookie.isExpired(new Date())) {
continue;
Date expirationDate = org.apache.http.client.utils.DateUtils.parseDate(expires);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have dependencies on o.a.httpclient in various places, it is acceptable to have it here too

if (expirationDate != null) {
cookie.setExpiryDate(expirationDate);

// check that it hasn't expired?
if (cookie.isExpired(new Date())) {
continue;
}
}

cookie.setExpiryDate(expirationDate);
} catch (ParseException e) {
// ignore exceptions
} catch (Exception e) {
LOG.debug("Could not parse cookie expiry date: {}", expires, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
// Utility class used to extract refresh tags from HTML pages
public abstract class RefreshTag {

private static final Matcher MATCHER =
Pattern.compile("^.*;\\s*URL='?(.+?)'?$", Pattern.CASE_INSENSITIVE).matcher("");
private static final Pattern PATTERN =
Pattern.compile("^.*;\\s*URL='?(.+?)'?$", Pattern.CASE_INSENSITIVE);

private static final Evaluator EVALUATOR =
QueryParser.parse("meta[http-equiv~=(?i)refresh][content]");
Expand All @@ -42,8 +42,9 @@ public static String extractRefreshURL(String value) {

// 0;URL=http://www.apollocolors.com/site
try {
if (MATCHER.reset(value).matches()) {
return MATCHER.group(1);
Matcher matcher = PATTERN.matcher(value);
if (matcher.matches()) {
return matcher.group(1);
}
} catch (Exception e) {
}
Expand Down