|
@@ -139,31 +139,33 @@ public class AdxClient {
|
|
|
int status = resp.statusCode();
|
|
int status = resp.statusCode();
|
|
|
if (status == 200) {
|
|
if (status == 200) {
|
|
|
log.info("[百度监测][请求成功] originalUrl={} finalUrl={} status={} redirects={}",
|
|
log.info("[百度监测][请求成功] originalUrl={} finalUrl={} status={} redirects={}",
|
|
|
- originalUrl, currentUrl, status, redirectCount);
|
|
|
|
|
|
|
+ summarizeUrl(originalUrl), summarizeUrl(currentUrl), status, redirectCount);
|
|
|
return new TrackingResult(originalUrl, status, true);
|
|
return new TrackingResult(originalUrl, status, true);
|
|
|
}
|
|
}
|
|
|
if (status != 302) {
|
|
if (status != 302) {
|
|
|
log.warn("[百度监测][请求失败] originalUrl={} finalUrl={} status={} redirects={}",
|
|
log.warn("[百度监测][请求失败] originalUrl={} finalUrl={} status={} redirects={}",
|
|
|
- originalUrl, currentUrl, status, redirectCount);
|
|
|
|
|
|
|
+ summarizeUrl(originalUrl), summarizeUrl(currentUrl), status, redirectCount);
|
|
|
return new TrackingResult(originalUrl, status, false);
|
|
return new TrackingResult(originalUrl, status, false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Optional<String> location = resp.headers().firstValue("location");
|
|
Optional<String> location = resp.headers().firstValue("location");
|
|
|
if (location.isEmpty() || location.get().isBlank()) {
|
|
if (location.isEmpty() || location.get().isBlank()) {
|
|
|
log.warn("[百度监测][302跟随失败] originalUrl={} currentUrl={} status={} redirects={} reason=missing_location",
|
|
log.warn("[百度监测][302跟随失败] originalUrl={} currentUrl={} status={} redirects={} reason=missing_location",
|
|
|
- originalUrl, currentUrl, status, redirectCount);
|
|
|
|
|
|
|
+ summarizeUrl(originalUrl), summarizeUrl(currentUrl), status, redirectCount);
|
|
|
return new TrackingResult(originalUrl, status, false);
|
|
return new TrackingResult(originalUrl, status, false);
|
|
|
}
|
|
}
|
|
|
if (redirectCount >= trackingMaxRedirects) {
|
|
if (redirectCount >= trackingMaxRedirects) {
|
|
|
log.warn("[百度监测][302跟随失败] originalUrl={} currentUrl={} location={} status={} redirects={} maxRedirects={} reason=redirect_limit_exceeded",
|
|
log.warn("[百度监测][302跟随失败] originalUrl={} currentUrl={} location={} status={} redirects={} maxRedirects={} reason=redirect_limit_exceeded",
|
|
|
- originalUrl, currentUrl, location.get(), status, redirectCount, trackingMaxRedirects);
|
|
|
|
|
|
|
+ summarizeUrl(originalUrl), summarizeUrl(currentUrl), summarizeUrl(location.get()),
|
|
|
|
|
+ status, redirectCount, trackingMaxRedirects);
|
|
|
return new TrackingResult(originalUrl, status, false);
|
|
return new TrackingResult(originalUrl, status, false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String nextUrl = resolveRedirectUrl(currentUrl, location.get());
|
|
String nextUrl = resolveRedirectUrl(currentUrl, location.get());
|
|
|
redirectCount++;
|
|
redirectCount++;
|
|
|
log.info("[百度监测][302跟随] originalUrl={} currentUrl={} location={} nextUrl={} status={} redirects={}/{}",
|
|
log.info("[百度监测][302跟随] originalUrl={} currentUrl={} location={} nextUrl={} status={} redirects={}/{}",
|
|
|
- originalUrl, currentUrl, location.get(), nextUrl, status, redirectCount, trackingMaxRedirects);
|
|
|
|
|
|
|
+ summarizeUrl(originalUrl), summarizeUrl(currentUrl), summarizeUrl(location.get()),
|
|
|
|
|
+ summarizeUrl(nextUrl), status, redirectCount, trackingMaxRedirects);
|
|
|
currentUrl = nextUrl;
|
|
currentUrl = nextUrl;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -173,6 +175,43 @@ public class AdxClient {
|
|
|
return current.resolve(location).toString();
|
|
return current.resolve(location).toString();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static String summarizeUrl(String rawUrl) {
|
|
|
|
|
+ if (rawUrl == null || rawUrl.isBlank()) {
|
|
|
|
|
+ return rawUrl;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ URI uri = URI.create(rawUrl);
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
|
+ if (uri.getScheme() != null && uri.getHost() != null) {
|
|
|
|
|
+ sb.append(uri.getScheme()).append("://").append(uri.getHost());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (uri.getRawPath() != null && !uri.getRawPath().isBlank()) {
|
|
|
|
|
+ sb.append(uri.getRawPath());
|
|
|
|
|
+ }
|
|
|
|
|
+ String query = uri.getRawQuery();
|
|
|
|
|
+ if (query != null && !query.isBlank()) {
|
|
|
|
|
+ sb.append('?').append(abbreviate(query, 96));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sb.length() == 0) {
|
|
|
|
|
+ sb.append(abbreviate(rawUrl, 120));
|
|
|
|
|
+ }
|
|
|
|
|
+ sb.append(" (len=").append(rawUrl.length()).append(')');
|
|
|
|
|
+ return sb.toString();
|
|
|
|
|
+ } catch (Exception ignore) {
|
|
|
|
|
+ return abbreviate(rawUrl, 120) + " (len=" + rawUrl.length() + ")";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String abbreviate(String value, int maxLen) {
|
|
|
|
|
+ if (value == null || value.length() <= maxLen) {
|
|
|
|
|
+ return value;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (maxLen <= 3) {
|
|
|
|
|
+ return value.substring(0, maxLen);
|
|
|
|
|
+ }
|
|
|
|
|
+ return value.substring(0, maxLen) + "...";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ─── 默认价格编码(不加密,直接 URL encode 数字字符串)───────────────
|
|
// ─── 默认价格编码(不加密,直接 URL encode 数字字符串)───────────────
|
|
|
public static String defaultEncodePrice(long price) {
|
|
public static String defaultEncodePrice(long price) {
|
|
|
return URLEncoder.encode(String.valueOf(price), StandardCharsets.UTF_8);
|
|
return URLEncoder.encode(String.valueOf(price), StandardCharsets.UTF_8);
|