Skip to content

Commit

Permalink
Remove deprecated OkHttp3ClientHttpFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Nov 17, 2024
1 parent 00ccf89 commit 0bc64a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import org.flywaydb.core.Flyway;
import org.nzbhydra.NzbHydra;
import org.nzbhydra.springnative.ReflectionMarker;
import org.nzbhydra.webaccess.HydraOkHttp3ClientHttpRequestFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;

import java.io.File;
import java.io.FileReader;
Expand Down Expand Up @@ -198,7 +198,7 @@ private static void runH2Command(List<String> updatePassCommand, String errorMes
}

private static File downloadJarFile(String url) throws IOException {
final ClientHttpRequest request = new OkHttp3ClientHttpRequestFactory().createRequest(URI.create(url), HttpMethod.GET);
final ClientHttpRequest request = new HydraOkHttp3ClientHttpRequestFactory().createRequest(URI.create(url), HttpMethod.GET);
final File jarFile;
try (ClientHttpResponse response = request.execute()) {
jarFile = Files.createTempFile("nzbhydra", ".jar").toFile();
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/nzbhydra/downloading/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.ConnectException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -398,6 +399,8 @@ protected byte[] downloadFile(SearchResultEntity result) throws MagnetLinkRedire
throw new DownloadException(result.getLink(), 500, "NZB downloaded is empty");
}
return body.bytes();
} catch (ConnectException e) {
throw new DownloadException(result.getLink(), 502, e.getMessage());
} catch (IOException e) {
logger.error("Error downloading result", e);
throw new DownloadException(result.getLink(), 500, "IOException: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) {


static Request buildRequest(HttpHeaders headers, byte[] content, URI uri, HttpMethod method)
throws MalformedURLException {
throws MalformedURLException {

okhttp3.MediaType contentType = getContentType(headers);
RequestBody body = (content.length > 0 ||
okhttp3.internal.http.HttpMethod.requiresRequestBody(method.name()) ?
RequestBody.create(contentType, content) : null);
okhttp3.internal.http.HttpMethod.requiresRequestBody(method.name()) ?
RequestBody.create(content, contentType) : null);

Request.Builder builder = new Request.Builder().url(uri.toURL()).method(method.name(), body);
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
Expand Down Expand Up @@ -243,15 +243,15 @@ private Boolean isHostInLocalNetwork(String host) {
InetAddress byName = InetAddress.getByName(host);
long ipToLong = ipToLong(byName);
return host.equals("127.0.0.1")
||
(ipToLong >= ipToLong(InetAddress.getByName("10.0.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("10.255.255.255")))
||
(ipToLong >= ipToLong(InetAddress.getByName("172.16.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("172.16.255.255")))
||
(ipToLong >= ipToLong(InetAddress.getByName("192.168.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("192.168.255.255")))
;
||
(ipToLong >= ipToLong(InetAddress.getByName("10.0.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("10.255.255.255")))
||
(ipToLong >= ipToLong(InetAddress.getByName("172.16.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("172.16.255.255")))
||
(ipToLong >= ipToLong(InetAddress.getByName("192.168.0.0")) && ipToLong <= ipToLong(InetAddress.getByName("192.168.255.255")))
;
} catch (UnknownHostException e) {
logger.error("Unable to parse host " + host, e);
logger.error("Unable to parse host {}", host, e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;

import java.io.IOException;
import java.net.URI;

/**
* {@link ClientHttpRequest} implementation based on OkHttp 3.x.
* <p>
* <p>Created via the {@link OkHttp3ClientHttpRequestFactory}.
* <p>Created via the {@link HydraOkHttp3ClientHttpRequestFactory}.
*
* @author Luciano Leggieri
* @author Arjen Poutsma
Expand Down

0 comments on commit 0bc64a8

Please sign in to comment.