mirror of
https://github.com/apache/nifi.git
synced 2025-02-06 18:18:27 +00:00
NIFI-12103 Replaced deprecated usage of new URL(String)
This closes #7771 Signed-off-by: David Handermann <exceptionfactory@apache.org> (cherry picked from commit 2aca08910c4e06fff2c98d3794d9b5a3cd427988)
This commit is contained in:
parent
978f4aa518
commit
18ab14b148
@ -40,7 +40,7 @@ import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -194,8 +194,8 @@ public abstract class AbstractTestSecure extends AbstractTestUnsecure {
|
||||
|
||||
protected HttpsURLConnection openUrlConnection(String url, SSLContext sslContext) throws IOException {
|
||||
DockerPort dockerPort = docker.containers().container("squid").port(3128);
|
||||
HttpsURLConnection httpURLConnection = (HttpsURLConnection) new URL(url).openConnection(
|
||||
new Proxy(Proxy.Type.HTTP, new InetSocketAddress(dockerPort.getIp(), dockerPort.getExternalPort())));
|
||||
HttpsURLConnection httpURLConnection = (HttpsURLConnection) URI.create(url).toURL().openConnection(
|
||||
new Proxy(Proxy.Type.HTTP, new InetSocketAddress(dockerPort.getIp(), dockerPort.getExternalPort())));
|
||||
httpURLConnection.setSSLSocketFactory(sslContext.getSocketFactory());
|
||||
return httpURLConnection;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@ -102,6 +102,6 @@ public abstract class AbstractTestUnsecure {
|
||||
}
|
||||
|
||||
protected HttpURLConnection openSuperUserUrlConnection(String url) throws IOException {
|
||||
return (HttpURLConnection) new URL(url).openConnection();
|
||||
return (HttpURLConnection) URI.create(url).toURL().openConnection();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import com.palantir.docker.compose.connection.waiting.SuccessOrFailure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class HttpStatusCodeHealthCheck implements HealthCheck<Container> {
|
||||
@ -50,6 +50,6 @@ public class HttpStatusCodeHealthCheck implements HealthCheck<Container> {
|
||||
}
|
||||
|
||||
protected HttpURLConnection openConnection(String url) throws IOException {
|
||||
return ((HttpURLConnection) new URL(url).openConnection());
|
||||
return ((HttpURLConnection) URI.create(url).toURL().openConnection());
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@ -62,7 +62,7 @@ public class HttpsStatusCodeHealthCheck implements HealthCheck<List<Container>>
|
||||
}
|
||||
|
||||
public static HttpURLConnection getHttpURLConnection(String url, SSLSocketFactory sslSocketFactory, String proxyHostname, int proxyPort) throws IOException {
|
||||
HttpsURLConnection httpURLConnection = (HttpsURLConnection) new URL(url).openConnection(
|
||||
HttpsURLConnection httpURLConnection = (HttpsURLConnection) URI.create(url).toURL().openConnection(
|
||||
new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHostname, proxyPort)));
|
||||
httpURLConnection.setSSLSocketFactory(sslSocketFactory);
|
||||
return httpURLConnection;
|
||||
|
@ -33,6 +33,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
@ -150,8 +151,8 @@ public class HttpConnector {
|
||||
}
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(endpointUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
url = URI.create(endpointUrl).toURL();
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
throw new ConfigurationProviderException("Malformed url " + endpointUrl, e);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -46,7 +47,7 @@ public class LogUtil {
|
||||
}
|
||||
DockerPort dockerPort = container.port(8000);
|
||||
logger.info("Connecting to external port {} for docker internal port of {}", new Object[]{dockerPort.getExternalPort(), dockerPort.getInternalPort()});
|
||||
URL url = new URL("http://" + dockerPort.getIp() + ":" + dockerPort.getExternalPort());
|
||||
URL url = URI.create("http://" + dockerPort.getIp() + ":" + dockerPort.getExternalPort()).toURL();
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||
try (InputStream inputStream = urlConnection.getInputStream();
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||
|
@ -19,6 +19,7 @@ package org.apache.nifi.components.resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -69,11 +70,11 @@ public class StandardResourceReferenceFactory implements ResourceReferenceFactor
|
||||
if (allowedResourceTypes.contains(ResourceType.URL)) {
|
||||
try {
|
||||
if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
|
||||
return new URLResourceReference(new URL(trimmed));
|
||||
return new URLResourceReference(URI.create(trimmed).toURL());
|
||||
}
|
||||
|
||||
if (trimmed.startsWith("file:")) {
|
||||
final URL url = new URL(trimmed);
|
||||
final URL url = URI.create(trimmed).toURL();
|
||||
final String filename = url.getFile();
|
||||
final File file = new File(filename);
|
||||
return new FileResourceReference(file);
|
||||
|
@ -38,10 +38,8 @@ import java.io.InputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
@ -93,6 +91,7 @@ import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.apache.http.client.utils.URIUtils;
|
||||
import org.apache.http.conn.ManagedHttpClientConnection;
|
||||
import org.apache.http.entity.BasicHttpEntity;
|
||||
@ -1356,8 +1355,14 @@ public class SiteToSiteRestApiClient implements Closeable {
|
||||
}
|
||||
|
||||
try {
|
||||
return new URL(clusterUrl.getScheme(), clusterUrl.getHost(), clusterUrl.getPort(), uriPath).toURI().toString();
|
||||
} catch (MalformedURLException|URISyntaxException e) {
|
||||
return new URIBuilder()
|
||||
.setScheme(clusterUrl.getScheme())
|
||||
.setHost(clusterUrl.getHost())
|
||||
.setPort(clusterUrl.getPort())
|
||||
.setPath(uriPath)
|
||||
.build()
|
||||
.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
@ -1369,8 +1374,14 @@ public class SiteToSiteRestApiClient implements Closeable {
|
||||
private void setBaseUrl(final String scheme, final String host, final int port, final String path) {
|
||||
final String baseUri;
|
||||
try {
|
||||
baseUri = new URL(scheme, host, port, path).toURI().toString();
|
||||
} catch (MalformedURLException|URISyntaxException e) {
|
||||
baseUri = new URIBuilder()
|
||||
.setScheme(scheme)
|
||||
.setHost(host)
|
||||
.setPort(port)
|
||||
.setPath(path)
|
||||
.build()
|
||||
.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
this.setBaseUrl(baseUri);
|
||||
|
@ -30,7 +30,6 @@ import org.apache.nifi.util.FormatUtils;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.text.NumberFormat;
|
||||
@ -548,7 +547,7 @@ public class StandardValidators {
|
||||
|
||||
try {
|
||||
final String evaluatedInput = context.newPropertyValue(input).evaluateAttributeExpressions().getValue();
|
||||
new URL(evaluatedInput);
|
||||
URI.create(evaluatedInput).toURL();
|
||||
return new ValidationResult.Builder().subject(subject).input(input).explanation("Valid URL").valid(true).build();
|
||||
} catch (final Exception e) {
|
||||
return new ValidationResult.Builder().subject(subject).input(input).explanation("Not a valid URL").valid(false).build();
|
||||
@ -577,8 +576,8 @@ public class StandardValidators {
|
||||
|
||||
// First check to see if it is a valid URL
|
||||
try {
|
||||
new URL(evaluatedInput);
|
||||
} catch (MalformedURLException mue) {
|
||||
URI.create(evaluatedInput).toURL();
|
||||
} catch (IllegalArgumentException | MalformedURLException mue) {
|
||||
validUrl = false;
|
||||
}
|
||||
|
||||
|
@ -98,8 +98,8 @@ public class ClassLoaderUtils {
|
||||
// If the path is already a URL, just add it (but don't check if it exists, too expensive and subject to network availability)
|
||||
boolean isUrl = true;
|
||||
try {
|
||||
additionalClasspath.add(new URL(modulePathString));
|
||||
} catch (MalformedURLException mue) {
|
||||
additionalClasspath.add(URI.create(modulePathString).toURL());
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
isUrl = false;
|
||||
}
|
||||
if (!isUrl) {
|
||||
|
@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.FilenameFilter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashSet;
|
||||
@ -124,7 +125,7 @@ public class TestClassLoaderUtils {
|
||||
@Test
|
||||
public void testGenerateAdditionalUrlsFingerprintForHttpUrl() throws MalformedURLException {
|
||||
final Set<URL> urls = new HashSet<>();
|
||||
URL testUrl = new URL("http://myhost/TestSuccess.jar");
|
||||
URL testUrl = URI.create("http://myhost/TestSuccess.jar").toURL();
|
||||
urls.add(testUrl);
|
||||
String testFingerprint = ClassLoaderUtils.generateAdditionalUrlsFingerprint(urls, null);
|
||||
assertNotNull(testFingerprint);
|
||||
|
@ -20,7 +20,7 @@ package org.apache.nifi.kafka.connect.validators;
|
||||
import org.apache.kafka.common.config.ConfigDef;
|
||||
import org.apache.kafka.common.config.ConfigException;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
|
||||
public class ConnectHttpUrlValidator implements ConfigDef.Validator {
|
||||
@Override
|
||||
@ -34,8 +34,7 @@ public class ConnectHttpUrlValidator implements ConfigDef.Validator {
|
||||
}
|
||||
|
||||
try {
|
||||
final URL url = new URL((String) value);
|
||||
final String protocol = url.getProtocol();
|
||||
final String protocol = URI.create((String) value).toURL().getProtocol();
|
||||
if (!protocol.equals("http") && !protocol.equals("https")) {
|
||||
throw new ConfigException("Invalid value for property " + name + ": The value must be an http or https URL");
|
||||
}
|
||||
|
@ -48,8 +48,8 @@ public abstract class AbstractNiFiProvenanceEventAnalyzer implements NiFiProvena
|
||||
*/
|
||||
protected URL parseUrl(String url) {
|
||||
try {
|
||||
return new URL(url);
|
||||
} catch (MalformedURLException e) {
|
||||
return URI.create(url).toURL();
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
final String msg = String.format("Failed to parse url %s due to %s", url, e);
|
||||
throw new IllegalArgumentException(msg, e);
|
||||
}
|
||||
|
@ -80,8 +80,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
@ -95,6 +94,7 @@ import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
@ -447,8 +447,7 @@ public class ReportLineageToAtlas extends AbstractReportingTask {
|
||||
.map(String::trim)
|
||||
.forEach(input -> {
|
||||
try {
|
||||
final URL url = new URL(input);
|
||||
schemes.add(url.toURI().getScheme());
|
||||
schemes.add(Objects.requireNonNull(URI.create(input).getScheme()));
|
||||
} catch (Exception e) {
|
||||
results.add(new ValidationResult.Builder().subject(ATLAS_URLS.getDisplayName()).input(input)
|
||||
.explanation("contains invalid URI: " + e).valid(false).build());
|
||||
@ -667,7 +666,7 @@ public class ReportLineageToAtlas extends AbstractReportingTask {
|
||||
.map(String::trim)
|
||||
.forEach(urlString -> {
|
||||
try {
|
||||
new URL(urlString);
|
||||
URI.create(urlString).toURL();
|
||||
} catch (Exception e) {
|
||||
throw new ProcessException(e);
|
||||
}
|
||||
@ -860,15 +859,8 @@ public class ReportLineageToAtlas extends AbstractReportingTask {
|
||||
final ProcessGroupStatus rootProcessGroup = context.getEventAccess().getGroupStatus("root");
|
||||
final String flowName = rootProcessGroup.getName();
|
||||
final String nifiUrl = context.getProperty(ATLAS_NIFI_URL).evaluateAttributeExpressions().getValue();
|
||||
|
||||
|
||||
final String namespace;
|
||||
try {
|
||||
final String nifiHostName = new URL(nifiUrl).getHost();
|
||||
namespace = namespaceResolvers.fromHostNames(nifiHostName);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new IllegalArgumentException("Failed to parse NiFi URL, " + e.getMessage(), e);
|
||||
}
|
||||
final String nifiHostName = URI.create(nifiUrl).getHost();
|
||||
final String namespace = namespaceResolvers.fromHostNames(nifiHostName);
|
||||
|
||||
NiFiFlow existingNiFiFlow = null;
|
||||
try {
|
||||
|
@ -53,7 +53,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -195,8 +194,8 @@ public class TestReportLineageToAtlas {
|
||||
atlasConf.setProperty("atlas.rest.address", atlasUrls);
|
||||
|
||||
Consumer<Exception> assertion = e -> assertTrue(
|
||||
e.getCause() instanceof MalformedURLException,
|
||||
"Expected " + MalformedURLException.class.getSimpleName() + " for " + atlasUrls + ", got " + e
|
||||
e.getCause() instanceof IllegalArgumentException,
|
||||
"Expected " + IllegalArgumentException.class.getSimpleName() + " for " + atlasUrls + ", got " + e
|
||||
);
|
||||
|
||||
// WHEN
|
||||
|
@ -31,7 +31,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -336,7 +335,7 @@ public abstract class AbstractAWSGatewayApiProcessor extends
|
||||
// but we may need to when validating
|
||||
final String encodedInput = URLEncoder.encode(evaluatedInput, "UTF-8");
|
||||
final String url = String.format("http://www.foo.com?%s", encodedInput);
|
||||
new URL(url);
|
||||
URI.create(url).toURL();
|
||||
results.add(new ValidationResult.Builder().subject(PROP_QUERY_PARAMS.getName())
|
||||
.input(input)
|
||||
.explanation("Valid URL params")
|
||||
|
@ -18,6 +18,7 @@ package org.apache.nifi.reporting.azure.loganalytics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.MessageFormat;
|
||||
@ -45,7 +46,6 @@ import org.apache.nifi.annotation.documentation.Tags;
|
||||
import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
|
||||
import org.apache.nifi.components.AllowableValue;
|
||||
import org.apache.nifi.components.PropertyDescriptor;
|
||||
import org.apache.nifi.controller.ConfigurationContext;
|
||||
import org.apache.nifi.controller.status.ProcessGroupStatus;
|
||||
import org.apache.nifi.expression.ExpressionLanguageScope;
|
||||
import org.apache.nifi.processor.util.StandardValidators;
|
||||
@ -169,8 +169,6 @@ public class AzureLogAnalyticsProvenanceReportingTask extends AbstractAzureLogAn
|
||||
.description("Specifies how many records to send in a single batch, at most.").required(true)
|
||||
.defaultValue("1000").addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR).build();
|
||||
|
||||
private ConfigurationContext context;
|
||||
|
||||
private volatile ProvenanceEventConsumer consumer;
|
||||
|
||||
@Override
|
||||
@ -300,8 +298,8 @@ public class AzureLogAnalyticsProvenanceReportingTask extends AbstractAzureLogAn
|
||||
final String nifiUrl = context.getProperty(INSTANCE_URL).evaluateAttributeExpressions().getValue();
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(nifiUrl);
|
||||
} catch (final MalformedURLException e1) {
|
||||
url = URI.create(nifiUrl).toURL();
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -419,7 +420,7 @@ public class ElasticSearchClientServiceImpl extends AbstractControllerService im
|
||||
this.url = hostsSplit.get(0);
|
||||
final List<HttpHost> hh = new ArrayList<>(hostsSplit.size());
|
||||
for (final String host : hostsSplit) {
|
||||
final URL u = new URL(host);
|
||||
final URL u = URI.create(host).toURL();
|
||||
hh.add(new HttpHost(u.getHost(), u.getPort(), u.getProtocol()));
|
||||
}
|
||||
|
||||
@ -560,8 +561,8 @@ public class ElasticSearchClientServiceImpl extends AbstractControllerService im
|
||||
}
|
||||
sb.append("/").append(endpoint);
|
||||
|
||||
final HttpEntity queryEntity = new NStringEntity(query, ContentType.APPLICATION_JSON);
|
||||
try {
|
||||
final HttpEntity queryEntity = new NStringEntity(query, ContentType.APPLICATION_JSON);
|
||||
return performRequest("POST", sb.toString(), requestParameters, queryEntity);
|
||||
} catch (final Exception e) {
|
||||
throw new ElasticsearchException(e);
|
||||
|
@ -40,6 +40,7 @@ import org.testcontainers.utility.DockerImageName;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
@ -134,7 +135,7 @@ public abstract class AbstractElasticsearchITBase {
|
||||
|
||||
protected static void setupTestData() throws IOException {
|
||||
final int majorVersion = getElasticMajorVersion();
|
||||
final URL url = new URL(elasticsearchHost);
|
||||
final URL url = URI.create(elasticsearchHost).toURL();
|
||||
testDataManagementClient = RestClient
|
||||
.builder(new HttpHost(url.getHost(), url.getPort(), url.getProtocol()))
|
||||
.setHttpClientConfigCallback(httpClientBuilder -> {
|
||||
|
@ -41,6 +41,7 @@ import org.springframework.security.oauth2.core.oidc.user.OidcUser;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.Cookie;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
@ -204,8 +205,8 @@ class OidcAuthenticationSuccessHandlerTest {
|
||||
|
||||
URL getIssuer() {
|
||||
try {
|
||||
return new URL(ISSUER);
|
||||
} catch (final MalformedURLException e) {
|
||||
return URI.create(ISSUER).toURL();
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -158,8 +158,7 @@ public class PrometheusReportingTaskIT {
|
||||
}
|
||||
|
||||
private String getMetrics() throws IOException {
|
||||
URL url = new URL("http://localhost:9092/metrics");
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
HttpURLConnection con = (HttpURLConnection) URI.create("http://localhost:9092/metrics").toURL().openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
int status = con.getResponseCode();
|
||||
assertEquals(HttpURLConnection.HTTP_OK, status);
|
||||
|
@ -51,7 +51,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -124,8 +124,7 @@ public class TestPrometheusRecordSink {
|
||||
}
|
||||
|
||||
private String getMetrics() throws IOException {
|
||||
URL url = new URL("http://localhost:" + portString + "/metrics");
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
HttpURLConnection con = (HttpURLConnection) URI.create("http://localhost:" + portString + "/metrics").toURL().openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
int status = con.getResponseCode();
|
||||
assertEquals(HttpURLConnection.HTTP_OK, status);
|
||||
|
@ -20,6 +20,7 @@ package org.apache.nifi.reporting;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -274,8 +275,8 @@ public class SiteToSiteProvenanceReportingTask extends AbstractSiteToSiteReporti
|
||||
final String nifiUrl = context.getProperty(SiteToSiteUtils.INSTANCE_URL).evaluateAttributeExpressions().getValue();
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(nifiUrl);
|
||||
} catch (final MalformedURLException e1) {
|
||||
url = URI.create(nifiUrl).toURL();
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
// already validated
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package org.apache.nifi.reporting;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -132,8 +133,8 @@ public class SiteToSiteStatusReportingTask extends AbstractSiteToSiteReportingTa
|
||||
final String nifiUrl = context.getProperty(SiteToSiteUtils.INSTANCE_URL).evaluateAttributeExpressions().getValue();
|
||||
URL url;
|
||||
try {
|
||||
url = new URL(nifiUrl);
|
||||
} catch (final MalformedURLException e1) {
|
||||
url = URI.create(nifiUrl).toURL();
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
// already validated
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
@ -255,7 +256,7 @@ public class PutSlack extends AbstractProcessor {
|
||||
jsonWriter.writeObject(jsonObject);
|
||||
jsonWriter.close();
|
||||
|
||||
URL url = new URL(context.getProperty(WEBHOOK_URL).evaluateAttributeExpressions(flowFile).getValue());
|
||||
URL url = URI.create(context.getProperty(WEBHOOK_URL).evaluateAttributeExpressions(flowFile).getValue()).toURL();
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
|
@ -27,6 +27,7 @@ import java.net.CookieManager;
|
||||
import java.net.CookiePolicy;
|
||||
import java.net.Proxy;
|
||||
import java.net.Proxy.Type;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -938,7 +939,7 @@ public class InvokeHTTP extends AbstractProcessor {
|
||||
FlowFile responseFlowFile = null;
|
||||
try {
|
||||
final String urlProperty = trimToEmpty(context.getProperty(HTTP_URL).evaluateAttributeExpressions(requestFlowFile).getValue());
|
||||
final URL url = new URL(urlProperty);
|
||||
final URL url = URI.create(urlProperty).toURL();
|
||||
|
||||
Request httpRequest = configureRequest(context, session, requestFlowFile, url);
|
||||
logRequest(logger, httpRequest);
|
||||
|
@ -56,7 +56,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
@ -125,8 +125,8 @@ public class ITestHandleHttpRequest {
|
||||
try {
|
||||
serverReady.await();
|
||||
final int port = ((HandleHttpRequest) runner.getProcessor()).getPort();
|
||||
final HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:"
|
||||
+ port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").openConnection();
|
||||
final HttpURLConnection connection = (HttpURLConnection) URI.create("http://localhost:"
|
||||
+ port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").toURL().openConnection();
|
||||
|
||||
connection.setDoOutput(false);
|
||||
connection.setRequestMethod("GET");
|
||||
@ -470,8 +470,8 @@ public class ITestHandleHttpRequest {
|
||||
serverReady.await();
|
||||
|
||||
final int port = ((HandleHttpRequest) runner.getProcessor()).getPort();
|
||||
connection = (HttpURLConnection) new URL("http://localhost:"
|
||||
+ port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").openConnection();
|
||||
connection = (HttpURLConnection) URI.create("http://localhost:"
|
||||
+ port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").toURL().openConnection();
|
||||
connection.setDoOutput(false);
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setRequestProperty("header1", "value1");
|
||||
@ -598,8 +598,8 @@ public class ITestHandleHttpRequest {
|
||||
serverReady.await();
|
||||
|
||||
final int port = ((HandleHttpRequest) runner.getProcessor()).getPort();
|
||||
final HttpsURLConnection connection = (HttpsURLConnection) new URL("https://localhost:"
|
||||
+ port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").openConnection();
|
||||
final HttpsURLConnection connection = (HttpsURLConnection) URI.create("https://localhost:"
|
||||
+ port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").toURL().openConnection();
|
||||
|
||||
SSLContext clientSslContext;
|
||||
if (twoWaySsl) {
|
||||
|
@ -48,6 +48,7 @@ import javax.net.ssl.SSLSocketFactory;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.GeneralSecurityException;
|
||||
@ -267,7 +268,7 @@ public class InvokeHTTPTest {
|
||||
runner.assertPenalizeCount(1);
|
||||
|
||||
final MockFlowFile flowFile = getFailureFlowFile();
|
||||
flowFile.assertAttributeEquals(InvokeHTTP.EXCEPTION_CLASS, MalformedURLException.class.getName());
|
||||
flowFile.assertAttributeEquals(InvokeHTTP.EXCEPTION_CLASS, IllegalArgumentException.class.getName());
|
||||
flowFile.assertAttributeExists(InvokeHTTP.EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
@ -798,9 +799,8 @@ public class InvokeHTTPTest {
|
||||
|
||||
@ParameterizedTest(name = "{index} => When {0} http://baseUrl/{1}, filename of the response FlowFile should be {2}")
|
||||
@MethodSource
|
||||
public void testResponseFlowFileFilenameExtractedFromRemoteUrl(String httpMethod, String inputUrl, String expectedFileName) throws MalformedURLException {
|
||||
URL baseUrl = new URL(getMockWebServerUrl());
|
||||
URL targetUrl = new URL(baseUrl, inputUrl);
|
||||
public void testResponseFlowFileFilenameExtractedFromRemoteUrl(String httpMethod, String relativePath, String expectedFileName) throws MalformedURLException, URISyntaxException {
|
||||
URL targetUrl = new URI("http", null, mockWebServer.getHostName(), mockWebServer.getPort(), String.format("/%s", relativePath), null, null).toURL();
|
||||
|
||||
runner.setProperty(InvokeHTTP.HTTP_METHOD, httpMethod);
|
||||
runner.setProperty(InvokeHTTP.HTTP_URL, targetUrl.toString());
|
||||
@ -824,8 +824,7 @@ public class InvokeHTTPTest {
|
||||
Arguments.of(HttpMethod.GET.name(), "file/", "file"),
|
||||
Arguments.of(HttpMethod.GET.name(), "file.txt", "file.txt"),
|
||||
Arguments.of(HttpMethod.GET.name(), "file.txt/", "file.txt"),
|
||||
Arguments.of(HttpMethod.GET.name(), "file.txt/?qp=v", "file.txt"),
|
||||
Arguments.of(HttpMethod.GET.name(), "f%69%6Cle.txt", "f%69%6Cle.txt"),
|
||||
Arguments.of(HttpMethod.GET.name(), "f%69%6Cle.txt", "f%2569%256Cle.txt"),
|
||||
Arguments.of(HttpMethod.GET.name(), "path/to/file.txt", "file.txt"),
|
||||
Arguments.of(HttpMethod.GET.name(), "", FLOW_FILE_INITIAL_FILENAME),
|
||||
Arguments.of(HttpMethod.POST.name(), "has/path", FLOW_FILE_INITIAL_FILENAME),
|
||||
|
@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
@ -92,8 +93,8 @@ public class ClassLoaderUtils {
|
||||
// If the path is already a URL, just add it (but don't check if it exists, too expensive and subject to network availability)
|
||||
boolean isUrl = true;
|
||||
try {
|
||||
additionalClasspath.add(new URL(modulePathString));
|
||||
} catch (MalformedURLException mue) {
|
||||
additionalClasspath.add(URI.create(modulePathString).toURL());
|
||||
} catch (IllegalArgumentException | MalformedURLException mue) {
|
||||
isUrl = false;
|
||||
}
|
||||
if (!isUrl) {
|
||||
|
@ -244,7 +244,7 @@ public class StandardOidcIdentityProvider implements OidcIdentityProvider {
|
||||
* @throws ParseException if there is a problem parsing the response
|
||||
*/
|
||||
private OIDCProviderMetadata retrieveOidcProviderMetadata(final String discoveryUri) throws IOException, ParseException {
|
||||
final URL url = new URL(discoveryUri);
|
||||
final URL url = URI.create(discoveryUri).toURL();
|
||||
final HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.GET, url);
|
||||
httpRequest.setConnectTimeout(oidcConnectTimeout);
|
||||
httpRequest.setReadTimeout(oidcReadTimeout);
|
||||
|
@ -38,7 +38,7 @@ import org.apache.nifi.util.file.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@ -77,8 +77,7 @@ public class FileSystemFlowRegistryClient extends AbstractFlowRegistryClient {
|
||||
@Override
|
||||
public boolean isStorageLocationApplicable(final FlowRegistryClientConfigurationContext context, final String storageLocation) {
|
||||
try {
|
||||
final URL url = new URL(storageLocation);
|
||||
final File file = new java.io.File(url.toURI());
|
||||
final File file = new java.io.File(URI.create(storageLocation));
|
||||
final Path path = file.toPath();
|
||||
|
||||
final String configuredDirectory = context.getProperty(DIRECTORY).getValue();
|
||||
|
@ -32,7 +32,6 @@ import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Objects;
|
||||
@ -242,9 +241,8 @@ public abstract class AbstractCommand<R extends Result> implements Command<R> {
|
||||
String contents;
|
||||
try {
|
||||
// try a public resource URL
|
||||
URL url = new URL(inputFile);
|
||||
contents = IOUtils.toString(url, StandardCharsets.UTF_8);
|
||||
} catch (MalformedURLException e) {
|
||||
contents = IOUtils.toString(URI.create(inputFile).toURL(), StandardCharsets.UTF_8);
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
// assume a local file then
|
||||
URI uri = Paths.get(inputFile).toAbsolutePath().toUri();
|
||||
contents = IOUtils.toString(uri, StandardCharsets.UTF_8);
|
||||
|
Loading…
x
Reference in New Issue
Block a user